Sprache Deutsch Language English

Script Dokumentation LS 2015 - DistantTrain (Patch 1.3)

Script Dokumentation Übersicht

scripts/objects/DistantTrain.lua

Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1-- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
2
3DistantTrain = {}
4
5local DistantTrain_mt = Class(DistantTrain);
6
7function DistantTrain:onCreate(id)
8 g_currentMission:addUpdateable(DistantTrain:new(id));
9 --print("created DistantTrain, id: ", id);
10end;
11
12function DistantTrain:new(id)
13 local instance = {};
14 setmetatable(instance, DistantTrain_mt);
15
16 instance.nurbsId = getChildAt(id, 0);
17 instance.distantTrainId = getChildAt(id, 1)
18 instance.time = 1;
19 instance.currentDelay = math.random(20000, 120000)
20
21 -- spline is a straight line, thus we only need to set the train's direction once
22 local dx, dy, dz = getSplineDirection(instance.nurbsId, 0.5);
23 setDirection(instance.distantTrainId, dx, 0, dz, 0, 1, 0);
24
25 instance.trainSound = createAudioSource("trainSound", "data/maps/sounds/train.wav", 300, 1, 1, 0);
26 link(instance.distantTrainId, instance.trainSound);
27
28 return instance;
29end;
30
31function DistantTrain:delete()
32
33end;
34
35function DistantTrain:update(dt)
36 if self.currentDelay > 0 then
37 self.currentDelay = self.currentDelay - dt;
38 else
39 setVisibility(self.trainSound, true);
40 self.time = self.time - 0.0002 * dt;
41 if (self.time < 0) then
42 self.time = 1;
43 self.currentDelay = math.random(20000, 120000);
44 setVisibility(self.trainSound, false);
45 end;
46 local x, y, z = getSplinePosition(self.nurbsId, self.time);
47 setTranslation(self.distantTrainId, x, y, z);
48 end;
49end;
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
Script Dokumentation Übersicht