nivekzin
New Member
- Joined
- Sep 24, 2012
- Messages
- 3
- Reaction score
- 0
I'm trying to setup a Shiny spawn on my PokeTibia server, but I'm having some problems with this onSpawn callback.
I understood that when I summon mannually the monster it will pass "again" in the onSpawn for that new creature, so it seems a made a semi-infinite loop and I would like to avoid that that new creature prevent to pass through this loop or at least had a flag to prevent to create a new creature.
Is there any way I could solve this?
I understood that when I summon mannually the monster it will pass "again" in the onSpawn for that new creature, so it seems a made a semi-infinite loop and I would like to avoid that that new creature prevent to pass through this loop or at least had a flag to prevent to create a new creature.
Is there any way I could solve this?
Lua:
local function isShiny()
chance = 400
if math.random(1, 1000) <= chance then
return true
end
return false
end
Lua:
ec.onSpawn = function(self, position, startup, artificial)
if artificial then
return true
end
if startup and self:isMonster() then
if isShiny(self) then
doRemoveCreature(self:getId())
spawnedShiny = Game.createMonster("Shiny "..self:getName(), position, false, false)
if spawnedShiny ~= nil then
doRemoveCreature(spawnedShiny:getId())
self = spawnedShiny
Game.createMonster(self:getName(), position, false, false)
print("A "..self:getName().." has spawned! Go check it!")
print("POS: X -"..position.x.." Y - "..position.y.. " / Health: "..self:getHealth())
return false
end
end
end
spawnedMob = Game.createMonster(self:getName(), position, false, false)
self = spawnedMob
doRemoveCreature(spawnedMob:getId())
return true
end