Sprache Deutsch Language English

Script Dokumentation LS 2015 - SiloAmountMover (Patch 1.3)

Script Dokumentation Übersicht

scripts/objects/SiloAmountMover.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
3SiloAmountMover = {}
4
5local SiloAmountMover_mt = Class(SiloAmountMover);
6
7function SiloAmountMover:onCreate(id)
8 g_currentMission:addNonUpdateable(SiloAmountMover:new(id));
9end;
10
11function SiloAmountMover:new(nodeId)
12 local self = {};
13 setmetatable(self, SiloAmountMover_mt);
14
15 self.nodeId = nodeId;
16 local minY, maxY = Utils.getVectorFromString(getUserAttribute(nodeId, "moveMinMaxY"));
17 if minY ~= nil and maxY ~= nil then
18 local maxAmount = tonumber(getUserAttribute(nodeId, "moveMaxAmount"));
19 if maxAmount ~= nil then
20 self.moveMinY = minY;
21 self.moveMaxY = maxY;
22 self.moveMaxAmount = maxAmount;
23 end;
24 end;
25 local fillType = getUserAttribute(nodeId, "fillType");
26 if fillType ~= nil then
27 self.fillType = Fillable.fillTypeNameToInt[fillType];
28 end;
29 if self.fillType == nil then
30 self.fillType = Fillable.FILLTYPE_LIQUIDMANURE;
31 end;
32 if self.moveMinY ~= nil then
33 g_currentMission:addSiloAmountListener(self, self.fillType);
34
35 self:onSiloAmountChanged(self.fillType, g_currentMission:getSiloAmount(self.fillType));
36 else
37 print("Error: SiloAmountMover '"..getName(nodeId).. "' invalid or missing user attributes 'moveMinMaxY' and 'moveMaxAmount'");
38 end;
39
40 return self;
41end;
42
43function SiloAmountMover:delete()
44 g_currentMission:removeSiloAmountListener(self);
45end;
46
47function SiloAmountMover:onSiloAmountChanged(fillType, amount)
48 if amount < 0.001 then
49 amount = 0;
50 end;
51 local x,y,z = getTranslation(self.nodeId);
52 local y = self.moveMinY + (self.moveMaxY - self.moveMinY)*Utils.clamp(amount, 0, self.moveMaxAmount)/(self.moveMaxAmount);
53 setTranslation(self.nodeId, x,y,z);
54end;
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