http://forums.uktrainsim.com/viewtopic. ... 8#p1687192
Basically, its a way to insert your own script instructions in front of the default script provided by the builder. Using his technique I was able to hook the OnControlValueChange function such that my script could process the brake key presses to achieve the spring return effect, while all other key presses pass on to the default script so the locomotive operates as the designer intended otherwise.
This is a pretty advanced technique, but for those who are into script writing, etc I am sure you can think of some cool uses for this.
PS, just a starting point, I'll provide the script I used for my brake control mods. The script requires some other mods to the InputMappers etc, but you might find it a helpful example for your own projects.
- Code: Select all
-- -*- lua -*-
-- this is the original engine script .out file
require("Assets/GreatNortherner/EMD-SD7-9/RailVehicles/Engines/SD7/Models/RWA/sd7_EngineScript.out")
-- keep previous functions before we provide our own
__OnControlValueChange = OnControlValueChange
__Update = Update
__Initialise = Initialise
function Initialise()
__Initialise()
-- you can add your custom code here
end
function Update(interval)
__Update(interval)
-- you can add your custom code here
end
previousReverserValue = 0
ReverserState = 0
function OnControlValueChange ( name, index, value )
--- ADD SNAP TO REVERSER
if name == "Reverser" then
--- Make reverser snap from forward to reverse
if value > previousReverserValue then
ReverserState = 1
elseif value < previousReverserValue then
ReverserState = -1
end
previousReverserValue = value
value = ReverserState
--- TRAIN BRAKE CONTROLS
elseif name == "ApplyBrake" then
if value > 0.1 then
--- When Apostrophe is pressed, TrainBrakeControl sets to FullService
Call( "*:SetControlValue", "TrainBrakeControl", 0, 0.6 )
Call( "*:SetControlValue", "Regulator", 0, 0 )
else
--- When Apostrophe is released, TrainBrakeControl sets to Hold
Call( "*:SetControlValue", "TrainBrakeControl", 0, 0.4 )
end
elseif name == "ReleaseBrake" then
if value > 0.1 then
--- When SemiColon is pressed, TrainBrakeControl sets to Release
Call( "*:SetControlValue", "TrainBrakeControl", 0, 0 )
else
--- When SemiColon is released, TrainBrakeControl moves to Running
Call( "*:SetControlValue", "TrainBrakeControl", 0, 0.2 )
end
--- ENGINE BRAKE CONTROLS
elseif name == "ApplyEngineBrake" then
if value > 0.1 then
--- When RightBracket is pressed, EngineBrakeControl sets to FullService
Call( "*:SetControlValue", "EngineBrakeControl", 0, 1.0 )
Call( "*:SetControlValue", "Regulator", 0, 0 )
else
--- When RightBracket is released, EngineBrakeControl sets to Hold
Call( "*:SetControlValue", "EngineBrakeControl", 0, 0.5 )
end
elseif name == "ReleaseEngineBrake" then
if value > 0.1 then
--- When LeftBracket is pressed, EngineBrakeControl sets to Release
Call( "*:SetControlValue", "EngineBrakeControl", 0, 0 )
else
--- When LeftBracket is released, EngineBrakeControl moves to Running
Call( "*:SetControlValue", "EngineBrakeControl", 0, 0.5 )
end
--- THROTTLE / BRAKE INTERLOCK - if throttle increased, and brakes are on, release them
elseif name == "Regulator" then
if value > 0.05 then
if Call( "*:GetControlValue", "TrainBrakeControl", 0 ) > 0.3 then
Call( "*:SetControlValue", "TrainBrakeControl", 0, 0 )
end
if Call( "*:GetControlValue", "LocoBrakeCylinderPressurePSI", 0 ) > 5 then
Call( "*:SetControlValue", "EngineBrakeControl", 0, 0 )
end
end
end
--- fall through to the original engine script
__OnControlValueChange( name, index, value )
end --- OnControlValueChange
