Advertisements

LAMBO MODS

Giants Editor Tutorials, Mods & Friends

WoodSell Trigger

WoodSellTrigger

Description

Class for wood sell triggers

Functions

onCreate

Description

On create wood sell trigger

Definition

onCreate(integer id)

Arguments

integer id id of trigger node

Code

15 function WoodSellTrigger:onCreate(id)
16 g_currentMission:addNonUpdateable(WoodSellTrigger:new(id));
17 end

new

Description

Create new wood sell trigger object

Definition

new(integer nodeId)

Arguments

integer nodeId if of trigger node

Return Values

table instance instance of object

Code

23 function WoodSellTrigger:new(nodeId)
24 local self = {};
25 setmetatable(self, WoodSellTrigger_mt);
26
27 self.triggerId = nodeId;
28 addTrigger(nodeId, “triggerCallback”, self);
29
30 self.updateEventListeners = {};
31 self.nextTimeSamplePlay = 0;
32 self.isEnabled = true;
33
34 self.priceMultiplier = Utils.getNoNil(getUserAttribute(nodeId, “priceMultiplier”), 1);
35
36 return self;
37 end

delete

Description

Delete wood sell trigger

Definition

delete()

Code

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

addUpdateEventListener

Description

Add listener to update listeners

Definition

addUpdateEventListener()

Code

49 function WoodSellTrigger:addUpdateEventListener(listener)
50 if listener ~= nil then
51 self.updateEventListeners[listener] = listener;
52 end;
53 end;

removeUpdateEventListener

Description

Remove listener from update listeners

Definition

removeUpdateEventListener()

Code

57 function WoodSellTrigger:removeUpdateEventListener(listener)
58 if listener ~= nil then
59 self.updateEventListeners[listener] = nil;
60 end;
61 end;

triggerCallback

Description

Trigger callback

Definition

triggerCallback(integer triggerId, integer otherActorId, boolean onEnter, boolean onLeave, boolean onStay, integer otherShapeId)

Arguments

integer triggerId id of trigger
integer otherActorId id of other actor
boolean onEnter on enter
boolean onLeave on leave
boolean onStay on stay
integer otherShapeId id of other shape

Code

71 function WoodSellTrigger:triggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId)
72 if self.isEnabled and onEnter then
73 if otherActorId ~= 0 then
74 local splitType = SplitUtil.splitTypes[getSplitType(otherActorId)];
75 if splitType ~= nil and splitType.pricePerLiter > 0 then
76
77 if g_currentMission.time > self.nextTimeSamplePlay then
78 self.nextTimeSamplePlay = g_currentMission.time + 500;
79 playSample(g_currentMission.cashRegistrySound, 1, 1, 0);
80 end;
81
82 if g_currentMission:getIsServer() then
83
84 local volume = getVolume(otherActorId);
85 local qualityScale = 1;
86 local lengthScale = 1;
87 local defoliageScale = 1;
88 local sizeX, sizeY, sizeZ, numConvexes, numAttachments = getSplitShapeStats(otherActorId);
89 if sizeX ~= nil and volume > 0 then
90 local bvVolume = sizeX*sizeY*sizeZ;
91 local volumeRatio = bvVolume / volume;
92 local volumeQuality = 1math.sqrt(Utils.clamp((volumeRatio3)/7, 0,1)) * 0.95; — ratio <= 3: 100%, ratio >= 10: 5%
93 local convexityQuality = 1Utils.clamp((numConvexes2)/(62), 0,1) * 0.95— 0-2: 100%:, >= 6: 5%
94
95 local maxSize = math.max(sizeX, math.max(sizeY, sizeZ));
96 — 1m: 60%, 6-11m: 120%, 19m: 60%
97 if maxSize < 11 then
98 lengthScale = 0.6 + math.min(math.max((maxSize1)/5, 0), 1)*0.6;
99 else
100 lengthScale = 1.2 math.min(math.max((maxSize11)/8, 0), 1)*0.6;
101 end
102
103 local minQuality = math.min(convexityQuality,volumeQuality);
104 local maxQuality = math.max(convexityQuality,volumeQuality);
105 qualityScale = minQuality + (maxQualityminQuality) * 0.3; — use 70% of min quality
106
107 defoliageScale = 1math.min(numAttachments/15, 1) * 0.8; — #attachments 0: 100%, >=15: 20%
108 end
109 — Only take 33% into account of the quality criteria on low
110 qualityScale = Utils.lerp(1, qualityScale, g_currentMission.missionInfo.difficulty/3);
111 defoliageScale = Utils.lerp(1, defoliageScale, g_currentMission.missionInfo.difficulty/3);
112 local baseValue = volume*1000*splitType.pricePerLiter*qualityScale*defoliageScale * lengthScale;
113
114 — update tons of wood sold for achievements
115 g_currentMission.missionStats:updateStats(“woodTonsSold”, volume);
116
117 local difficultyMultiplier = g_currentMission.missionInfo.sellPriceMultiplier;
118 g_currentMission:addSharedMoney(baseValue * difficultyMultiplier * self.priceMultiplier, “soldWood”);
119 g_currentMission:addMoneyChange(baseValue * difficultyMultiplier * self.priceMultiplier, FSBaseMission.MONEY_TYPE_SINGLE, true, g_i18n:getText(“finance_soldWood”));
120 delete(otherActorId);
121
122 for _, listener in pairs(self.updateEventListeners) do
123 listener:onWoodSellingUpdateEvent(self, baseValue * difficultyMultiplier * self.priceMultiplier);
124 end;
125 end
126 end
127 end
128 end
129
130 end
Advertisements
%d bloggers like this: