11addEvent (" mapfixes:client:loadAllComponents" , true )
22addEvent (" mapfixes:client:togOneComponent" , true )
33
4- local function loadOneMapFixComponent (name , data )
4+ local function loadOneMapFixComponent (name , data , wasToggled )
55 -- Clear the previous elements if any
66 local createdElements = data .createdElements
77 if createdElements then
@@ -34,9 +34,22 @@ local function loadOneMapFixComponent(name, data)
3434 setGarageOpen (garageID , false )
3535 end
3636 end
37+ -- Revert previously set model flags
38+ local modelFlagsToSet = data .modelFlagsToSet
39+ if modelFlagsToSet then
40+ for _ , v in pairs (modelFlagsToSet ) do
41+ engineSetModelFlag (v [1 ], v [2 ], not v [3 ])
42+ end
43+ end
3744
3845 -- Don't proceed if the component is disabled
3946 if not data .enabled then
47+
48+ -- Force restream world after unloading this component
49+ -- only if it was the only one toggled
50+ if wasToggled then
51+ engineRestreamWorld ()
52+ end
4053 return
4154 end
4255
@@ -60,7 +73,6 @@ local function loadOneMapFixComponent(name, data)
6073 if allocatedID then
6174 if not data .allocatedIDs then data .allocatedIDs = {} end
6275 data .allocatedIDs [# data .allocatedIDs + 1 ] = allocatedID
63-
6476 object = createObject (allocatedID , v .x , v .y , v .z , v .rx , v .ry , v .rz )
6577 if object then
6678 engineSetModelPhysicalPropertiesGroup (allocatedID , v .physicalPropertiesGroup )
@@ -94,6 +106,18 @@ local function loadOneMapFixComponent(name, data)
94106 setGarageOpen (garageID , true )
95107 end
96108 end
109+ -- Set model flags if any
110+ if modelFlagsToSet then
111+ for _ , v in pairs (modelFlagsToSet ) do
112+ engineSetModelFlag (v [1 ], v [2 ], v [3 ])
113+ end
114+ end
115+
116+ -- Force restream world after loading this component
117+ -- only if it was the only one toggled
118+ if wasToggled then
119+ engineRestreamWorld ()
120+ end
97121end
98122
99123local function loadMapFixComponents (mapFixComponentStatuses )
@@ -105,6 +129,7 @@ local function loadMapFixComponents(mapFixComponentStatuses)
105129 loadOneMapFixComponent (name , data )
106130 end
107131 end
132+ engineRestreamWorld ()
108133end
109134addEventHandler (" mapfixes:client:loadAllComponents" , localPlayer , loadMapFixComponents , false )
110135
@@ -116,7 +141,7 @@ local function toggleOneMapFixComponent(name, enable)
116141 return
117142 end
118143 data .enabled = (enable == true )
119- loadOneMapFixComponent (name , data )
144+ loadOneMapFixComponent (name , data , true )
120145 if eventName ~= " onClientResourceStop" then
121146 outputDebugString (" Map fix component '" .. name .. " ' is now " .. (data .enabled and " enabled" or " disabled" ))
122147 end
@@ -127,5 +152,6 @@ local function unloadAllMapFixComponents()
127152 for name , _ in pairs (mapFixComponents ) do
128153 toggleOneMapFixComponent (name , false )
129154 end
155+ engineRestreamWorld ()
130156end
131157addEventHandler (" onClientResourceStop" , resourceRoot , unloadAllMapFixComponents , false )
0 commit comments