------------------------------------------------ -- ScenarioScript.lua -- 30/07/2012 -- Copyright 2012 RailSimulator.com ltd -- -- Scenario Script Tutorial - 'The Last Run' ------------------------------------------------ -- true/false defn FALSE = 0 TRUE = 1 -- condition return values CONDITION_NOT_YET_MET = 0 CONDITION_SUCCEEDED = 1 CONDITION_FAILED = 2 -- Message types MT_INFO = 0 -- large centre screen pop up MT_ALERT = 1 -- top right alert message MSG_TOP = 1 MSG_LEFT = 8 MSG_RIGHT = 32 MSG_SMALL = 0 MSG_REG = 1 totalHornCheckpoints = 8 timesHornUsed = 0 currentCheckpoint = 1 hornCondition = "HornCondition" currentHornCondition = hornCondition .. currentCheckpoint; ------------------------------------------------ -- Fn OnEvent -- event - name of the event -- return - TRUE/FALSE if event handled function OnEvent (event) if event == "HornCheckStart" then if currentCheckpoint == 1 then SysCall("ScenarioManager:ShowInfoMessageExt", "af7a2b92-ad57-4bdc-88be-eef5f7459b6a", "horn.html", 0, MSG_RIGHT, MSG_SMALL, TRUE); end -- if currentCheckpoint == 1 SysCall("ScenarioManager:BeginConditionCheck", currentHornCondition); return TRUE; end -- if event == "HornCheckStart" if event == "HornCheckEnd" then CheckHorn(false); currentCheckpoint = currentCheckpoint + 1; currentHornCondition = hornCondition .. currentCheckpoint; return TRUE; end -- if event == "HornCheckEnd" if event == "FinalHornCheck" then CheckHorn(true); return TRUE; end -- if event == "FinalHornCheck" end -- functionOnEvent(event) ------------------------------------------------ -- Fn TestCondition -- condition - name of the condition -- return state of the condition function TestCondition ( condition ) if condition == currentHornCondition then hornValue = SysCall("PlayerEngine:GetControlValue", "Horn", 0); if hornValue > 0 then return CONDITION_SUCCEEDED; else return CONDITION_NOT_YET_MET; end -- if hornValue == 1 end -- if condition == "HornCheck" return CONDITION_NOT_YET_MET; end -- function TestCondition(condition) function CheckHorn(isFinalHornCheck) hornCheckStatus = SysCall("ScenarioManager:GetConditionStatus", currentHornCondition); if hornCheckStatus == CONDITION_NOT_YET_MET then SysCall("ScenarioManager:EndConditionCheck", currentHornCondition); if isFinalHornCheck ~= true then SysCall("ScenarioManager:ShowMessage", "af7a2b92-ad57-4bdc-88be-eef5f7459b6a", "You didn't use your whistle, or you did not sound it for long enough, leaving some of the rail fans disappointed! Make sure you sound the whistle for a few seconds when approaching the rail fans.", MT_INFO); end -- if isFinalHornCheck ~= true else if isFinalHornCheck ~= true then SysCall("ScenarioManager:ShowMessage", "af7a2b92-ad57-4bdc-88be-eef5f7459b6a", "The rail fans cheer as you approach!", MT_INFO); end -- if isFinalHornCheck ~= true timesHornUsed = timesHornUsed + 1; end -- if hornCheckStatus == CONDITION_NOT_YET_MET if isFinalHornCheck == true then if timesHornUsed < totalHornCheckpoints then SysCall("ScenarioManager:TriggerScenarioFailure", "You failed to use the whistle at some of the points! Try again."); else SysCall("ScenarioManager:ShowMessage", "af7a2b92-ad57-4bdc-88be-eef5f7459b6a", "Well done - you used your whistle when required at each of the locations. Next, make sure you stop at your next point as indicated on your task list for a quick photo session.", MT_INFO); end -- if timesHornUsed < totalHornCheckpoints end -- if isFinalHornCheck == true end -- function CheckHorn()