@@ -64,24 +64,26 @@ function createColPatchObjects()
6464 g_placementObjs = {}
6565 g_placementIDObjs = {}
6666
67- for k ,v in ipairs (g_placementData ) do
68- if k % COL_CREATE_FRAME == 0 then
69- coroutine.yield ()
70- end
71-
72- local obj = createObject (v .id , v .x , v .y , v .z , v .rx , v .ry , v .rz )
73- if obj then
74- setElementDimension (obj , getWorkingDimension ())
75- setElementAlpha (obj , 0 )
76- if v .int > 0 and v .int < 256 then
77- setElementInterior (obj , v .int )
67+ if g_placementData then
68+ for k ,v in ipairs (g_placementData ) do
69+ if k % COL_CREATE_FRAME == 0 then
70+ coroutine.yield ()
7871 end
79- g_placementObjs [obj ] = v
8072
81- if not g_placementIDObjs [v .id ] then
82- g_placementIDObjs [v .id ] = {}
73+ local obj = createObject (v .id , v .x , v .y , v .z , v .rx , v .ry , v .rz )
74+ if obj then
75+ setElementDimension (obj , getWorkingDimension ())
76+ setElementAlpha (obj , 0 )
77+ if v .int > 0 and v .int < 256 then
78+ setElementInterior (obj , v .int )
79+ end
80+ g_placementObjs [obj ] = v
81+
82+ if not g_placementIDObjs [v .id ] then
83+ g_placementIDObjs [v .id ] = {}
84+ end
85+ table.insert (g_placementIDObjs [v .id ], obj )
8386 end
84- table.insert (g_placementIDObjs [v .id ], obj )
8587 end
8688 end
8789
9597
9698function destroyColPatchObjects ()
9799 local i = 0
98- for obj in pairs (g_placementObjs ) do
99- if i % COL_DESTROY_FRAME == 0 then
100- coroutine.yield ()
100+ if g_placementObjs then
101+ for obj in pairs (g_placementObjs ) do
102+ if i % COL_DESTROY_FRAME == 0 then
103+ coroutine.yield ()
104+ end
105+ destroyElement (obj )
106+ i = i + 1
101107 end
102- destroyElement (obj )
103- i = i + 1
104108 end
105109
106110 g_placementObjs = nil
@@ -175,17 +179,19 @@ end
175179
176180function loadAndReplaceCollision ()
177181 g_colElements = {}
178- for k ,colData in ipairs (g_colData ) do
179- if k % COL_LOAD_FRAME == 0 then
180- coroutine.yield ()
181- end
182-
183- local col = engineLoadCOL (colData .colFile )
184- if col then
185- if engineReplaceCOL (col , colData .colID ) then
186- table.insert (g_colElements , col )
187- else
188- destroyElement (col )
182+ if g_colData then
183+ for k ,colData in ipairs (g_colData ) do
184+ if k % COL_LOAD_FRAME == 0 then
185+ coroutine.yield ()
186+ end
187+
188+ local col = engineLoadCOL (colData .colFile )
189+ if col then
190+ if engineReplaceCOL (col , colData .colID ) then
191+ table.insert (g_colElements , col )
192+ else
193+ destroyElement (col )
194+ end
189195 end
190196 end
191197 end
@@ -194,27 +200,33 @@ function loadAndReplaceCollision()
194200end
195201
196202function restoreAndDestroyCollision ()
197- for k ,colData in ipairs (g_colData ) do
198- if k % COL_RESTORE_FRAME == 0 then
199- coroutine.yield ()
200- end
201- engineRestoreCOL (colData .colID )
202- end
203- for k ,col in ipairs (g_colElements ) do
204- if isElement (col ) then
203+ if g_colData then
204+ for k ,colData in ipairs (g_colData ) do
205205 if k % COL_RESTORE_FRAME == 0 then
206206 coroutine.yield ()
207207 end
208- destroyElement ( col )
208+ engineRestoreCOL ( colData . colID )
209209 end
210210 end
211-
212- g_colElements = nil
211+ if g_colElements then
212+ for k ,col in ipairs (g_colElements ) do
213+ if isElement (col ) then
214+ if k % COL_RESTORE_FRAME == 0 then
215+ coroutine.yield ()
216+ end
217+ destroyElement (col )
218+ end
219+ end
220+ g_colElements = nil
221+ end
222+
213223 destroyColPatchObjects ()
214224end
215225
216226-- Called after we finish loading to apply removed world objects in current map
217227function applyRemovedColPatches ()
228+ if not g_placementIDObjs then return end
229+ if not g_placementObjs then return end
218230 for i ,element in ipairs (getElementsByType (" removeWorldObject" )) do
219231 local model = getElementData (element , " model" )
220232 if g_placementIDObjs [model ] then
242254
243255local function onClientElementCreateDestroy ()
244256 if not g_placementData then return end
257+ if not g_placementIDObjs then return end
258+ if not g_placementObjs then return end
245259 if (getElementType (source ) ~= " removeWorldObject" ) then return end
246260
247261 local model = getElementData (source , " model" )
0 commit comments