Для полноты картины, думаю, всё же следует дать здесь обзор кода lua для скрипта сценария.
В качестве примера разберём скрипт для "фирменного" сценария Шерман Хилл "Running the #3 Track".
В самом начале кода находится так называемая заголовочная часть, где определяются некоторые
важные константы, которые в дальнейшем будут использоваться в основном "теле" скрипта:
- Код: Выделить всё
------------------------------------------------
-- ScenarioScript.lua
-- 20/08/2012
-- Copyright 2012 RailSimulator.com ltd
--
-- Scenario Script Tutorial - 'Running the #3 Track'
------------------------------------------------
-- 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_VCENTRE = 2
MSG_BOTTOM = 4
MSG_LEFT = 8
MSG_CENTRE = 16
MSG_RIGHT = 32
MSG_SMALL = 0
MSG_REG = 1
MSG_LRG = 2
Далее находится одно из главных определений скрипта - объявляется функция принимающая и обрабатывающая
события из игры:
- Код: Выделить всё
------------------------------------------------
-- Fn OnEvent
-- event - name of the event
-- return - TRUE/FALSE if event handled
function OnEvent ( event )
В момент вызова этой функции единственный аргумент "event" содержит строку содержащуюся
в соответствующих тегах файла "Scenario.bin":
- Код: Выделить всё
<SuccessEvent d:type="cDeltaString">cam1</SuccessEvent>
<FailureEvent d:type="cDeltaString"></FailureEvent>
Далее в коде скрипта идёт тело функции "OnEvent":
- Код: Выделить всё
-- Instruction triggers
---------------------------
-- Timed triggers
---------------------------
if event == "cam1" then -- Pan around and look at yard
SysCall ( "CameraManager:ActivateCamera", "cam1", 0 );
SysCall ( "ScenarioManager:LockControls");
return TRUE;
end -- if event == "wagoncam" then
Как будет видно, тело этой функции в основном состоит из блоков "if event == "имя_события" then *** end".
Внутри блока, который исполняется если имя события совпадает с ожидаемым, как правило, осуществляетются
соответствующие вызовы функции "SysCall". Некотрые примеры таких вызовов с небольшими пояснениями
ранее здесь постил товарищ
supermax.
- Код: Выделить всё
if event == "intro" then -- Pop up message
SysCall ( "ScenarioManager:ShowInfoMessageExt", "9dad0778-251d-4f0e-8fd2-3002904bbe00", "intro.html", 15, MSG_RIGHT + MSG_TOP, MSG_REG, FALSE );
return TRUE;
end -- if event == "intro" then
if event == "cab" then -- Put in cabview
SysCall ( "CameraManager:ActivateCamera", "CabCamera", 0 );
SysCall ( "ScenarioManager:UnlockControls");
return TRUE;
end -- if event == "cab" then
if event == "start" then -- Pop up message
SysCall ( "ScenarioManager:ShowInfoMessageExt", "af7a2b92-ad57-4bdc-88be-eef5f7459b6a", "start.html", 35, MSG_RIGHT + MSG_TOP, MSG_SMALL, FALSE );
return TRUE;
end -- if event == "start" then
if event == "lightning" then -- Pop up message
SysCall ( "ScenarioManager:ShowInfoMessageExt", "af7a2b92-ad57-4bdc-88be-eef5f7459b6a", "lightning.html", 60, MSG_LEFT + MSG_TOP, MSG_SMALL, FALSE );
return TRUE;
end -- if event == "lightning" then
if event == "stormstart" then
SysCall ( "WeatherController:SetCurrentWeatherEventChain", "MinorStorm" )
return TRUE
end
if event == "fault" then -- Pop up message
SysCall ( "ScenarioManager:ShowInfoMessageExt", "af7a2b92-ad57-4bdc-88be-eef5f7459b6a", "fault.html", 25, MSG_RIGHT + MSG_TOP, MSG_SMALL, FALSE );
SysCall ( "WeatherController:SetCurrentWeatherEventChain", "MinorStorm" )
return TRUE;
end -- if event == "fault" then
if event == "lynch" then -- Pop up message
SysCall ( "ScenarioManager:ShowInfoMessageExt", "af7a2b92-ad57-4bdc-88be-eef5f7459b6a", "lynch.html", 25, MSG_LEFT + MSG_TOP, MSG_SMALL, FALSE );
return TRUE;
end -- if event == "lynch" then
if event == "fall" then -- Pop up message
SysCall ( "ScenarioManager:ShowInfoMessageExt", "af7a2b92-ad57-4bdc-88be-eef5f7459b6a", "fall.html", 25, MSG_LEFT + MSG_TOP, MSG_SMALL, FALSE );
return TRUE;
end -- if event == "fall" then
if event == "wait" then -- Pop up message
SysCall ( "ScenarioManager:ShowInfoMessageExt", "af7a2b92-ad57-4bdc-88be-eef5f7459b6a", "wait.html", 25, MSG_RIGHT + MSG_TOP, MSG_SMALL, FALSE );
return TRUE;
end -- if event == "wait" then
if event == "go" then -- Pop up message
SysCall ( "ScenarioManager:ShowInfoMessageExt", "af7a2b92-ad57-4bdc-88be-eef5f7459b6a", "go.html", 25, MSG_LEFT + MSG_TOP, MSG_SMALL, FALSE );
return TRUE;
end -- if event == "go" then
if event == "laramie" then -- Pop up message
SysCall ( "ScenarioManager:ShowInfoMessageExt", "af7a2b92-ad57-4bdc-88be-eef5f7459b6a", "laramie.html", 25, MSG_RIGHT + MSG_TOP, MSG_SMALL, FALSE );
return TRUE;
end -- if event == "laramie" then
if event == "tom" then -- Pop up message
SysCall ( "ScenarioManager:ShowInfoMessageExt", "61969999-d8db-40a9-a37c-022cca18980b", "tom.html", 25, MSG_LEFT + MSG_TOP, MSG_SMALL, FALSE );
return TRUE;
end -- if event == "tom" then
if event == "tom2" then -- Pop up message
SysCall ( "ScenarioManager:ShowInfoMessageExt", "61969999-d8db-40a9-a37c-022cca18980b", "tom2.html", 25, MSG_RIGHT + MSG_TOP, MSG_SMALL, FALSE );
return TRUE;
end -- if event == "tom2" then
if event == "tom3" then -- Pop up message
SysCall ( "ScenarioManager:ShowInfoMessageExt", "61969999-d8db-40a9-a37c-022cca18980b", "tom3.html", 25, MSG_RIGHT + MSG_TOP, MSG_SMALL, FALSE );
return TRUE;
end -- if event == "tom3" then
end
Кроме тела функции "OnEvent" в коде этого скрипта ничего больше нет.
Осталось только обозначить вызовы "SysCall" которые осуществляются при обработке событий
моим стандартным скриптом:
- события, выводящие текстовые сообщения: "SysCall ( "ScenarioManager:ShowInfoMessageExt", ..."
- события, управляющие поездом: "SysCall ("PlayerEngine:SetControlValue", ..."
- события, управляющие камерой: "SysCall ( "CameraManager:ActivateCamera", ..."
- события, управляющие погодой: "SysCall ( "WeatherController:SetCurrentWeatherEventChain", ..."
Вот теперь совсем всё. Ну если конечно есть желание "копать" в глубь, то...
Последний раз редактировалось sergz692 27.02.2013, 22:32, всего редактировалось 1 раз.