Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- AnimatedMapObject
- AnimatedObject
- Bale
- Basketball
- BgaSellStation
- BunkerSilo
- BuyingStation
- DigitalDisplay
- DogBall
- HelpIcons
- InlineBale
- InlineBaleSingle
- LoadingStation
- MountableObject
- NightIllumination
- Nightlight2
- NightlightFlicker
- PackedBale
- PhysicsObject
- ProductionPoint
- Rotator
- SellingStation
- SimParticleSystem
- Storage
- SunAdmirer
- TourIconsMobile
- UnloadingStation
- VehicleSellingPoint
- WildlifeSpawner
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
VehicleSellingPoint
DescriptionClass for vehicle selling pointFunctions
- delete
- determineCurrentVehicles
- getOwnerFarmId
- load
- new
- openMenu
- playerFarmChanged
- registerXMLPaths
- sellAreaTriggerCallback
- setOwnerFarmId
- triggerCallback
- updateIconVisibility
delete
DescriptionDeleting vehicle selling pointDefinition
delete()Code
66 | function VehicleSellingPoint:delete() |
67 | g_messageCenter:unsubscribeAll(self) |
68 | |
69 | if self.playerTrigger ~= nil then |
70 | removeTrigger(self.playerTrigger) |
71 | self.playerTrigger = nil |
72 | end |
73 | if self.sellTriggerNode ~= nil then |
74 | removeTrigger(self.sellTriggerNode) |
75 | self.sellTriggerNode = nil |
76 | end |
77 | |
78 | g_currentMission.activatableObjectsSystem:removeActivatable(self.activatable) |
79 | |
80 | self.sellIcon = nil |
81 | end |
determineCurrentVehicles
DescriptionDetermine current vehicleDefinition
determineCurrentVehicles()Code
136 | function VehicleSellingPoint:determineCurrentVehicles() |
137 | local vehicles = {} |
138 | |
139 | -- Find first vehicle, then get its rood and all children |
140 | for shapeId, inRange in pairs(self.vehicleShapesInRange) do |
141 | if inRange ~= nil and entityExists(shapeId) then |
142 | local vehicle = g_currentMission.nodeToObject[shapeId] |
143 | if vehicle ~= nil then |
144 | local isRidable = SpecializationUtil.hasSpecialization(Rideable, vehicle.specializations) |
145 | if not isRidable and not vehicle.isPallet and vehicle.getSellPrice ~= nil and vehicle.price ~= nil then |
146 | local items = vehicle.rootVehicle:getChildVehicles() |
147 | for i = 1, #items do |
148 | local item = items[i] |
149 | if (self:getOwnerFarmId() == AccessHandler.EVERYONE or self:getOwnerFarmId() == item:getOwnerFarmId()) and g_currentMission.accessHandler:canPlayerAccess(item) then |
150 | -- uniqueness check builtin |
151 | table.addElement(vehicles, item) |
152 | end |
153 | end |
154 | end |
155 | end |
156 | else |
157 | self.vehicleShapesInRange[shapeId] = nil |
158 | end |
159 | end |
160 | |
161 | -- Consistent order independent on which piece of the vehicle entered the trigger first |
162 | table.sort(vehicles, function(a, b) |
163 | return a.rootNode < b.rootNode |
164 | end) |
165 | |
166 | return vehicles |
167 | end |
getOwnerFarmId
DescriptionDefinitiongetOwnerFarmId()Code
198 | function VehicleSellingPoint:getOwnerFarmId() |
199 | return self.ownerFarmId |
200 | end |
load
DescriptionDefinitionload()Code
39 | function VehicleSellingPoint:load(components, xmlFile, key, i3dMappings) |
40 | self.playerTrigger = xmlFile:getValue(key.."#playerTriggerNode", nil, components, i3dMappings) |
41 | self.sellIcon = xmlFile:getValue(key.."#iconNode", nil, components, i3dMappings) |
42 | self.sellTriggerNode = xmlFile:getValue(key.."#sellTriggerNode", nil, components, i3dMappings) |
43 | self.ownWorkshop = xmlFile:getValue(key.."#ownWorkshop", false) |
44 | self.mobileWorkshop = xmlFile:getValue(key.."#mobileWorkshop", false) |
45 | |
46 | if not CollisionFlag.getHasFlagSet(self.playerTrigger, CollisionFlag.TRIGGER_PLAYER) then |
47 | Logging.xmlWarning(xmlFile, "Missing collision mask bit '%d'. Please add this bit to vehicle selling player trigger node '%s'", CollisionFlag.getBit(CollisionFlag.TRIGGER_PLAYER), I3DUtil.getNodePath(self.playerTrigger)) |
48 | end |
49 | addTrigger(self.playerTrigger, "triggerCallback", self) |
50 | |
51 | if not CollisionFlag.getHasFlagSet(self.sellTriggerNode, CollisionFlag.TRIGGER_VEHICLE) then |
52 | Logging.xmlWarning(xmlFile, "Missing collision mask bit '%d'. Please add this bit to vehicle sell area trigger node '%s'", CollisionFlag.getBit(CollisionFlag.TRIGGER_VEHICLE), I3DUtil.getNodePath(self.sellTriggerNode)) |
53 | end |
54 | addTrigger(self.sellTriggerNode, "sellAreaTriggerCallback", self) |
55 | |
56 | self.activatable = VehicleSellingPointActivatable.new(self, self.ownWorkshop) |
57 | |
58 | g_messageCenter:subscribe(MessageType.PLAYER_FARM_CHANGED, self.playerFarmChanged, self) |
59 | g_messageCenter:subscribe(MessageType.PLAYER_CREATED, self.playerFarmChanged, self) |
60 | |
61 | self:updateIconVisibility() |
62 | end |
new
DescriptionCreating vehicle selling pointDefinition
new(integer id)Arguments
integer | id | node id |
table | instance | Instance of object |
25 | function VehicleSellingPoint.new() |
26 | local self = setmetatable({}, VehicleSellingPoint_mt) |
27 | |
28 | self.vehicleShapesInRange = {} |
29 | |
30 | self.activateText = "" |
31 | |
32 | self.isEnabled = true |
33 | |
34 | return self |
35 | end |
openMenu
DescriptionOn activate objectDefinition
openMenu()Code
85 | function VehicleSellingPoint:openMenu() |
86 | local vehicles = self:determineCurrentVehicles() |
87 | |
88 | g_workshopScreen:setSellingPoint(self, not self.ownWorkshop, self.ownWorkshop, self.mobileWorkshop) |
89 | g_workshopScreen:setVehicles(vehicles) |
90 | g_gui:showGui("WorkshopScreen") |
91 | end |
playerFarmChanged
DescriptionDefinitionplayerFarmChanged()Code
183 | function VehicleSellingPoint:playerFarmChanged(player) |
184 | if player == g_currentMission.player then |
185 | self:updateIconVisibility() |
186 | end |
187 | end |
registerXMLPaths
DescriptionDefinitionregisterXMLPaths()Code
13 | function VehicleSellingPoint.registerXMLPaths(schema, basePath) |
14 | schema:register(XMLValueType.NODE_INDEX, basePath .. "#playerTriggerNode", "Player trigger node") |
15 | schema:register(XMLValueType.NODE_INDEX, basePath .. "#iconNode", "Icon node") |
16 | schema:register(XMLValueType.NODE_INDEX, basePath .. "#sellTriggerNode", "Sell trigger node") |
17 | schema:register(XMLValueType.BOOL, basePath .. "#ownWorkshop", "Owned by player", false) |
18 | schema:register(XMLValueType.BOOL, basePath .. "#mobileWorkshop", "Workshop is on vehicle", false) |
19 | end |
sellAreaTriggerCallback
DescriptionSell area trigger callbackDefinition
sellAreaTriggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)Arguments
integer | triggerId | id of trigger |
integer | otherId | id of actor |
boolean | onEnter | on enter |
boolean | onLeave | on leave |
boolean | onStay | on stay |
122 | function VehicleSellingPoint:sellAreaTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay, otherShapeId) |
123 | if otherShapeId ~= nil and (onEnter or onLeave) then |
124 | if onEnter then |
125 | self.vehicleShapesInRange[otherShapeId] = true |
126 | elseif onLeave then |
127 | self.vehicleShapesInRange[otherShapeId] = nil |
128 | end |
129 | |
130 | g_workshopScreen:updateVehicles(self, self:determineCurrentVehicles()) |
131 | end |
132 | end |
setOwnerFarmId
DescriptionDefinitionsetOwnerFarmId()Code
191 | function VehicleSellingPoint:setOwnerFarmId(ownerFarmId) |
192 | self.ownerFarmId = ownerFarmId |
193 | self:updateIconVisibility() |
194 | end |
triggerCallback
DescriptionTrigger callbackDefinition
triggerCallback(integer triggerId, integer otherId, boolean onEnter, boolean onLeave, boolean onStay)Arguments
integer | triggerId | id of trigger |
integer | otherId | id of actor |
boolean | onEnter | on enter |
boolean | onLeave | on leave |
boolean | onStay | on stay |
100 | function VehicleSellingPoint:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay) |
101 | if self.isEnabled and g_currentMission.missionInfo:isa(FSCareerMissionInfo) then |
102 | if onEnter or onLeave then |
103 | if g_currentMission.player ~= nil and otherId == g_currentMission.player.rootNode then |
104 | if onEnter then |
105 | g_currentMission.activatableObjectsSystem:addActivatable(self.activatable) |
106 | else |
107 | g_currentMission.activatableObjectsSystem:removeActivatable(self.activatable) |
108 | self:determineCurrentVehicles() |
109 | end |
110 | end |
111 | end |
112 | end |
113 | end |
updateIconVisibility
DescriptionTurn the icon on or off depending on the current game and the players farmDefinition
updateIconVisibility()Code
171 | function VehicleSellingPoint:updateIconVisibility() |
172 | if self.sellIcon ~= nil then |
173 | local isAvailable = self.isEnabled and g_currentMission.missionInfo:isa(FSCareerMissionInfo) |
174 | local farmId = g_currentMission:getFarmId() |
175 | local visibleForFarm = farmId ~= FarmManager.SPECTATOR_FARM_ID and (self:getOwnerFarmId() == AccessHandler.EVERYONE or farmId == self:getOwnerFarmId()) |
176 | |
177 | setVisibility(self.sellIcon, isAvailable and visibleForFarm) |
178 | end |
179 | end |