FORO Railsim.es
Limitar velocidad composicion en todo el escenario - Versión para impresión

+- FORO Railsim.es (https://www.railsim.es/foro)
+-- Foro: Train Simulator (https://www.railsim.es/foro/forumdisplay.php?fid=6)
+--- Foro: Escenario - Actividades (https://www.railsim.es/foro/forumdisplay.php?fid=12)
+--- Tema: Limitar velocidad composicion en todo el escenario (/showthread.php?tid=2204)



Limitar velocidad composicion en todo el escenario - obispo rojo - 06-03-2014

Saludos compañer@s forer@s.

He visto en algún escenario, que aunque la velocidad de la ruta sea por ejemplo de 180 km, la composicion al rebasar una velocidad determinada, pongamos 120, sale una ventana con un mensaje en el que avisa que la velocidad máxima permitida de esa composición es de 120 km/h.

Estoy preparando un escenario y por ubicación en el tiempo (año donde se realiza el escenario), me encuentro que la ruta tiene tramos de 200 km/h y por hacerlo más real, queria limitar la velocidad máxima de la composición.

Alguien me puede ayudar a realizar esta acción.

Gracias por anticipado y un cordial saludo a tod@s.


Re: Limitar velocidad composicion en todo el escenario - Bermudez - 06-03-2014

Es algo complicadillo, ya que si no me equivoco, se hace mediante LUA scripting.


Re: Limitar velocidad composicion en todo el escenario - obispo rojo - 06-03-2014

Gracias Bermudez por la respuesta, ya me temia yo que esto no era cosa de pinchar aqui y poner numeritos.
Muy agradecido, pensaremos que poder hacer más real el escenario.
Saludos


Re: Limitar velocidad composicion en todo el escenario - AEC - 06-03-2014

El amigo Francesc SV te podra ilustrar sobre el tema ya que el ya ha conseguido realizarlo. Te confirmo que es mediante script LUA.


Re: Limitar velocidad composicion en todo el escenario - el_pinchos - 06-04-2014

Una vez que se sabe programar LUA, el script necesario para limitar las velocidades es bastante sencillo. Yo tengo un escenario en el Workshop de TS2014 donde utilicé un script para limitar las velocidades en dos fases, una a 25 mph y otra a 50 mph. La sección de limitación es más o menos así:

Código:

function OnEvent ( event )

if event == "inicio_25" then
    
        SysCall ( "ScenarioManager:BeginConditionCheck", "SpeedCondition1" );
        
        return TRUE;
        
    end
    
    if event == "fin_25" then
    
        SysCall ( "ScenarioManager:EndConditionCheck", "SpeedCondition1" );
        
        return TRUE;
        
    end -- if event...
    
    if event == "inicio_50" then
    
        SysCall ( "ScenarioManager:BeginConditionCheck", "SpeedCondition2" );
        
        return TRUE;
        
    end
    
    if event == "fin_50" then
    
        SysCall ( "ScenarioManager:EndConditionCheck", "SpeedCondition2" );
        
        return TRUE;
        
    end

if event == "pasas_de_25" then -- Trigger at reached 30mph
                
        -- show html briefing '30mph Reached'
        SysCall ( "ScenarioManager:ShowMessage", "Penalty Brake. Remember: max speed permited is 25 MPH" );
        SysCall ( "PlayerEngine:SetControlValue", "Regulator", 0, 0.0);
        SysCall ( "PlayerEngine:SetControlValue", "Reverser", 0, 0.0);
        SysCall ( "PlayerEngine:SetControlValue", "TrainBrakeControl", 0, 1.0);
        --return TRUE;
            
    end -- if event == "SpeedReached" then
    
    if event == "pasas_de_50" then -- Trigger at reached 10mph
            
        -- show html briefing 'Stopped'
        SysCall ( "ScenarioManager:ShowMessage", "Penalty Brake. Remember: max speed permited is 50 MPH" );
        SysCall ( "PlayerEngine:SetControlValue", "Regulator", 0, 0.0);
        SysCall ( "PlayerEngine:SetControlValue", "Reverser", 0, 0.0);
        SysCall ( "PlayerEngine:SetControlValue", "TrainBrakeControl", 0, 1.0);
        --return TRUE;
            
    end -- if event == "SpeedReached" then
    
end

function TestCondition ( condition )

    if condition == "SpeedCondition1" then
    
        speed = SysCall ( "PlayerEngine:GetSpeed" );
        
        if speed > 11.623 then -- 25mph
        
            SysCall ( "ScenarioManager:TriggerDeferredEvent", "pasas_de_25", 0.1 );
            return CONDITION_NOT_YET_MET;
        
        end -- if speed...
    
    end -- if condition...
    
    if condition == "SpeedCondition2" then
    
        speed = SysCall ( "PlayerEngine:GetSpeed" );
        
        if speed > 22.799 then -- 50mph
        
            SysCall ( "ScenarioManager:TriggerDeferredEvent", "pasas_de_50", 0.1 );
            return CONDITION_NOT_YET_MET;
        
        end -- if speed...
    
    end -- if condition...    
    
end

A simple vista parece muy complicado, pero a ojos de un programador es bastante sencillo. Solo es cuestión de tener un poco de práctica en programación.


Re: Limitar velocidad composicion en todo el escenario - AEC - 06-04-2014

¿Eso va dentro de la funcion Update() o el OnEvent se declara en el editor?
Muchas gracias por compartir el trabajo, Pinchos. :ok:


Re: Limitar velocidad composicion en todo el escenario - el_pinchos - 06-04-2014

El script de escenario funciona solo con las funciones de declaración de eventos ('OnEvent ( event ) '), y declaración de condiciones ('TestCondition ( condition )'). Los eventos se indican como 'triggers' en el editor de escenarios o se toman en el mismo script en la función de condiciones.

Los eventos 'inicio_25', 'fin_25', 'inicio_50', 'fin_50' son tomados del editor de escenarios, mientras que los nombrados 'pasas_de_25' y 'pasas_de_50' son tomados de la funciones de condiciones.

En el script de este escenario hay además eventos para cámaras cinemáticas y meteorología especial, aunque estas propiedades se definen solamente en la función de eventos y se toman de los 'triggers' del editor de escenarios:

Código:

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 )

-- Instruction triggers
---------------------------

    if event == "camera_start" then
            
        SysCall ( "CameraManager:ActivateCamera", "cam_1", 0 );
        SysCall ( "ScenarioManager:LockControls");
        return TRUE;
            
    end
    
    if event == "camera_end" then
            
        SysCall ( "CameraManager:CabCamera", 0 );
        SysCall ( "ScenarioManager:UnlockControls");
        return TRUE;
            
    end
    
    if event == "inicio_25" then
    
        SysCall ( "ScenarioManager:BeginConditionCheck", "SpeedCondition1" );
        
        return TRUE;
        
    end
    
    if event == "fin_25" then
    
        SysCall ( "ScenarioManager:EndConditionCheck", "SpeedCondition1" );
        
        return TRUE;
        
    end -- if event...
    
    if event == "inicio_50" then
    
        SysCall ( "ScenarioManager:BeginConditionCheck", "SpeedCondition2" );
        
        return TRUE;
        
    end
    
    if event == "fin_50" then
    
        SysCall ( "ScenarioManager:EndConditionCheck", "SpeedCondition2" );
        
        return TRUE;
        
    end -- if event...
    
    if event == "snow" then
    
        SysCall("WeatherController:SetCurrentWeatherEventChain", "TheStormChain");
        return TRUE;
    
    end -- if event == "StormStart"


-- Timed triggers
---------------------------
    
    if event == "pasas_de_25" then -- Trigger at reached 30mph
                
        -- show html briefing '30mph Reached'
        SysCall ( "ScenarioManager:ShowMessage", "Penalty Brake. Remember: max speed permited is 25 MPH" );
        SysCall ( "PlayerEngine:SetControlValue", "Regulator", 0, 0.0);
        SysCall ( "PlayerEngine:SetControlValue", "Reverser", 0, 0.0);
        SysCall ( "PlayerEngine:SetControlValue", "TrainBrakeControl", 0, 1.0);
        --return TRUE;
            
    end -- if event == "SpeedReached" then
    
    if event == "pasas_de_50" then -- Trigger at reached 10mph
            
        -- show html briefing 'Stopped'
        SysCall ( "ScenarioManager:ShowMessage", "Penalty Brake. Remember: max speed permited is 50 MPH" );
        SysCall ( "PlayerEngine:SetControlValue", "Regulator", 0, 0.0);
        SysCall ( "PlayerEngine:SetControlValue", "Reverser", 0, 0.0);
        SysCall ( "PlayerEngine:SetControlValue", "TrainBrakeControl", 0, 1.0);
        --return TRUE;
            
    end -- if event == "SpeedReached" then
    
end -- function OnEvent ( event )

------------------------------------------------
-- Fn TestCondition
--        condition - name of the condition
--        return state of the condition
function TestCondition ( condition )

    if condition == "SpeedCondition1" then
    
        speed = SysCall ( "PlayerEngine:GetSpeed" );
        
        if speed > 11.623 then -- 25mph
        
            SysCall ( "ScenarioManager:TriggerDeferredEvent", "pasas_de_25", 0.1 );
            return CONDITION_NOT_YET_MET;
        
        end -- if speed...
    
    end -- if condition...
    
    if condition == "SpeedCondition2" then
    
        speed = SysCall ( "PlayerEngine:GetSpeed" );
        
        if speed > 22.799 then -- 50mph
        
            SysCall ( "ScenarioManager:TriggerDeferredEvent", "pasas_de_50", 0.1 );
            return CONDITION_NOT_YET_MET;
        
        end -- if speed...
    
    end -- if condition...    
    
end -- function TestCondition ( condition )



Re: Limitar velocidad composicion en todo el escenario - AEC - 06-04-2014

el_pinchos El script de escenario funciona solo con las funciones de declaración de eventos ('OnEvent ( event ) '), y declaración de condiciones ('TestCondition ( condition )'). Los eventos se indican como 'triggers' en el editor de escenarios o se toman en el mismo script en la función de condiciones.

Los eventos 'inicio_25', 'fin_25', 'inicio_50', 'fin_50' son tomados del editor de escenarios, mientras que los nombrados 'pasas_de_25' y 'pasas_de_50' son tomados de la funciones de condiciones.

En el script de este escenario hay además eventos para cámaras cinemáticas y meteorología especial, aunque estas propiedades se definen solamente en la función de eventos y se toman de los 'triggers' del editor de escenarios:

Código:

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 )

-- Instruction triggers
---------------------------

    if event == "camera_start" then
            
        SysCall ( "CameraManager:ActivateCamera", "cam_1", 0 );
        SysCall ( "ScenarioManager:LockControls");
        return TRUE;
            
    end
    
    if event == "camera_end" then
            
        SysCall ( "CameraManager:CabCamera", 0 );
        SysCall ( "ScenarioManager:UnlockControls");
        return TRUE;
            
    end
    
    if event == "inicio_25" then
    
        SysCall ( "ScenarioManager:BeginConditionCheck", "SpeedCondition1" );
        
        return TRUE;
        
    end
    
    if event == "fin_25" then
    
        SysCall ( "ScenarioManager:EndConditionCheck", "SpeedCondition1" );
        
        return TRUE;
        
    end -- if event...
    
    if event == "inicio_50" then
    
        SysCall ( "ScenarioManager:BeginConditionCheck", "SpeedCondition2" );
        
        return TRUE;
        
    end
    
    if event == "fin_50" then
    
        SysCall ( "ScenarioManager:EndConditionCheck", "SpeedCondition2" );
        
        return TRUE;
        
    end -- if event...
    
    if event == "snow" then
    
        SysCall("WeatherController:SetCurrentWeatherEventChain", "TheStormChain");
        return TRUE;
    
    end -- if event == "StormStart"


-- Timed triggers
---------------------------
    
    if event == "pasas_de_25" then -- Trigger at reached 30mph
                
        -- show html briefing '30mph Reached'
        SysCall ( "ScenarioManager:ShowMessage", "Penalty Brake. Remember: max speed permited is 25 MPH" );
        SysCall ( "PlayerEngine:SetControlValue", "Regulator", 0, 0.0);
        SysCall ( "PlayerEngine:SetControlValue", "Reverser", 0, 0.0);
        SysCall ( "PlayerEngine:SetControlValue", "TrainBrakeControl", 0, 1.0);
        --return TRUE;
            
    end -- if event == "SpeedReached" then
    
    if event == "pasas_de_50" then -- Trigger at reached 10mph
            
        -- show html briefing 'Stopped'
        SysCall ( "ScenarioManager:ShowMessage", "Penalty Brake. Remember: max speed permited is 50 MPH" );
        SysCall ( "PlayerEngine:SetControlValue", "Regulator", 0, 0.0);
        SysCall ( "PlayerEngine:SetControlValue", "Reverser", 0, 0.0);
        SysCall ( "PlayerEngine:SetControlValue", "TrainBrakeControl", 0, 1.0);
        --return TRUE;
            
    end -- if event == "SpeedReached" then
    
end -- function OnEvent ( event )

------------------------------------------------
-- Fn TestCondition
--        condition - name of the condition
--        return state of the condition
function TestCondition ( condition )

    if condition == "SpeedCondition1" then
    
        speed = SysCall ( "PlayerEngine:GetSpeed" );
        
        if speed > 11.623 then -- 25mph
        
            SysCall ( "ScenarioManager:TriggerDeferredEvent", "pasas_de_25", 0.1 );
            return CONDITION_NOT_YET_MET;
        
        end -- if speed...
    
    end -- if condition...
    
    if condition == "SpeedCondition2" then
    
        speed = SysCall ( "PlayerEngine:GetSpeed" );
        
        if speed > 22.799 then -- 50mph
        
            SysCall ( "ScenarioManager:TriggerDeferredEvent", "pasas_de_50", 0.1 );
            return CONDITION_NOT_YET_MET;
        
        end -- if speed...
    
    end -- if condition...    
    
end -- function TestCondition ( condition )
De acuerdo, muchisimas gracias. :maestro: Yo de momento solo me habia mirado los scripts del material rodante.
Igual que me he fijado que aqui escribes SysCall y no simplemente Call como en los trenes.


Re: Limitar velocidad composicion en todo el escenario - obispo rojo - 06-04-2014

Estimados compañeros.

Solo daros las gracias por estas respuestas, que a un "aprendiz" como yo, le animan a enciscarme en esto de los escenarios.

Os pondria miles de [Smile y otros miles de :maestro: porque sois verdaderos genios.

De verdad, muchisimas gracias, creo que vuestros comentarios ayudaran a muchos creadores.

Un cordial saludo.

Obispo Rojo