Sprache Deutsch Language English

Script Dokumentation LS 2015 - PalletTrigger (Patch 1.3)

Script Dokumentation Übersicht

scripts/triggers/PalletTrigger.lua

Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1--
2-- PalletTrigger
3--
4-- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
5
6PalletTrigger = {};
7
8-- TODO sync this over the network (play the sound only for the client that was using the pallet fork, use palletFork.owner)
9
10local PalletTrigger_mt = Class(PalletTrigger, Object);
11
12InitStaticObjectClass(PalletTrigger, "PalletTrigger", ObjectIds.OBJECT_PALLET_TRIGGER);
13
14function PalletTrigger:onCreate(id)
15 local trigger = PalletTrigger:new(g_server ~= nil, g_client ~= nil);
16 --print("created pallet trigger, id: ", id);
17 local index = g_currentMission:addOnCreateLoadedObject(trigger);
18 trigger:load(id);
19 trigger:register(true);
20 --[[if g_client ~= nil then
21 g_client:getServerConnection():sendEvent(OnCreateLoadedObjectEvent:new(index));
22 end;]]
23end;
24
25function PalletTrigger:new(isServer, isClient)
26
27 local self = Object:new(isServer, isClient, PalletTrigger_mt);
28 self.triggerId = 0;
29 self.deletePalletTimerId = 0;
30 return self;
31end;
32
33function PalletTrigger:load(id)
34 self.triggerId = id;
35 addTrigger(self.triggerId, "triggerCallback", self);
36
37 self.currentPallet = 0;
38 self.deletePalletTimerId = 0;
39
40 return self;
41end;
42
43function PalletTrigger:update()
44end;
45
46function PalletTrigger:delete()
47 removeTrigger(self.triggerId);
48 if self.deletePalletTimerId ~= 0 then
49 removeTimer(self.deletePalletTimerId);
50 end;
51
52 PalletTrigger:superClass().delete(self);
53end;
54
55function PalletTrigger:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
56
57 if otherId ~= 0 then
58 if onLeave then
59 local isPallet = getUserAttribute(otherId, "isPallet");
60
61 if isPallet ~= nil and isPallet then
62 --print("Pallet left trigger: ", tostring(otherId));
63 self.currentPallet = 0;
64 end;
65 end;
66
67 if onEnter then
68 local isPallet = getUserAttribute(otherId, "isPallet");
69
70 if isPallet ~= nil and isPallet then
71 self.currentPallet = otherId;
72 end;
73 end;
74
75 if onLeave then
76 if self.isServer then
77 if self.deletePalletTimerId == 0 and self.currentPallet ~= 0 then
78 local isPalletFork = getUserAttribute(otherId, "isPalletFork");
79 if isPalletFork ~= nil and isPalletFork then
80 --print("Pallet Fork left trigger: ", tostring(otherId));
81 self.deletePalletTimerId = addTimer(2000, "palletTriggerTimerCallback", self);
82 end;
83 end;
84 end;
85 end;
86 end;
87end;
88
89-- this is only executed on the server
90function PalletTrigger:palletTriggerTimerCallback()
91 if self.currentPallet ~= 0 then
92 --print("Ka-Ching!");
93 delete(self.currentPallet);
94 self.currentPallet = 0;
95 local difficultyMultiplier = 2 ^ (3 - g_currentMission.missionStats.difficulty);
96 --g_currentMission.missionStats.money = g_currentMission.missionStats.money + 400 * difficultyMultiplier;
97 local money = 400 * difficultyMultiplier;
98 g_currentMission:addSharedMoney(money);
99 g_currentMission:addMoneyChange(money, FSBaseMission.MONEY_TYPE_SINGLE, true);
100 -- g_currentMission:increaseReputation(1);
101
102 playSample(g_currentMission.cashRegistrySound, 1, 1, 0);
103
104 end;
105 self.deletePalletTimerId = 0;
106 return false; -- remove this timer
107end;
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