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 | |
3 | WeighStation = {}; |
4 | |
5 | local WeighStation_mt = Class(WeighStation); |
6 | |
7 | function WeighStation:onCreate(id) |
8 | g_currentMission:addNonUpdateable(WeighStation:new(id)); |
9 | end; |
10 | |
11 | function WeighStation:new(triggerId) |
12 | local self = {}; |
13 | setmetatable(self, WeighStation_mt); |
14 | |
15 | local nodeId = triggerId; |
16 | self.triggerId = triggerId; |
17 | addTrigger(triggerId, "triggerCallback", self); |
18 | |
19 | self.isEnabled = true; |
20 | self.triggerVehicles = {}; |
21 | |
22 | local weightDisplayIndex = getUserAttribute(nodeId, "weightDisplayIndex"); |
23 | if weightDisplayIndex ~= nil then |
24 | self.displayNumbers = Utils.indexToObject(nodeId, weightDisplayIndex); |
25 | end; |
26 | |
27 | return self; |
28 | end; |
29 | |
30 | function WeighStation:delete() |
31 | if self.triggerId ~= nil then |
32 | removeTrigger(self.triggerId); |
33 | self.triggerId = nil; |
34 | end; |
35 | end; |
36 | |
37 | function WeighStation:updateDisplayNumbers(mass) |
38 | if self.displayNumbers ~= nil then |
39 | Utils.setNumberShaderByValue(self.displayNumbers, math.floor(mass), 0); |
40 | end; |
41 | end; |
42 | |
43 | function WeighStation:updateWeight() |
44 | local mass = 0; |
45 | for vehicle, _ in pairs(self.triggerVehicles) do |
46 | mass = mass + vehicle:getTotalMass(); |
47 | end; |
48 | self:updateDisplayNumbers(mass*1000); |
49 | end; |
50 | |
51 | function WeighStation:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay) |
52 | if self.isEnabled and (onEnter or onLeave) then |
53 | local vehicle = g_currentMission.nodeToVehicle[otherId]; |
54 | if onEnter then |
55 | if vehicle ~= nil then |
56 | if self.triggerVehicles[vehicle] == nil then |
57 | self.triggerVehicles[vehicle] = 0; |
58 | end; |
59 | self.triggerVehicles[vehicle] = self.triggerVehicles[vehicle] + 1; |
60 | end; |
61 | else |
62 | if vehicle ~= nil then |
63 | self.triggerVehicles[vehicle] = self.triggerVehicles[vehicle] - 1; |
64 | if self.triggerVehicles[vehicle] == 0 then |
65 | self.triggerVehicles[vehicle] = nil; |
66 | end; |
67 | end; |
68 | end; |
69 | |
70 | self:updateWeight(); |
71 | end; |
72 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de