- Joined
- Apr 13, 2008
- Messages
- 669
- Reaction score
- 20
I've just recently started converting my old scripts to TFS 1.3's revscriptsys and for the life of mine I can't figure out how to register an onDeath event for a newly created monster. I know I could do it this way with TFS 0.4 (although the event had to be registered in xml).
Anyone knows how to do it properly? I'd like to take advantage of the ability to have everything in .lua and avoid registering events in monsters.
There are no errors in the console, just that onDeath doesn't fire when I kill these mobs.
Anyone knows how to do it properly? I'd like to take advantage of the ability to have everything in .lua and avoid registering events in monsters.
There are no errors in the console, just that onDeath doesn't fire when I kill these mobs.
Lua:
local storage = G_storage.svargrond_arena
boss_death = CreatureEvent('arena_boss_death')
boss_death:type('death')
function boss_death.onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
print('on death')
setCanEnterNextRoom(mostdamagekiller, true)
return true
end
local start_tp = MoveEvent()
start_tp:type('stepin')
for k, v in pairs(arena_monsters) do start_tp:aid(k) end
-- Enter next arena teleport
function start_tp.onStepIn(creature, item, position, fromPosition)
if not creature:isPlayer() then
return false
end
if not canEnterNextRoom(creature) then
creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have to kill the boss first!")
return false
end
if not isArenaRoomFree(item.actionid) then
creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Someone is fighting on the other side. You have to wait.")
return false
end
local arena_level = creature:getStorageValue(storage['did_arena_level'])
arena_level = arena_level < 1 and 0 or math.min(arena_level, 2)
local level_offset = arena_level * 10 + item.actionid
local tile = Item(item.actionid) -- a bit confusing, but tp's AID = UID of the tile in the next room
if not tile then -- means that's the last tp so the arena is complete
creature:teleportTo(arena_kick_pos)
creature:setStorageValue(storage['did_arena_level'], arena_level + 1)
creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Congratulations! You have completed the ".. getArenaLevelName(arena_level) .." arena!")
return true
end
local next_pos = tile:getPosition()
local monster = Monster(Game.getStorageValue(level_offset))
if monster and monster:isMonster() then
print(monster:getName() .. ' is alive. Killing now!')
monster:remove()
end
monster = Game.createMonster(arena_monsters[level_offset], Position(next_pos.x - 1, next_pos.y - 1, next_pos.z))
Game.setStorageValue(level_offset, monster)
-- tried to register each one separetely or both but still onDeath doesn't fire
monster:getType():registerEvent('arena_boss_death')
monster:registerEvent('arena_boss_death')
creature:teleportTo(next_pos)
setCanEnterNextRoom(creature, false)
return true
end
local login = CreatureEvent('arena_login')
login:type('login')
function login.onLogin(player)
setCanEnterNextRoom(player, true)
return true
end
login:register()
boss_death:register()
start_tp:register()