Sprache Deutsch Language English

Script Dokumentation LS 2015 - LiquidManureFillTrigger (Patch 1.3)

Script Dokumentation Übersicht

scripts/triggers/LiquidManureFillTrigger.lua

Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1-- LiquidManureFillTrigger class
2--
3-- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
4--
5
6LiquidManureFillTrigger = {}
7
8local LiquidManureFillTrigger_mt = Class(LiquidManureFillTrigger, FillTrigger);
9
10function LiquidManureFillTrigger:new(mt)
11 if mt == nil then
12 mt = LiquidManureFillTrigger_mt;
13 end
14 local self = FillTrigger:new(mt);
15
16 self.fillLevel = 0;
17 self.capacity = 800000;
18
19 self.vehiclesInRange = {};
20 self.playerInRange = false;
21
22 return self;
23end
24
25function LiquidManureFillTrigger:load(nodeId, fillLevelObject)
26
27 if not LiquidManureFillTrigger:superClass().load(self, nodeId, Fillable.FILLTYPE_LIQUIDMANURE) then
28 return false;
29 end
30 self.fillLevelObject = fillLevelObject;
31
32 local capacityStr = getUserAttribute(nodeId, "capacity");
33 if capacityStr ~= nil then
34 self.capacity = Utils.getNoNil(tonumber(capacityStr), self.capacity);
35 end;
36
37 local minY, maxY = Utils.getVectorFromString(getUserAttribute(nodeId, "moveMinMaxY"));
38 if minY ~= nil and maxY ~= nil then
39 self.moveMinY = minY;
40 self.moveMaxY = maxY;
41 self.movingId = Utils.indexToObject(nodeId, getUserAttribute(nodeId, "movingIndex"));
42 end;
43
44 self.fillLevel = -1;
45 self:setFillLevel(0, true);
46
47 return true;
48end;
49
50function LiquidManureFillTrigger:delete()
51 LiquidManureFillTrigger:superClass().delete(self);
52end;
53
54function LiquidManureFillTrigger:update(dt)
55 if self:getShowInfo() then
56 g_currentMission:addExtraPrintText(g_i18n:getText("fill_level").." "..math.floor(self.fillLevel).." ("..math.floor(100*self.fillLevel/self.capacity).."%)");
57 end;
58end;
59
60function LiquidManureFillTrigger:fill(tool, delta)
61 if not tool:allowFillType(self.fillType, false) then
62 return 0.0;
63 end
64
65 delta = math.max(math.min(delta, self.fillLevel), 0);
66
67 if delta > 0 then
68 local oldFillLevel = tool:getFillLevel(self.fillType);
69 tool:setFillLevel(oldFillLevel + delta, self.fillType, true);
70 delta = tool:getFillLevel(self.fillType) - oldFillLevel;
71 if delta > 0 then
72 self:setFillLevel(self.fillLevel - delta);
73 end;
74 end;
75 return delta;
76end;
77
78function LiquidManureFillTrigger:setFillLevel(fillLevel, noEventSend)
79
80 fillLevel = Utils.clamp(fillLevel, 0, self.capacity);
81 if self.fillLevel ~= fillLevel then
82 self.fillLevel = fillLevel;
83
84 if noEventSend == nil or not noEventSend then
85 self.fillLevelObject:liquidManureFillLevelChanged(fillLevel, self.fillType, self);
86 end
87
88 if self.fillLevelObject.isClient then
89 if self.movingId ~= nil then
90 local x,y,z = getTranslation(self.movingId);
91 local y = self.moveMinY + (self.moveMaxY - self.moveMinY)*self.fillLevel/self.capacity;
92 setTranslation(self.movingId, x,y,z);
93 end;
94 end;
95 end
96end;
97
98function LiquidManureFillTrigger:getShowInfo()
99 if (g_currentMission.controlPlayer and self.playerInRange) then
100 return true;
101 end;
102 if not g_currentMission.controlPlayer then
103 for vehicle in pairs(self.vehiclesInRange) do
104 if vehicle:getIsActiveForInput(false) then
105 return true;
106 end;
107 end;
108 end;
109 return false;
110end;
111
112function LiquidManureFillTrigger:triggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId)
113 if self.isEnabled and (onEnter or onLeave) then
114
115 if g_currentMission.player ~= nil and otherActorId == g_currentMission.player.rootNode then
116 if onEnter then
117 self.playerInRange = true;
118 else
119 self.playerInRange = false;
120 end;
121 else
122 local vehicle = g_currentMission.nodeToVehicle[otherActorId];
123 if vehicle ~= nil then
124 if onEnter then
125 self.vehiclesInRange[vehicle] = true;
126 else
127 self.vehiclesInRange[vehicle] = nil;
128 end;
129 end;
130 end;
131 end
132
133 LiquidManureFillTrigger:superClass().triggerCallback(self, triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId);
134end;
135
136function LiquidManureFillTrigger:getIsActivatable(fillable)
137 if self.fillLevel <= 0 then
138 return false;
139 end;
140 return LiquidManureFillTrigger:superClass().getIsActivatable(self, fillable);
141end;
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