-
Member
Strange Bug with Eluna, need help
I am absolutely stumped. I have a function prepareNPCs() that registers an event to a list of creatures. I call this when Eluna reloads. It works as expected.
But if I call prepareNPCs() later, after I add more items to the list, the event function never gets fired, as if the RegisterCreatureEvent doesn't work.
I'm baffled. What's the difference between registering NPCs on eluna reload and registering them later?
Call at startup:
(I've made it SendWorldMessage the command)
12:32:42 RegisterCreatureEvent(299,4,mobKill)
12:32:42 RegisterCreatureEvent(69,4,mobKill)
12:32:42 RegisterCreatureEvent(1995,4,mobKill)
Call after adding another item to the list and then using a command that calls the prepareNPCs() function
12:33:13 RegisterCreatureEvent(299,4,mobKill)
12:33:13 RegisterCreatureEvent(69,4,mobKill)
12:33:13 RegisterCreatureEvent(1995,4,mobKill)
12:33:13 RegisterCreatureEvent(721,4,mobKill)
12:33:13 Reloaded.
And yet the event does not fire when an npc with entry 721 is killed.
Only when I reload Eluna again does the event get properly registered.
Code:
local function prepareNPCs()
local dbRes = WorldDBQuery("SELECT nentry,type FROM v_npc");
if dbRes ~= nil then
for x=1,dbRes:GetRowCount(),1 do
RegisterCreatureEvent(dbRes:GetInt32(0),4,mobKill);
SendWorldMessage("RegisterCreatureEvent("..dbRes:GetInt32(0)..",4,mobKill)");
if dbRes:GetInt8(1)==1 then
RegisterCreatureEvent(dbRes:GetInt32(0),37,VLHandler.qremove,1);
end
dbRes:NextRow();
end
end
end
local function vcomms(event,player,command)
if player:GetGMRank()>=3 then
if command=="vtest" then
prepareNPCs();
player:SendBroadcastMessage("Reloaded.");
return false;
end
end
end
local function onLoad()
RegisterPlayerEvent(42, vcomms);
prepareNPCs();
RegisterGameObjectGossipEvent(lGOB,1,VLHandler.useBag);
end
onLoad();
I don't understand what is making a world of difference here. I've registered events for creatures post-load before, and I've never encountered this problem.
Thanks in advance for any help.
-
Member
Rochet has the answer:
If a creature does not have any lua events registered, then due to the system using the AI systems of the core, it is not possible to suddenly add new hooks to the creature.
You have to register some event, a dummy event .. any kind of AI event on the creature before the creature is spawned ingame.
Then you can add new hooks as you like.
This needs to be done so that when the creature is initially spawned, he gets a lua AI chosen.
-
Post Thanks / Like - 1 Thanks
stoneharry (1 members gave Thanks to Vale the Violet Mote for this useful post)