Advertisements

LAMBO MODS

Giants Editor Tutorials, Mods & Friends

WeighStation Trigger

WeighStation

Description

Class for weigh stations

Functions

onCreate

Description

On create weigh station

Definition

onCreate(integer id)

Arguments

integer id id of weigh station node

Code

13 function WeighStation:onCreate(id)
14 g_currentMission:addNonUpdateable(WeighStation:new(id));
15 end;

new

Description

Create new weigh station object

Definition

new(integer trigger)

Arguments

integer trigger id id of trigger node

Return Values

table instance instance of object

Code

21 function WeighStation:new(triggerId)
22 local self = {};
23 setmetatable(self, WeighStation_mt);
24
25 local nodeId = triggerId;
26 self.triggerId = triggerId;
27 addTrigger(triggerId, “triggerCallback”, self);
28
29 self.isEnabled = true;
30 self.triggerVehicles = {};
31
32 local weightDisplayIndex = getUserAttribute(nodeId, “weightDisplayIndex”);
33 if weightDisplayIndex ~= nil then
34 self.displayNumbers = Utils.indexToObject(nodeId, weightDisplayIndex);
35 end;
36
37 return self;
38 end;

delete

Description

Delete weigh station

Definition

delete()

Code

42 function WeighStation:delete()
43 if self.triggerId ~= nil then
44 removeTrigger(self.triggerId);
45 self.triggerId = nil;
46 end;
47 end;

updateDisplayNumbers

Description

Write new mass into the display

Definition

updateDisplayNumbers(float mass)

Arguments

float mass mass

Code

52 function WeighStation:updateDisplayNumbers(mass)
53 if self.displayNumbers ~= nil then
54 Utils.setNumberShaderByValue(self.displayNumbers, math.floor(mass), 0);
55 end;
56 end;

updateWeight

Description

Get mass of vehicles in trigger and update display

Definition

updateWeight()

Code

60 function WeighStation:updateWeight()
61 local mass = 0;
62 for vehicle, _ in pairs(self.triggerVehicles) do
63 mass = mass + vehicle:getTotalMass();
64 end;
65 self:updateDisplayNumbers(mass*1000);
66 end;

triggerCallback

Description

Trigger callback

Definition

triggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)

Arguments

integer triggerId id of trigger
integer otherId id of actor
boolean onEnter on enter
boolean onLeave on leave
boolean onStay on stay

Code

75 function WeighStation:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
76 if self.isEnabled and (onEnter or onLeave) then
77 local vehicle = g_currentMission.nodeToVehicle[otherId];
78 if onEnter then
79 if vehicle ~= nil then
80 if self.triggerVehicles[vehicle] == nil then
81 self.triggerVehicles[vehicle] = 0;
82 end;
83 self.triggerVehicles[vehicle] = self.triggerVehicles[vehicle] + 1;
84 end;
85 else
86 if vehicle ~= nil then
87 self.triggerVehicles[vehicle] = self.triggerVehicles[vehicle] 1;
88 if self.triggerVehicles[vehicle] == 0 then
89 self.triggerVehicles[vehicle] = nil;
90 end;
91 end;
92 end;
93
94 self:updateWeight();
95 end;
96 end;

 

Advertisements
%d bloggers like this: