I'm testing GAMEOBJECT_EVENT_ON_SPAWN, trying to get the nearest player to a specific type of object (mining node). I have the following code:
(The output is just going to the server console at the moment.)
GAMEOBJECT_EVENT_ON_SPAWN = 2
local goID = 1731 -- copper vein
local function object_spawn(event, go)
print("object spawned: "..go:GetName().." "..go:GetDBTableGUIDLow())
nearestPlayer = go:GetNearestPlayer(10)
nearestPlayerName = nearestPlayer:GetName()
print("nearest player: "..nearestPlayerName)
RegisterGameObjectEvent(goID, GAMEOBJECT_EVENT_ON_SPAWN, object_spawn)
One question I have is, what actually triggers the spawn event for a game object? I notice that I get some output at the console indicating a number of objects spawning, based on the code, so it seems to be working in that sense. However, if I am in game and standing next to an indicated game object and wait for it to respawn, no output occurs, and it does not detect my character as I would have expected from :GetNearestPlayer(). I have tried locating my character next to several instances of the game object during respawning, and the :GetNearestPlayer() method never seems to be triggered. In fact, the presumed spawn event does not seem to be triggered at all -- no print to the console. What am I missing? Is object respawning not the same as GAMEOBJECT_EVENT_ON_SPAWN?
Incidentally, I tried similar code with CREATURE_EVENT_ON_SPAWN, and it seems to work as expected -- the :GetNearestPlayer() method is indeed triggered. Any insight would be helpful. Thank you.