-- Cauldronlocal CauldronItem = 200001local CauldronObj = 186472-- Chairlocal ChairItem = 200002local ChairObj = 186732-- bedlocal BedItem = 200003local BedObj = 13948-- vendor tentlocal VendortentItem = 200004local VendortentObj = 4000668local function SpawnObj(plr, entry, despawn_time) plr:SummonGameObject(entry, plr:GetX(), plr:GetY(), plr:GetZ(), plr:GetO(), despawn_time)endlocal 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)
local x,y,z,o = plr:GetLocation()local tar = plr:SpawnCreature( 36, x, y, z, o )-- save guid somewhere, I save it to global variable GUIDL, but then again this is just an example codeGUIDL = tar:GetGUID()-- Later access the creature by the saved guid:local creature = plr:GetMap():GetWorldObject( GUIDL )creature:SendUnitSay("asd", 0)
-- Cauldronlocal CauldronItem = 200001local CauldronObj = 186472-- Chairlocal ChairItem = 200002local ChairObj = 186732-- bedlocal BedItem = 200003local BedObj = 13948-- vendor tentlocal VendortentItem = 200004local VendortentObj = 4000668local GUIDL = 0local function SpawnObj(plr, entry, despawn_time) tar = plr:SummonGameObject(entry, plr:GetX(), plr:GetY(), plr:GetZ(), plr:GetO(), despawn_time) GUIDL = tar:GetGUID()endlocal function Cauldron(event, plr, item, target) if GUIDL:IsInWorld() == "IsInWorld" then GUIDL:RemoveFromWorld( deleteFromDB ) else SpawnObj(plr, CauldronObj, 0 ) endendlocal 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 GUIDLlocal function SpawnObj(plr, entry, despawn_time) if GUIDL then local spawnedGobject = plr:GetMap():GetWorldObject(GUIDL) if spawnedGobject then spawnedGobject:RemoveFromWorld(true) GUIDL = nil end else local gobject = plr:SummonGameObject(entry, plr:GetX(), plr:GetY(), plr:GetZ(), plr:GetO(), despawn_time) GUIDL = gobject:GetGUID() 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)
Wow 10/10, thanks. This works, and the objects despawn on teh second use. But, are you ready for the next issue? If I spawn the chair, and then someone else has the chair item, and they try to spawn one, it de-spawns mine. I'm wondering if there is a way to have the code function differently for each player.
Quote from: "jar0fair"Wow 10/10, thanks. This works, and the objects despawn on teh second use. But, are you ready for the next issue? If I spawn the chair, and then someone else has the chair item, and they try to spawn one, it de-spawns mine. I'm wondering if there is a way to have the code function differently for each player.Create a table and use it like this:gameobjectlist[playerguid] = gobject:GetGUID()If you can't do it with that hint, just tell us and we'll show you. (This is better for learning purposes instead of spoon feeding you )
local spawns = {GUIDLowner = unit}local function SpawnObj(plr, entry, despawn_time) if spawns[2] then local spawnedGobject = plr:GetMap():GetWorldObject(GUIDL) if spawnedGobject then spawnedGobject:RemoveFromWorld(true)spawns = { GUIDL = nilowner = unit} end else local gobject = plr:SummonGameObject(entry, plr:GetX(), plr:GetY(), plr:GetZ(), plr:GetO(), despawn_time) spawns = {GUIDL = gobject:GetGUID()owner = unit} endend
Quote from: "Kaev"Quote from: "jar0fair"Wow 10/10, thanks. This works, and the objects despawn on teh second use. But, are you ready for the next issue? If I spawn the chair, and then someone else has the chair item, and they try to spawn one, it de-spawns mine. I'm wondering if there is a way to have the code function differently for each player.Create a table and use it like this:gameobjectlist[playerguid] = gobject:GetGUID()If you can't do it with that hint, just tell us and we'll show you. (This is better for learning purposes instead of spoon feeding you )Thank you, I really am trying to learn how to do this stuff myself but, I am pretty new yet. Getting pretty frustrated with myself for not being able to figure it out. I've seen how to structure a table once or twice, but I don't think I am doing it right. This is what I did.Code: [Select]local spawns = {GUIDLowner = unit}local function SpawnObj(plr, entry, despawn_time) if spawns[2] then local spawnedGobject = plr:GetMap():GetWorldObject(GUIDL) if spawnedGobject then spawnedGobject:RemoveFromWorld(true)spawns = { GUIDL = nilowner = unit} end else local gobject = plr:SummonGameObject(entry, plr:GetX(), plr:GetY(), plr:GetZ(), plr:GetO(), despawn_time) spawns = {GUIDL = gobject:GetGUID()owner = unit} endend
local table = {}
table[123] = "foo"table["bar"] = 234table[2] = 12345
local tablevalue = table[123] -- this will return "foo"local tablevalue2 = table["bar"] -- this will return 234local tablevalue3 = table[2] -- this will return 12345
table[plr:GetGUID()] = gobject:GetGUID() -- now you can access the GUID of the object via the GUID of the player
local spawn = {}local function SpawnObj(plr, entry, despawn_time) if spawn then local spawnedGobject = plr:GetMap():GetWorldObject(spawn[plr:GetGUID()]) if spawnedGobject then spawnedGobject:RemoveFromWorld(true) spawn[plr:GetGUID()] = nil end else local gobject = plr:SummonGameObject(entry, plr:GetX(), plr:GetY(), plr:GetZ(), plr:GetO(), despawn_time) spawn[plr:GetGUID()] = gobject:GetGUID() endend
if spawn then
if spawn[plr:GetGUID()] then
This is because in your code you checkCode: [Select]if spawn thenBut spawn is always defined. The check is useless.The code inside the IF statement is run and it errors because the value for the key plr:GetGUID() is nil in the spawn table.What you should check instead isCode: [Select]if spawn[plr:GetGUID()] then
-- 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) if spawn[plr:GetGUID()] then spawn[plr:GetGUID()]:RemoveFromWorld(true) spawn[plr:GetGUID()] = nil else gobject = plr:SummonGameObject(entry, plr:GetX(), plr:GetY(), plr:GetZ(), plr:GetO(), despawn_time) spawn[plr:GetGUID()] = gobject:GetGUID() 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)