--env-m4.lua if S.trains == nil then S.trains = {} end if S.d == nil then S.d = {} end if S.datetime == nil then S.datetime = "" end if S.stop_display == nil then S.stop_display = false end F.print = function (str) if F.debug then print("".. (str or "nil") ) end end F.isempty = function (s) return s == nil or s == "" end F.get_rc_safe = function() return get_rc() or "" end F.get_line_safe = function() return get_line() or "" end F.get_train_length_safe = function() return train_length() or 0 end F.avg = function(t) local sum = 0 local count = 0 for k,v in pairs(t) do if type(v) == "number" then sum = sum + v count = count + 1 end end return (sum / count) end if event.init then F.debug = true F.printAllTrainsInfo = true F.max_displays = 4 F.print("Initialized") end F.does_train_have_rc = function(wanted_rc) local rc = F.get_rc_safe() if rc:match(wanted_rc) then return true end end --old splitter and cpl for demo function F.cpllooparound(ln) if not (event.train) then return end if not (F.get_line_safe() == ln) then return end if "ENGINE" == F.get_rc_safe() then atc_send("CplS0WRSM") set_rc("") return end split_at_index(F.get_train_length_safe()-1,"A0S0") --Stopping the wagons is handled here by SO set_rc("ENGINE") atc_send("A1") end --new ones function F.split_looparound(ln) if not (event.train) then return end if not (F.get_line_safe() == ln) then return end split_at_index(F.get_train_length_safe()-1,"A0S0OC") --Stopping the wagons is handled here by SO set_rc("ENGINE") atc_send("A1") end function F.split_looparound_left(ln) if not (event.train) then return end if not (F.get_line_safe() == ln) then return end split_at_index(F.get_train_length_safe()-1,"A0S0OL") --Stopping the wagons is handled here by SO set_rc("ENGINE") atc_send("A1") end function F.split_looparound_right(ln) if not (event.train) then return end if not (F.get_line_safe() == ln) then return end split_at_index(F.get_train_length_safe()-1,"A0S0OR") --Stopping the wagons is handled here by SO set_rc("ENGINE") atc_send("A1") end function F.cpl_looparound(ln) if not (event.train) then return end if not (F.get_line_safe() == ln) then return end if "ENGINE" == F.get_rc_safe() then atc_send("CplS0WD2RS4") set_rc("") return end end --end of new cpl functions