Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
include "Locomotive.gs"
class ZLocomotiveLLCType2 isclass Locomotive {
bool FanState = false;
Asset MyAsset1;
public void Init(Asset asset) {
inherited(asset);
MyAsset1 = asset;
SetMeshAnimationState("galuzi_vody_right", false);
SetMeshAnimationState("galuzi_vody_left", false);
SetMeshAnimationState("galuzi1_verhnie", false);
AddHandler(me, "Vehicle", "Throttle-Change", "OnThrottleChanged");
}
void OnThrottleChanged(Message msg) {
float throttle = GetEngineSetting("throttle");
if (!FanState and GetEngineSetting("throttle")>5) {
FanState = true;
World.PlaySound(MyAsset1, "sound/zhaluzi_on.wav", 1.0f, 20.0f, 100.0f, me, "a.zhaluzi");
Sleep(0.1);
SetMeshAnimationState("galuzi_vody_right", true);
SetMeshAnimationState("galuzi_vody_left", true);
SetMeshAnimationState("galuzi1_verhnie", true);
}
else if (FanState and GetEngineSetting("throttle")==0) {
FanState = false;
World.PlaySound(MyAsset1, "sound/zhaluzi_off.wav", 1.0f, 20.0f, 100.0f, me, "a.zhaluzi");
Sleep(0.1);
SetMeshAnimationState("galuzi_vody_right", false);
SetMeshAnimationState("galuzi_vody_left", false);
SetMeshAnimationState("galuzi1_verhnie", false);
}
}
};
According to the WiKi on this page , that message is sent by the Train and not the Vehicle. The message is actually "ThrottleChanged" so your script would have to listen (Sniff) for messages sent by your train.Hello, can anyone tell me, please, why this script doesn't work? There are no errors, but locomotive shutters animation doesn't work. I added all tags in config the same as they are in script, also added necessary sounds. Here is script:
...
The purpose is to get shutters open, when locomotive engine/water is getting overheated.Which is the purpose of this script?
Well, i'm not keen on scripts, so i don't know, how to get those messages coming or how to write throttle monitor code.According to the WiKi on this page , that message is sent by the Train and not the Vehicle. The message is actually "ThrottleChanged" so your script would have to listen (Sniff) for messages sent by your train.
I ran a small test session and couldn't see any such messages in the log in any driving mode. So, I wonder if the message does exist as a standard message. Others may know more.
You could write you own throttle monitor code or use one in some library included by your script.
BTW, if the animated meshes didn't exist in the model Trainz would simply ignore the animation call so there would be no error messages. That may change in future validation checks.
include "Locomotive.gs"
class ZLocomotiveLLCType2 isclass Locomotive {
bool FanState = false;
bool objectRunningDriver = false;
// prototypes
thread void MainThread();
void ModuleInitHandler(Message msg);
public void Init(Asset asset) {
inherited(asset);
SetMeshAnimationState("galuzi_vody_right", false);
SetMeshAnimationState("galuzi_vody_left", false);
SetMeshAnimationState("galuzi1_verhnie", false);
}
void ModuleInitHandler(Message msg) {
if (objectRunningDriver) {
return;
}
if (World.GetCurrentModule() == World.DRIVER_MODULE) {
objectRunningDriver = true;
MainThread();
}
}
thread void MainThread() {
while(true) {
if(!FanState and GetEngineSetting("throttle")>5) {
FanState=true;
World.PlaySound(MyAsset1, "sound/zhaluzi_on.wav", 1.0f, 20.0f, 100.0f, me, "a.zhaluzi");
}
if(FanState and GetEngineSetting("throttle")==0) {
FanState=false;
World.PlaySound(MyAsset1, "sound/zhaluzi_off.wav", 1.0f, 20.0f, 100.0f, me, "a.zhaluzi");
}
SetMeshAnimationState("galuzi_vody_right",FanState);
SetMeshAnimationState("galuzi_vody_left",FanState);
SetMeshAnimationState("galuzi1_verhnie",FanState);
Sleep(5.0);
}
}
};