-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
--EQUIPMENT DEFECT DETECTOR ENGINE SCRIPT INJECTION--------------------------------------------------------------------------------------------------------------------
--(c)Searchlight Simulations 2020, OPEN SOURCE-------------------------------------------------------------------------------------------------------------------------

local MSG_ID_INITIAL_CONSIST_MESSAGE = false

local AXLE_COUNT = 4
local CAR_ID = 0

function Initialise()

--ASSIGN UNIQUE MESSAGE ID FOR EACH CAR
CAR_ID = math.random(100000,999999)

Call ( "BeginUpdate" )
	
end

function Update()

end

function OnConsistMessage ( msg, argument, direction )

	-- 00001 IS SENT BY THE LEAD LOCOMOTIVE ONCE IT'S FIRST AXLE PASSES A EQUIPMENT DEFECT DETECTOR DETECTION POINT
	if msg == 00001 then
	    --SEND UNIQUE ID'ED MESSAGE WITH AXLE COUNT BACK TO THE LEAD LOCOMOTIVE
		Call( "SendConsistMessage", CAR_ID, AXLE_COUNT, 0 )
		Call( "SendConsistMessage", CAR_ID, AXLE_COUNT, 1 )
	end
		
	Call( "SendConsistMessage", msg, argument, direction )
end