Sprache Deutsch Language English

Script Dokumentation LS 2015 - ShovelFillTrigger (Patch 1.3)

Script Dokumentation Übersicht

scripts/triggers/ShovelFillTrigger.lua

Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1-- ShovelFillTrigger class
2--
3-- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
4
5ShovelFillTrigger = {}
6
7local ShovelFillTrigger_mt = Class(ShovelFillTrigger);
8
9function ShovelFillTrigger:onCreate(id)
10 if g_currentMission:getIsServer() then
11 local trigger = ShovelFillTrigger:new();
12 if trigger:load(id) then
13 g_currentMission:addUpdateable(trigger);
14 else
15 trigger:delete();
16 end
17 end;
18end;
19
20function ShovelFillTrigger:new(mt)
21
22 local self = {};
23 if mt == nil then
24 mt = ShovelFillTrigger_mt;
25 end;
26 setmetatable(self, mt);
27
28 self.triggerId = 0;
29 self.infoTriggerId = 0;
30 self.nodeId = 0;
31
32 return self;
33end
34
35function ShovelFillTrigger:load(nodeId, fillType)
36
37 self.nodeId = nodeId;
38 if g_currentMission:getIsServer() then
39 self.triggerId = Utils.indexToObject(nodeId, getUserAttribute(nodeId, "triggerIndex"));
40 if self.triggerId == nil then
41 self.triggerId = nodeId;
42 end
43 addTrigger(self.triggerId, "triggerCallback", self);
44 end
45
46 self.infoTriggerId = Utils.indexToObject(nodeId, getUserAttribute(nodeId, "infoTriggerIndex"));
47 if self.infoTriggerId ~= nil then
48 addTrigger(self.infoTriggerId, "infoTriggerCallback", self);
49 end;
50
51 self.isEnabled = true;
52
53 self.isSiloTrigger = Utils.getNoNil(getUserAttribute(nodeId, "isSiloTrigger"), false);
54 if fillType ~= nil and fillType ~= Fillable.FILLTYPE_UNKNOWN then
55 self.fillType = fillType;
56 else
57 self.fillType = Fillable.FILLTYPE_UNKNOWN;
58 local fillType = getUserAttribute(nodeId, "fillType");
59 if fillType ~= nil then
60 local fillTypeInt = Fillable.fillTypeNameToInt[fillType];
61 if fillTypeInt ~= nil then
62 self.fillType = fillTypeInt;
63 end;
64 end;
65 if self.fillType == Fillable.FILLTYPE_UNKNOWN then
66 print("Error: shovel fill trigger "..getName(nodeId).." has invalid fill type");
67 end;
68 end
69
70 self.currentShovel = nil;
71
72 self.moneyChangeId = getMoneyTypeId();
73 self.lastMoneyChange = -1;
74
75 return true;
76end;
77
78function ShovelFillTrigger:delete()
79 if self.triggerId ~= nil and self.triggerId ~= 0 then
80 removeTrigger(self.triggerId);
81 end
82 if self.infoTriggerId ~= nil and self.infoTriggerId ~= 0 then
83 removeTrigger(self.infoTriggerId);
84 end
85end;
86
87function ShovelFillTrigger:update(dt)
88 if g_currentMission:getIsServer() and self.currentShovel ~= nil then
89 -- get the shovel object again (maybe it was deleted in the meantime)
90 local shovel = g_currentMission.nodeToVehicle[self.currentShovelNode];
91 self.currentShovel = shovel;
92 if shovel ~= nil then
93 self:fillShovel(shovel, dt);
94 end
95 end
96 if self.lastMoneyChange > 0 then
97 self.lastMoneyChange = self.lastMoneyChange - 1;
98 if self.lastMoneyChange == 0 then
99 g_currentMission:showMoneyChange(self.moneyChangeId);
100 end;
101 end;
102end
103
104function ShovelFillTrigger:fillShovel(shovel, dt)
105 if self.isSiloTrigger then
106 local silo = g_currentMission:getSiloAmount(self.fillType);
107 if silo > 0 then
108 local delta = shovel:fillShovelFromTrigger(self, silo, self.fillType, dt);
109 if delta > 0 then
110 g_currentMission:setSiloAmount(self.fillType, silo-delta);
111 end
112 end
113 else
114 local delta = shovel:fillShovelFromTrigger(self, math.huge, self.fillType, dt);
115 if delta > 0 then
116 local price = Fillable.fillTypeIndexToDesc[self.fillType].pricePerLiter;
117 if price > 0 then
118 g_currentMission:addSharedMoney(-price*delta, "other");
119 g_currentMission:addMoneyChange(-price*delta, self.moneyChangeId);
120 self.lastMoneyChange = 30;
121 end
122 end
123 end
124end
125
126function ShovelFillTrigger:triggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId)
127
128 if self.isEnabled and (onEnter or onLeave) then
129
130 local shovel = g_currentMission.nodeToVehicle[otherActorId];
131
132 if shovel ~= nil then
133 if onLeave then
134 if self.currentShovel == shovel and self.currentShovelNode == otherActorId then
135 self.currentShovel = nil;
136 end
137 else
138 if shovel.allowFillFromShovelTrigger and shovel.fillShovelFromTrigger ~= nil and (shovel.shovelNodes == nil or shovel.shovelNodes[otherShapeId] or shovel.shovelNodes[otherActorId]) then
139 self.currentShovel = shovel;
140 self.currentShovelNode = otherActorId;
141 end;
142 end;
143 end;
144 end;
145end;
146
147function ShovelFillTrigger:infoTriggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId)
148end;
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