FS 17 Modding Guide

Giants Editor Tutorials, Mods & Friends

Heating Plant Placeable

We are gonna learn how to  write a heating plant placeable script.

new

Description

Creating placeable high pressure washer

Definition

new(boolean isServer, boolean isClient, table customMt)

Arguments

boolean isServer is server
boolean isClient is client
table customMt custom metatable

Return Values

table instance Instance of object

Code

18 function HeatingPlantPlaceable:new(isServer, isClient, customMt)
19 local mt = customMt;
20 if mt == nil then
21 mt = HeatingPlantPlaceable_mt;
22 end;
23
24 local self = Placeable:new(isServer, isClient, mt);
25
26 registerObjectClassName(self, “HeatingPlantPlaceable”);
27
28 return self;
29 end;

delete

Description

Deleting heating plant

Definition

delete()

Code

33 function HeatingPlantPlaceable:delete()
34 if self.tipTrigger ~= nil then
35 self.tipTrigger:removeUpdateEventListener(self)
36 if self.tipTrigger.isRegistered then
37 self.tipTrigger:unregister()
38 end
39 self.tipTrigger:delete()
40 end
41
42 if self.exhaustEffect ~= nil then
43 Utils.releaseSharedI3DFile(self.exhaustEffect.filename, self.baseDirectory, true);
44 end
45
46 unregisterObjectClassName(self);
47 HeatingPlantPlaceable:superClass().delete(self);
48 end;

load

Description

Load heating plant

Definition

load(string xmlFilename, float x, float y, float z, float rx, float ry, float rz, boolean initRandom)

Arguments

string xmlFilename xml file name
float x x world position
float y z world position
float z z world position
float rx rx world rotation
float ry ry world rotation
float rz rz world rotation
boolean initRandom initialize random

Return Values

boolean success success

Code

61 function HeatingPlantPlaceable:load(xmlFilename, x,y,z, rx,ry,rz, initRandom)
62 if not HeatingPlantPlaceable:superClass().load(self, xmlFilename, x,y,z, rx,ry,rz, initRandom) then
63 return false;
64 end;
65
66 local xmlFile = loadXMLFile(“TempXML”, xmlFilename);
67
68 self.tipTrigger = TipTrigger:new(self.isServer, self.isClient)
69 if self.tipTrigger:load(Utils.indexToObject(self.nodeId, getXMLString(xmlFile, “placeable.heatingPlant#tipTrigger”))) then
70 self.tipTrigger:register(true)
71 self.tipTrigger:addUpdateEventListener(self)
72 else
73 self.tipTrigger:delete()
74 self.tipTrigger = nil
75 end
76
77 if self.isClient then
78 self.heatingPlantRotationNodes = Utils.loadRotationNodes(xmlFile, {}, “placeable.turnedOnRotationNodes.turnedOnRotationNode”, “heatingPlant”, self.nodeId);
79
80 local filename = getXMLString(xmlFile, “placeable.exhaust#filename”);
81 local node = Utils.indexToObject(self.nodeId, getXMLString(xmlFile, “placeable.exhaust#index”));
82 if filename ~= nil then
83 local i3dNode = Utils.loadSharedI3DFile(filename, self.baseDirectory, false, false, false);
84 if i3dNode ~= 0 then
85 self.exhaustEffect = {}
86 self.exhaustEffect.node = getChildAt(i3dNode, 0);
87 self.exhaustEffect.filename = filename
88 link(Utils.getNoNil(node, self.nodeId), self.exhaustEffect.node);
89 setVisibility(self.exhaustEffect.node, false);
90 setShaderParameter(self.exhaustEffect.node, “param”, 0, 0, 0, 0.4, false);
91 delete(i3dNode);
92 end
93 end
94 end
95
96 self.workingTime = 0
97
98 delete(xmlFile);
99
100 return true;
101 end;

readStream

Description

Called on client side on join

Definition

readStream(integer streamId, table connection)

Arguments

integer streamId stream ID
table connection connection

Code

107 function HeatingPlantPlaceable:readStream(streamId, connection)
108 HeatingPlantPlaceable:superClass().readStream(self, streamId, connection);
109 if connection:getIsServer() then
110 local tipTriggerId = readNetworkNodeObjectId(streamId);
111 self.tipTrigger:readStream(streamId, connection);
112 g_client:finishRegisterObject(self.tipTrigger, tipTriggerId);
113 end
114 end

writeStream

Description

Called on server side on join

Definition

writeStream(integer streamId, table connection)

Arguments

integer streamId stream ID
table connection connection

Code

120 function HeatingPlantPlaceable:writeStream(streamId, connection)
121 HeatingPlantPlaceable:superClass().writeStream(self, streamId, connection);
122 if not connection:getIsServer() then
123 writeNetworkNodeObjectId(streamId, self.tipTrigger.id);
124 self.tipTrigger:writeStream(streamId, connection);
125 g_server:registerObjectInStream(connection, self.tipTrigger);
126 end
127 end

collectPickObjects

Description

Collect pick objects

Definition

collectPickObjects(integer node)

Arguments

integer node node id

Code

132 function HeatingPlantPlaceable:collectPickObjects(node)
133 if self.tipTrigger == nil or self.tipTrigger.shovelTarget == nil or self.tipTrigger.shovelTarget.nodeId ~= node then
134 HeatingPlantPlaceable:superClass().collectPickObjects(self, node)
135 end
136 end;

update

Description

Update

Definition

update(float dt)

Arguments

float dt time since last call in ms

Code

141 function HeatingPlantPlaceable:update(dt)
142 HeatingPlantPlaceable:superClass().update(self, dt);
143
144 if self.isClient then
145 if self.workingTime > 0 then
146 self.workingTime = self.workingTime dt
147 if self.workingTime <= 0 then
148 if self.exhaustEffect ~= nil then
149 setVisibility(self.exhaustEffect.node, false);
150 end
151 end
152 end
153
154 Utils.updateRotationNodes(self, self.heatingPlantRotationNodes, dt, self.workingTime > 0);
155 end
156 end

updateTick

Description

Update tick

Definition

updateTick(float dt)

Arguments

float dt time since last call in ms

Code

161 function HeatingPlantPlaceable:updateTick(dt)
162 HeatingPlantPlaceable:superClass().updateTick(self, dt);
163 end

onUpdateEvent

Description

Called if someone filled in something

Definition

onUpdateEvent(table trigger, float fillDelta, integer fillType, table trailer, table tipTriggerTarget)

Arguments

table trigger trigger
float fillDelta delta filled in
integer fillType fill type filled in
table trailer object of trailer
table tipTriggerTarget tip trigger target

Code

172 function HeatingPlantPlaceable:onUpdateEvent(trigger, fillDelta, fillType, trailer, tipTriggerTarget)
173 if self.exhaustEffect ~= nil then
174 setVisibility(self.exhaustEffect.node, true);
175 end
176 self.workingTime = 120 * 1000
177 end
Advertisements
%d bloggers like this: