Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- HotspotTrigger class |
2 | -- |
3 | -- HotspotTriggers consist of a trigger object and two rings (which are children of the trigger object) that rotate around their y axis at different speeds |
4 | -- |
5 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
6 | |
7 | HotspotTrigger = {} |
8 | |
9 | local HotspotTrigger_mt = Class(HotspotTrigger); |
10 | |
11 | function HotspotTrigger:onCreate(id) |
12 | g_currentMission:addUpdateable(HotspotTrigger:new(id)); |
13 | --print("Created HotspotTrigger, id: ", id); |
14 | end; |
15 | |
16 | function HotspotTrigger:new(name) |
17 | local instance = {}; |
18 | setmetatable(instance, HotspotTrigger_mt); |
19 | |
20 | instance.triggerId = name; |
21 | addTrigger(name, "triggerCallback", instance); |
22 | |
23 | instance.hotspotSymbol = getChildAt(name, 0); |
24 | |
25 | local x, y, z = getTranslation(name); |
26 | |
27 | -- put yourself on the pda map |
28 | instance.mapHotspot = g_currentMission.ingameMap:createMapHotspot(tostring(name), "dataS2/menu/hud/hud_pda_spot_yellow.png", x, z, g_currentMission.ingameMap.mapArrowWidth / 3, g_currentMission.ingameMap.mapArrowHeight / 3, false, true, false, 0); |
29 | |
30 | instance.distanceToPlayer = 0; |
31 | |
32 | instance.isEnabled = true; |
33 | |
34 | return instance; |
35 | end; |
36 | |
37 | function HotspotTrigger:delete() |
38 | removeTrigger(self.triggerId); |
39 | --print("HOTSPOT TRIGGER REMOVED: ", self.triggerId); |
40 | end; |
41 | |
42 | function HotspotTrigger:update(dt) |
43 | rotate(self.hotspotSymbol, 0, 0.005 * dt, 0); |
44 | end; |
45 | |
46 | function HotspotTrigger:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay) |
47 | if onEnter and self.isEnabled and g_currentMission.controlledVehicle ~= nil then |
48 | if otherId == g_currentMission.controlledVehicle.components[1].node then -- only react if player enters while driving a vehicle |
49 | -- play trigger sound |
50 | if g_currentMission.hotspotSound ~= nil then |
51 | playSample(g_currentMission.hotspotSound, 1, 1, 0); |
52 | end; |
53 | |
54 | -- tell the mission you've been triggered |
55 | g_currentMission:hotspotTouched(triggerId); |
56 | |
57 | self.mapHotspot.visible = false; |
58 | self.mapHotspot.enabled = false; |
59 | |
60 | self.isEnabled = false; |
61 | setVisibility(self.triggerId, false); |
62 | end; |
63 | end; |
64 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de