Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- ShopTrigger class |
2 | -- |
3 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
4 | |
5 | ShopTrigger = {} |
6 | |
7 | local ShopTrigger_mt = Class(ShopTrigger); |
8 | |
9 | function ShopTrigger:onCreate(id) |
10 | g_currentMission:addNonUpdateable(ShopTrigger:new(id)); |
11 | --print("Created ShopTrigger, id: ", id); |
12 | end; |
13 | |
14 | function ShopTrigger:new(name) |
15 | local self = {}; |
16 | setmetatable(self, ShopTrigger_mt); |
17 | |
18 | self.triggerId = name; |
19 | if g_currentMission:getIsClient() then |
20 | addTrigger(name, "triggerCallback", self); |
21 | end; |
22 | |
23 | self.shopSymbol = getChildAt(name, 0); |
24 | self.shopPlayerSpawn = getChildAt(name, 1); |
25 | |
26 | self.shopType = tonumber(Utils.getNoNil(getUserAttribute(name, "shopType"), 1)); |
27 | if self.shopType ~= ShopScreen.TYPE_VEHICLES and self.shopType ~= ShopScreen.TYPE_GARDEN_CENTER then |
28 | print("Warning: Invalid shopType '"..self.shopType.."'! Use VehicleShop instead"); |
29 | self.shopType = ShopScreen.TYPE_VEHICLES; |
30 | end; |
31 | |
32 | self.objectActivated = false; |
33 | self.isEnabled = true; |
34 | |
35 | if g_isDemo or g_isGamescomVersion or (not g_currentMission.missionInfo:isa(FSCareerMissionInfo)) then |
36 | setVisibility(self.shopSymbol, false); |
37 | end; |
38 | |
39 | self.activateText = g_i18n:getText("ActivateShop"); |
40 | if self.shopType == ShopScreen.TYPE_GARDEN_CENTER then |
41 | self.activateText = g_i18n:getText("ActivateGardenCenterShop"); |
42 | end; |
43 | |
44 | return self; |
45 | end; |
46 | |
47 | function ShopTrigger:delete() |
48 | if g_currentMission:getIsClient() then |
49 | removeTrigger(self.triggerId); |
50 | g_currentMission:removeActivatableObject(self); |
51 | end; |
52 | end; |
53 | |
54 | function ShopTrigger:getIsActivatable() |
55 | return self.isEnabled and g_currentMission.controlPlayer; |
56 | end; |
57 | |
58 | function ShopTrigger:drawActivate() |
59 | return; |
60 | end; |
61 | |
62 | function ShopTrigger:onActivateObject() |
63 | g_currentMission:addActivatableObject(self); |
64 | self.objectActivated = true; |
65 | g_shopScreen:setShopType(self.shopType); |
66 | g_gui:showGui("ShopScreen"); |
67 | local x,y,z = getWorldTranslation(self.shopPlayerSpawn); |
68 | local dx, dy, dz = localDirectionToWorld(self.shopPlayerSpawn, 0, 0, 1); |
69 | g_currentMission.player:moveToAbsolute(x,y,z); |
70 | g_client:getServerConnection():sendEvent(PlayerTeleportEvent:new(x,y,z)); |
71 | g_currentMission.player.rotY = Utils.getYRotationFromDirection(dx, dz) + math.pi; |
72 | |
73 | end; |
74 | |
75 | function ShopTrigger:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay) |
76 | if self.isEnabled and not g_isGamescomVersion and not g_isDemo and g_currentMission.missionInfo:isa(FSCareerMissionInfo) then |
77 | if onEnter or onLeave then |
78 | if g_currentMission.player ~= nil and otherId == g_currentMission.player.rootNode then |
79 | if onEnter then |
80 | if not self.objectActivated then |
81 | g_currentMission:addActivatableObject(self); |
82 | self.objectActivated = true; |
83 | end |
84 | else |
85 | if self.objectActivated then |
86 | g_currentMission:removeActivatableObject(self); |
87 | self.objectActivated = false; |
88 | end |
89 | end; |
90 | end; |
91 | end; |
92 | end; |
93 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de