LUADOC - Farming Simulator 17

Printable Version

BaleDestroyerTrigger

Description
Class for bale destroy triggers
Functions

onCreate

Description
onCreate trigger
Definition
onCreate(integer id)
Arguments
integeridid of trigger node
Code
15function BaleDestroyerTrigger:onCreate(id)
16 g_currentMission:addNonUpdateable(BaleDestroyerTrigger:new(id));
17end;

new

Description
Create bale destroyer trigger object
Definition
new(integer id)
Arguments
integeridid of trigger node
Return Values
tableinstanceinstance of destroyer trigger
Code
23function BaleDestroyerTrigger:new(id)
24 local self = {};
25 setmetatable(self, BaleDestroyerTrigger_mt);
26
27 self.triggerId = id;
28 addTrigger(id, "triggerCallback", self);
29
30 self.isBaleDestroyerTrigger = true;
31 self.isEnabled = true;
32
33 self.appearsOnPDA = Utils.getNoNil(getUserAttribute(id, "appearsOnPDA"), true)
34 if self.appearsOnPDA then
35 local mapPosition = id
36 local mapPositionIndex = getUserAttribute(id, "mapPositionIndex")
37 if mapPositionIndex ~= nil then
38 mapPosition = Utils.indexToObject(id, mapPositionIndex)
39 if mapPosition == nil then
40 mapPosition = id
41 end
42 end
43
44 local x, _, z = getWorldTranslation(mapPosition)
45 self.mapHotspot = g_currentMission.ingameMap:createMapHotspot("baleSellTrigger", "", nil, getNormalizedUVs({8, 520, 240, 240}), {1,1,1,1}, x, z, nil, nil, false, false, false, 0, nil, MapHotspot.CATEGORY_TRIGGER)
46 end
47
48 return self;
49end;

delete

Description
Deleting destroyer trigger
Definition
delete()
Code
53function BaleDestroyerTrigger:delete()
54 removeTrigger(self.triggerId);
55
56 if self.mapHotspot ~= nil then
57 g_currentMission.ingameMap:deleteMapHotspot(self.mapHotspot)
58 end
59end;

triggerCallback

Description
Trigger callback
Definition
triggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay, integer otherShapeId)
Arguments
integertriggerIdid of trigger
integerotherIdid of actor
booleanonEnteron enter
booleanonLeaveon leave
booleanonStayon stay
integerotherShapeIdid of other actor
Code
69function BaleDestroyerTrigger:triggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId)
70 if self.isEnabled then
71 if onEnter then
72 -- this happens if a compound child of a deleted compound is entering
73 if otherActorId ~= 0 then
74 local object = g_currentMission:getNodeObject(otherActorId);
75 if object ~= nil then
76 if object:isa(Bale) and object:getCanBeSold() then
77 playSample(g_currentMission.cashRegistrySound, 1, 1, 0);
78 -- TODO: display a particle effect
79
80 if g_currentMission:getIsServer() then
81 -- print("Bale stored: ", tostring(otherActorId));
82 local difficultyMultiplier = g_currentMission.missionInfo.sellPriceMultiplier;
83 local baseValue = object:getValue();
84 g_currentMission:addSharedMoney(baseValue * difficultyMultiplier, "soldBales");
85 g_currentMission:addMoneyChange(baseValue * difficultyMultiplier, FSBaseMission.MONEY_TYPE_SINGLE, true, g_i18n:getText("finance_soldBales"));
86 object:delete();
87 end;
88
89 end;
90 else
91 if g_currentMission.nodeToVehicle[otherActorId] == nil then
92 -- there is nothing that could end up here, since physics objects are an object, thus this could only introduce bugs
93 -- delete(otherActorId);
94 end;
95 end;
96 end;
97 end;
98 end
99end;