But what does inactive mean? That monster target list is empty? I'm still confused why it's getting recommended for handling monster walk when going by that logic it won't even be executed? Or maybe
Xikini is right and I'm missing something?
I'm also thinking about making the monsters permanently active because my use case doesn't need to worry about performance much(small number of monsters on server). I looked inside source files and onThink() function but on first look I couldn't find any simple solution.
It's not printing, because you didn't register it in the monster, I think.
you can use onSpawn to register it to the monsters globally..
Or if attaching to a specific creature.. via lua, both would use this line
Lua:
creature:registerEvent("name_of_creatureEvent")
single monsters you can put it into the monsters.xml file like this..
XML:
<script>
<event name="name_of_creatureEvent" />
</script>
About onThink itself.. yeah it's only when the monster is classified as active.
I haven't attempted to read the source code, but what happens in-game, is that it only triggers when a player is nearby, and the creature 'wakes up', doing normal auto walking stuff.
I'd say like.. 30 tiles away, +- a floor. (unless it's floor 7 or 6) then it's just -1/+1 floor, cuz of that interaction.
And probably would also not trigger on a god?
So unless you can read and alter source code..
My work-around to this, if you need it to always be active.. or least always be able to trigger..
Would be to make a looping addEvent.
Lua:
addEvent(loopingFunction, 1000, creature:getId())
Lua:
local function loopingFunction(creatureId)
local creature = Creature(creatureId)
if not creature then
return
end
print("Working.")
addEvent(loopingFunction, 1000, creatureId)
end
And then you would 'attach' this to any creature you want, and would replace your onThink event entirely.
The only caveat to the above solution, is that even tho we are setting the timer to trigger every 1000 milliseconds, is that it's 1000ms + time to execute the functions up to that point. (1001 milliseconds.. and over 1000 seconds, it would trigger 1 less time then expected)
So generally it'll be slightly slower then once per second.. where onThink is triggered via source, every 1 second, based on the runtime of the application.
But that minor time discrepancy won't really be an issue because we're waiting for the monster to walk around anyway.