function onKill(cid, target, flags, damage, war) if not isMonster(target) or getCreatureMaster(target) == cid then return true end if #getMonstersInRange(positions[1][1], positions[1][2]) == 1 then local name, value = getCreatureName(target), math.max(1, getCreatureStorage(cid, storage)) * 2 if value == 2 ^ rounds then local _rewards = rewards[name:lower()].final if _rewards then local reward = _rewards[math.random(#_rewards)] doPlayerAddItem(cid, reward[1], reward[2] or 1) local name = getItemInfo(reward[1]).name doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, '[Challenge Room] You have been awarded with ' .. getArticle(name) .. string.char(32) .. name .. ' for the battle.') end doTeleportThing(cid, positions[2]) doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, '[Challenge Room] Congratulations, you have completed all of the rounds of the Challenge Room!') doCreatureSetStorage(cid, storage, nil) unregisterCreatureEvent(cid, 'challenge_kill') unregisterCreatureEvent(cid, 'challenge_death') else local _rewards = rewards[name:lower()].round if _rewards then local reward = _rewards[math.random(#_rewards)] doPlayerAddItem(cid, reward[1], reward[2]) doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, '[Challenge Room] You have been awarded with ' .. reward[2] .. 'x ' .. getItemInfo(reward[1]).name .. ' for current round.') end local spawn = getArea(positions[4], 3, 3) for i = 1, value do if delay > 0 then addEvent(doCreateMonster, delay, name, spawn[math.random(#spawn)]) else doCreateMonster(name, spawn[math.random(#spawn)]) end end if delay > 0 then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, '[Challenge Room] Congratulations! Next round starts in ' .. delay / 1000 .. ' seconds with ' .. value .. ' monsters.') else doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, '[Challenge Room] Congratulations! Next round started with ' .. value .. ' monsters.') end doCreatureSetStorage(cid, storage, value) end if refill.hitpoints then doCreatureAddHealth(cid, getCreatureMaxHealth(cid)) end if refill.mana then doCreatureAddMana(cid, getCreatureMaxMana(cid)) end end return true end function onPrepareDeath(cid, deathList) for _, v in pairs(getMonstersInRange(positions[1][1], positions[1][2])) do doRemoveCreature(v) end doTeleportThing(cid, positions[3]) doCreatureAddHealth(cid, getCreatureMaxHealth(cid), CONST_ME_MAGIC_BLUE, COLOR_GREEN, true) doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, '[Challenge Room] Defeat! You\'ve lost the battle against monsters.') doCreatureSetStorage(cid, storage, nil) unregisterCreatureEvent(cid, 'challenge_kill') unregisterCreatureEvent(cid, 'challenge_death') return false end