Jump to content

My first steps..


Recommended Posts

 

Hello,

I'm taking my first steps in Lua and I'm having a lot of fun. I don't really have any programming skills, but it's all logical.

However, after a few hours of tinkering I've reached a problem where I'm stuck.

The goal: After I arrive with my locomotive behind signal E114 in Lazy and have coupled it to the wagons, a route is to be set after ZEW1. However, the SignalTrigger does not recognize my stopping locomotive.

Enclosed is the code, with a request for help. Perhaps someone can see the problem at first glance. Thank you for your help!

-- SimRail - The Railway Simulator
-- LUA Scripting scenario
-- Version: 1.0
--
require("SimRailCore")

DeveloperMode = function()
    return true
end

StartPosition = {17788.41, 338.47, 23638.06}
ScenarioStep = "basic"
Sounds = {}

--- Function called by SimRail when the loading finishes - you should set scenario time in here, spawn trains etc. After calling this mission recorder is started and stuff gets registered
function StartScenario()
    StartRecorder()
    DisplayChatText("LuaText2")
    SetWeather(WeatherConditionCode.ClearSky, 26, 1000, 100, 2000, 0, 10, 0, true)
    PlayerTrainset = SpawnTrainsetOnSignal("Player", FindSignal("LA_Tm2"), 10, true, true, false, true, {
        CreateNewSpawnFullVehicleDescriptor(LocomotiveNames.ET22_836, false, "", 0, BrakeRegime.P),
    })
    PlayerTrainset.SetRadioChannel(2, true)
    PlayerTrainset.SetState(DynamicState.dsStop, TrainsetState.tsShunting, true)
    PlayerTrainset.SetAllowCouplerAttach(true)
    PlayerTrainset.SetAllowCouplerDetach(true)

    SpawnTrainsetOnSignalAsync("Cargo", FindSignal("LA_E114"), 40, false, false, true, {
        CreateNewSpawnFullVehicleDescriptor(FreightWagonNames._441V_31516635283_3, true, FreightLoads_412W_v4.Coal, 70, BrakeRegime.P),
        CreateNewSpawnFullVehicleDescriptor(FreightWagonNames._441V_31516635283_3, true, FreightLoads_412W_v4.Coal, 70, BrakeRegime.P),
        CreateNewSpawnFullVehicleDescriptor(FreightWagonNames._441V_31516635512_5, true, FreightLoads_412W_v4.Coal, 70, BrakeRegime.P),
    }, function (trainset)
        Trains[1] = trainset
        trainset.SetAllowCouplerAttach(true)
        trainset.SetAllowCouplerDetach(true)
    end)
end



--- Function below is called by SimRail when VD is ready to start receiving orders
function OnVirtualDispatcherReady()
    Log("Ready!")
    ScenarioStep = "start"
end

function OnPlayerRadioCall(trainsetInfo, radio_SelectionCall)
    if(ScenarioStep == "neutral") then
        Log("No action on radio call here")
    end
    if(ScenarioStep == "start") then
        ScenarioStep = "neutral"
        CreateCoroutine(function ()
            VDSetRoute("LA_Tm2", "LA_Tm15", VDOrderType.ManeuverRoute)
            VDSetRoute("LA_Tm15", "LA_Tm125", VDOrderType.ManeuverRoute)
        end)
    end
    if(ScenarioStep == "LAcoupled") then
        CreateCoroutine(function ()
            VDSetRoute("LA_E114", "LA_Tm7", VDOrderType.ManeuverRoute)
        end)
    end
end

CreateSignalTrigger(FindSignal("LA_E114"), 5, {
    check = UnconditialCheck,
    result = function(e)
        CreateCoroutine(function()
            coroutine.yield(CoroutineYields.WaitForVehicleStop, RailstockGetPlayerTrainset().Vehicles[1])
            ScenarioStep = "LAcoupled"
            Log("Now Ready for new radio call!")
        end)
    end
})

 

Link to comment
Share on other sites

Heya!
So: signal triggers are interconnected with game refresh rate (track one are not). So giving just 5m can not catch it properly (I usually use at least 130m))
But beside of it - your code should work just fine 🙂

  • Thanks 1
Link to comment
Share on other sites

 

Thank you for your answer!

I have increased the range to 130. Unfortunately it does not work. 

"ScenarioStep" seems to remain at the value "neutral" and is not changed to "LAcoupled", so that the message "No action on radio call here" continues to appear at pressing ZEW1 after coupling to the cars.

I am at a bit of a loss. ^^

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Our servers

    • Drivers | Maszyniści Drivers | Maszyniści
      • PL2
      • pl2
      • 5 / 75
          • Percentage filling 7%
          • Most players 103
      • PL3
      • pl3
      • 0 / 77
          • Percentage filling 0%
          • Most players 78
      • PL4
      • pl4
      • 0 / 88
          • Percentage filling 0%
          • Most players 87
      • PL8
      • pl8
      • 0 / 44
          • Percentage filling 0%
          • Most players 84
      • EN1
      • en1
      • 5 / 79
          • Percentage filling 6%
          • Most players 81
      • EN2
      • en2
      • 0 / 86
          • Percentage filling 0%
          • Most players 60
      • EN3
      • en3
      • 0 / 80
          • Percentage filling 0%
          • Most players 60
      • DE1
      • de1
      • 3 / 87
          • Percentage filling 3%
          • Most players 87
      • DE3
      • de3
      • 0 / 81
          • Percentage filling 0%
          • Most players 67
      • DE4
      • de4
      • 0 / 84
          • Percentage filling 0%
          • Most players 65
      • FR1
      • fr1
      • 1 / 87
          • Percentage filling 1%
          • Most players 49
      • UA1
      • ua1
      • 0 / 81
          • Percentage filling 0%
          • Most players 27
      • CN1
      • cn1
      • 0 / 80
          • Percentage filling 0%
          • Most players 28
      • CZ1
      • cz1
      • 1 / 81
          • Percentage filling 1%
          • Most players 61
      • ES1
      • es1
      • 0 / 77
          • Percentage filling 0%
          • Most players 23
    • Dispatchers | Dyżurni ruchu Dispatchers | Dyżurni ruchu
      • PL2
      • pl2
      • 7 / 34
          • Percentage filling 21%
          • Most players 34
      • PL3
      • pl3
      • 0 / 34
          • Percentage filling 0%
          • Most players 31
      • PL4
      • pl4
      • 1 / 34
          • Percentage filling 3%
          • Most players 34
      • PL8
      • pl8
      • 0 / 34
          • Percentage filling 0%
          • Most players 27
      • EN1
      • en1
      • 3 / 34
          • Percentage filling 9%
          • Most players 34
      • EN2
      • en2
      • 2 / 34
          • Percentage filling 6%
          • Most players 21
      • EN3
      • en3
      • 1 / 34
          • Percentage filling 3%
          • Most players 13
      • DE1
      • de1
      • 0 / 34
          • Percentage filling 0%
          • Most players 34
      • DE3
      • de3
      • 0 / 34
          • Percentage filling 0%
          • Most players 29
      • DE4
      • de4
      • 0 / 34
          • Percentage filling 0%
          • Most players 29
      • UA1
      • ua1
      • 0 / 34
          • Percentage filling 0%
          • Most players 17
      • FR1
      • fr1
      • 2 / 34
          • Percentage filling 6%
          • Most players 23
      • ES1
      • es1
      • 0 / 34
          • Percentage filling 0%
          • Most players 15
      • CZ1
      • cz1
      • 1 / 34
          • Percentage filling 3%
          • Most players 28
      • CN1
      • cn1
      • 1 / 34
          • Percentage filling 3%
          • Most players 19
    • 30 Total servers
    • 33 / 1697 Total players
    • 2% Filled servers
×
×
  • Create New...

Important Information

Terms of Use Privacy Policy