Sprache Deutsch Language English

Script Dokumentation LS 2015 - VehicleSellingPoint (Patch 1.3)

Script Dokumentation Übersicht

scripts/objects/VehicleSellingPoint.lua

Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1-- VehicleSellingPoint class
2--
3-- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
4
5source("dataS/scripts/SellSpecificVehicleEvent.lua"); -- TODO: that goes into the selling dialog
6
7VehicleSellingPoint = {}
8
9local VehicleSellingPoint_mt = Class(VehicleSellingPoint);
10
11function VehicleSellingPoint:onCreate(id)
12 local vehicleSellingPoint = VehicleSellingPoint:new(id);
13 table.insert(g_currentMission.updateables, vehicleSellingPoint);
14 g_currentMission.vehicleSellingPointBase = vehicleSellingPoint;
15 -- print("created VehicleSellingPoint, id: ", id);
16end;
17
18function VehicleSellingPoint:new(name)
19 local self = {};
20 setmetatable(self, VehicleSellingPoint_mt);
21
22 self.id = name;
23
24 self.sellTriggerId = getChildAt(self.id, 0);
25 self.sellIconId = getChildAt(self.sellTriggerId, 0);
26 addTrigger(self.sellTriggerId, "triggerCallback", self);
27
28 self.sellAreaTriggerId = getChildAt(self.id, 1);
29 addTrigger(self.sellAreaTriggerId, "sellAreaTriggerCallback", self);
30
31 self.shapesCount = {};
32 self.currentVehicle = nil;
33 self.currentVehicleId = 0;
34
35 self.activateText = g_i18n:getText("SellSpecificVehicle");
36
37 self.isEnabled = true;
38 self.objectActivated = false;
39
40 if g_isDemo or g_isGamescomVersion or (not g_currentMission.missionInfo:isa(FSCareerMissionInfo)) then
41 setVisibility(self.sellIconId, false);
42 end;
43
44 return self;
45end;
46
47function VehicleSellingPoint:delete()
48
49 if g_currentMission:getIsClient() then
50 removeTrigger(self.sellTriggerId);
51 removeTrigger(self.sellAreaTriggerId);
52 end;
53end;
54
55function VehicleSellingPoint:getIsActivatable()
56 return self.isEnabled and g_currentMission.controlPlayer;
57end;
58
59function VehicleSellingPoint:drawActivate()
60 return;
61end;
62
63function VehicleSellingPoint:onActivateObject()
64 -- TODO: check if there is a vehicle at all inside the trigger
65
66 local sellVehicleDialog = g_gui:showGui("SellVehicleDialog");
67 self:determineCurrentVehicle();
68 g_sellVehicleDialog:setVehicle(self.currentVehicle, self.currentVehicleId);
69 g_sellVehicleDialog:setCallbacks(nil, nil);
70 g_sellVehicleDialog:setReturnScreen("");
71
72 self.objectActivated = true;
73 g_currentMission:addActivatableObject(self);
74end;
75
76function VehicleSellingPoint:update(dt)
77 if self.isEnabled then
78 rotate(self.sellIconId, 0, 0.002 * dt, 0);
79 end;
80end;
81
82function VehicleSellingPoint:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
83
84 if self.isEnabled and not g_isGamescomVersion and not g_isDemo and g_currentMission.missionInfo:isa(FSCareerMissionInfo) then
85 if onEnter or onLeave then
86 if g_currentMission.player ~= nil and otherId == g_currentMission.player.rootNode then
87 if onEnter then
88 if not self.objectActivated then
89 g_currentMission:addActivatableObject(self);
90 self.objectActivated = true;
91 end
92 else
93 if self.objectActivated then
94 g_currentMission:removeActivatableObject(self);
95 self.objectActivated = false;
96 end
97 end;
98 end;
99 end;
100 end;
101
102end;
103
104function VehicleSellingPoint:sellAreaTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
105 if onEnter or onLeave then
106 if self.shapesCount[otherId] == nil then
107 self.shapesCount[otherId] = 0;
108 end;
109
110 if onEnter then
111 self.shapesCount[otherId] = self.shapesCount[otherId]+1;
112 elseif onLeave then
113 self.shapesCount[otherId] = self.shapesCount[otherId]-1;
114 end;
115
116 self:determineCurrentVehicle();
117 end;
118end;
119
120function VehicleSellingPoint:determineCurrentVehicle()
121 self.currentVehicle = nil;
122
123 for vehicleId, count in pairs(self.shapesCount) do
124 if count > 0 then
125 self.currentVehicle = g_currentMission.nodeToVehicle[vehicleId];
126 self.currentVehicleId = vehicleId;
127 if self.currentVehicle ~= nil then
128 break;
129 end;
130 end;
131 -- invalid vehicle (not existing or left), remove from list
132 self.shapesCount[vehicleId] = nil;
133 end;
134
135-- if self.currentVehicle ~= nil then
136-- print("VEHICLE: " .. tostring(self.currentVehicle.configFileName));
137-- else
138-- print("NO VEHICLE");
139-- end;
140
141end;
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