Skip to content

Commit cdab718

Browse files
committed
v1.1-hotfix
- Stop object preview when the UI is closed. - Automatically cleanup spawned objects from the dropdown list if an object gets removed in another way other than the script itself (delete gun for example).
1 parent f9a2ab3 commit cdab718

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

object_spawner.lua

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,12 @@ object_spawner:add_imgui(function()
295295
end
296296
if spawned_props[1] ~= nil then
297297
ImGui.Text("Spawned Objects:")
298-
ImGui.PushItemWidth(180)
298+
ImGui.PushItemWidth(230)
299299
spawned_index, used = ImGui.Combo("##Spawned Objects", spawned_index, filteredSpawnNames, #spawned_props)
300300
ImGui.PopItemWidth()
301301
selectedObject = spawned_props[spawned_index + 1]
302302
ImGui.SameLine()
303-
if ImGui.Button(" Delete ") then
303+
if ImGui.Button("Delete") then
304304
script.run_in_fiber(function(script)
305305
if ENTITY.DOES_ENTITY_EXIST(selectedObject) then
306306
ENTITY.SET_ENTITY_AS_MISSION_ENTITY(selectedObject)
@@ -314,7 +314,7 @@ object_spawner:add_imgui(function()
314314
spawned_index = spawned_index - 1
315315
end
316316
if attached then
317-
attachPos = { x = 0.0, y = 0.0, z = 0.0, rotX = 0.0, rotY = 0.0, rotZ = 0.0}
317+
attachPos = { x = 0.0, y = 0.0, z = 0.0, rotX = 0.0, rotY = 0.0, rotZ = 0.0}
318318
attached = false
319319
attachedToSelf = false
320320
attachedToPlayer = false
@@ -480,7 +480,7 @@ object_spawner:add_imgui(function()
480480
if attached then
481481
ENTITY.ATTACH_ENTITY_TO_ENTITY(selectedObject, plyr, PED.GET_PED_BONE_INDEX(plyr, boneData.ID), 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, false, false, false, false, 2, true, 1)
482482
else
483-
ENTITY.SET_ENTITY_COORDS(selectedObject, coords.x + (forwardX * 2), coords.y + (forwardY * 2), coords.z)
483+
ENTITY.SET_ENTITY_COORDS(selectedObject, coords.x + (forwardX * 3), coords.y + (forwardY * 3), coords.z)
484484
ENTITY.SET_ENTITY_HEADING(selectedObject, heading)
485485
OBJECT.PLACE_OBJECT_ON_GROUND_OR_OBJECT_PROPERLY(selectedObject)
486486
end
@@ -495,7 +495,7 @@ object_spawner:add_imgui(function()
495495
end
496496
end)
497497
script.register_looped("Preview", function(preview)
498-
if previewLoop then
498+
if previewLoop and gui.is_open() then
499499
local currentHeading = ENTITY.GET_ENTITY_HEADING(previewEntity)
500500
if currentObjectPreview ~= previewEntity then
501501
ENTITY.DELETE_ENTITY(previewEntity)
@@ -520,9 +520,11 @@ script.register_looped("Preview", function(preview)
520520
OBJECT.SET_OBJECT_ALLOW_LOW_LOD_BUOYANCY(previewEntity, false)
521521
currentObjectPreview = ENTITY.GET_ENTITY_MODEL(previewEntity)
522522
previewStarted = true
523-
if PED.IS_PED_STOPPED(self.get_ped()) then
524-
while true do
525-
preview:yield()
523+
end
524+
if PED.IS_PED_STOPPED(self.get_ped()) then
525+
while true do
526+
preview:yield()
527+
if gui.is_open() then
526528
currentHeading = currentHeading + 1
527529
ENTITY.SET_ENTITY_HEADING(previewEntity, currentHeading)
528530
preview:sleep(10)
@@ -531,14 +533,16 @@ script.register_looped("Preview", function(preview)
531533
previewStarted = false
532534
end
533535
if not PED.IS_PED_STOPPED(self.get_ped()) or not previewStarted then
534-
ENTITY.SET_ENTITY_HEADING(previewEntity, currentHeading)
535536
previewStarted = false
536537
break
537538
end
539+
else
540+
ENTITY.DELETE_ENTITY(previewEntity)
541+
previewStarted = false
538542
end
539-
else
540-
return
541543
end
544+
else
545+
return
542546
end
543547
end
544548
else
@@ -570,5 +574,10 @@ script.register_looped("edit mode", function()
570574
ENTITY.SET_ENTITY_ROTATION(selectedObject, current_rotation.x, current_rotation.y, current_rotation.z + spawnRot.z, 2, true)
571575
end
572576
end
573-
end
577+
for k, v in ipairs(spawned_props) do
578+
if not ENTITY.DOES_ENTITY_EXIST(v) then
579+
table.remove(spawned_props, k)
580+
end
581+
end
582+
end
574583
end)

0 commit comments

Comments
 (0)