Try this. I basically just added back in the GetWorldObject you removed.Code: [Select]-- Cauldronlocal CauldronItem = 200001local CauldronObj = 186472-- Chairlocal ChairItem = 200002local ChairObj = 186732-- bedlocal BedItem = 200003local BedObj = 13948-- vendor tentlocal VendortentItem = 200004local VendortentObj = 4000668local spawn = {}local function SpawnObj(plr, entry, despawn_time) local guid = plr:GetGUID() if spawn[guid] then local spawnedGobject = plr:GetMap():GetWorldObject(spawn[guid]) if spawnedGobject then spawnedGobject:RemoveFromWorld(true) spawn[guid] = nil else plr:SendNotification("You need to be closer to the existing object to despawn it") end else local x, y, z, o = plr:GetLocation() local gobject = plr:SummonGameObject(entry, x, y, z, o, despawn_time) if gobject then spawn[guid] = gobject:GetGUID() end endendlocal function Cauldron(event, plr, item, target) SpawnObj(plr, CauldronObj, 0)endlocal function Chair(event, plr, item, target) SpawnObj(plr, ChairObj, 0)endlocal function Bed(event, plr, item, target) SpawnObj(plr, BedObj, 5)endlocal function VendorTent(event, plr, item, target) SpawnObj(plr, VendortentObj, 0)endRegisterItemEvent(CauldronItem, 2, Cauldron)RegisterItemEvent(ChairItem, 2, Chair)RegisterItemEvent(BedItem, 2, Bed)RegisterItemEvent(VendortentItem, 2, VendorTent)
-- Cauldronlocal CauldronItem = 200001local CauldronObj = 186472-- Chairlocal ChairItem = 200002local ChairObj = 186732-- bedlocal BedItem = 200003local BedObj = 13948-- vendor tentlocal VendortentItem = 200004local VendortentObj = 4000668local spawn = {}local function SpawnObj(plr, entry, despawn_time) local guid = plr:GetGUID() if spawn[guid] then local spawnedGobject = plr:GetMap():GetWorldObject(spawn[guid]) if spawnedGobject then spawnedGobject:RemoveFromWorld(true) spawn[guid] = nil else plr:SendNotification("You need to be closer to the existing object to despawn it") end else local x, y, z, o = plr:GetLocation() local gobject = plr:SummonGameObject(entry, x, y, z, o, despawn_time) if gobject then spawn[guid] = gobject:GetGUID() end endendlocal function Cauldron(event, plr, item, target) SpawnObj(plr, CauldronObj, 0)endlocal function Chair(event, plr, item, target) SpawnObj(plr, ChairObj, 0)endlocal function Bed(event, plr, item, target) SpawnObj(plr, BedObj, 5)endlocal function VendorTent(event, plr, item, target) SpawnObj(plr, VendortentObj, 0)endRegisterItemEvent(CauldronItem, 2, Cauldron)RegisterItemEvent(ChairItem, 2, Chair)RegisterItemEvent(BedItem, 2, Bed)RegisterItemEvent(VendortentItem, 2, VendorTent)
Nope, It doesn't remove the objects, and I am not sure why, because, it really seems like would, reading the code.
Alright, I see the error now.Changelocal guid = plr:GetGUID()tolocal guid = plr:GetGUIDLow()The difference here is that GetGUID returns an uint64 number which is represented as an object.Each GetGUID returns a different object causing the lua table to map them to different locations.GetGUIDLow returns a normal number.To properly make the uint64 work as table key it might need to be converted to strings, but using lowguid is easier for this and might be faster.
-- Name Herelocal item = 200002local obj = 22713-- Codelocal spawn = {}local function SpawnObj(plr, entry, despawn_time) local guid = plr:GetGUIDLow() if spawn[guid] then local spawnedGobject = plr:GetMap():GetWorldObject(spawn[guid]) if spawnedGobject then spawnedGobject:RemoveFromWorld(true) spawn[guid] = nil end else local x, y, z, o = plr:GetLocation() local gobject = plr:SummonGameObject(entry, x, y, z, o, despawn_time) if gobject then spawn[guid] = gobject:GetGUID() end endendlocal function logoff(plr, entry) guid = plr.GetGUIDLow() spawn[guid] = nilend-- Spawn Functionlocal function use(event, plr, item, target) SpawnObj(plr, obj, 0)end-- RegistersRegisterItemEvent(item, 2, use)RegisterPlayerEvent(4, logoff)
Code: [Select]local function logoff(plr, entry) guid = plr.GetGUIDLow() spawn[guid] = nilend
local function logoff(plr, entry) guid = plr.GetGUIDLow() spawn[guid] = nilend