Description:
You need 2 people for this minigame. You stand on the tiles and pull the lever.
Inside the arena each player will get a random summon, which will then attack the enemy's monster. The player whose summon kills the other monster first wins and gets rewarded.
Map:
Mediafire: http://www.mediafire.com/download/qnnqj1rmilmrd5a/monsterarena.otbm
Scripts:
Actions
actions.xml
Code:
<action actionid="1500" script="monsterarena.lua"/>
actions/scripts/monsterarena.lua
Code:
MonsterArena = {
fromPosition = { Position(1022, 1030, 7), Position(1024, 1030, 7) },
toPosition = { Position(1020, 1021, 7), Position(1022, 1021, 7) },
spawnPosition = { Position(1020, 1022, 7), Position(1022, 1020, 7) },
area = {
from = Position(1015, 1016, 7),
to = Position(1027, 1026, 7)
},
exitPosition = Position(1022, 1028, 7),
reward = {itemId = 2160, count = 10},
blockItemId = 3402,
-- Only convincable / summonable monsters
-- You can create custom monsters which are stronger and convincable
monsters = {'Troll', 'Rat', 'Tortoise', 'Orc Berserker', 'Minotaur'},
event = 'MonsterArenaDeath',
players = {}
}
function MonsterArena.hasPlayer(player)
local position = player:getPosition()
return position.x >= MonsterArena.area.from.x and position.y >= MonsterArena.area.from.y
and position.x <= MonsterArena.area.to.x and position.y <= MonsterArena.area.to.y
and position.z == MonsterArena.area.from.z
end
function MonsterArena.isOccupied()
for _, pid in ipairs(MonsterArena.players) do
local player = Player(pid)
if player and MonsterArena.hasPlayer(player) then
return true
end
end
return false
end
function MonsterArena.clean()
for i = 1, #MonsterArena.players do
MonsterArena.players[i] = nil
end
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item.itemid ~= 1945 then
item:transform(1946)
return true
end
if MonsterArena.isOccupied() then
player:sendCancelMessage('The monster arena is currently occupied.')
return true
end
local players = {}
for _, fromPosition in ipairs(MonsterArena.fromPosition) do
local creature = Tile(fromPosition):getTopCreature()
if not creature or not creature:isPlayer() then
player:sendCancelMessage('You need another player for the monster arena.')
return true
end
table.insert(players, creature)
end
MonsterArena.clean()
local summons = {}
for i, player in ipairs(players) do
player:teleportTo(MonsterArena.toPosition[i])
MonsterArena.fromPosition[i]:sendMagicEffect(CONST_ME_POFF)
MonsterArena.toPosition[i]:sendMagicEffect(CONST_ME_TELEPORT)
local monsterName = MonsterArena.monsters[math.random(#MonsterArena.monsters)]
local monster = Game.createMonster(monsterName, MonsterArena.spawnPosition[i], true)
monster:setMaster(player)
monster:registerEvent(MonsterArena.event)
table.insert(summons, monster)
Game.createItem(MonsterArena.blockItemId, 1, MonsterArena.spawnPosition[i])
player:sendTextMessage(MESSAGE_INFO_DESCR, string.format('A %s is fighting for you this round!', monsterName))
table.insert(MonsterArena.players, player.uid)
end
players[1]:setTarget(summons[2])
players[2]:setTarget(summons[1])
item:transform(1945)
return true
end
Creaturescript
creaturescripts.xml
Code:
<event type="death" name="MonsterArenaDeath" script="monsterarenadeath.lua"/>
creaturescripts/scripts/monsterarenadeath.lua
Code:
function onDeath(monster, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
local winnerPlayer = killer:getMaster()
local loserPlayer = monster:getMaster()
local reward = MonsterArena.reward
if reward then
winnerPlayer:sendTextMessage(MESSAGE_INFO_DESCR, 'Your monster won the fight and earned a reward for you!')
winnerPlayer:addItem(reward.itemId, reward.count)
else
winnerPlayer:sendTextMessage(MESSAGE_INFO_DESCR, 'Your monster won the fight!')
end
loserPlayer:sendTextMessage(MESSAGE_INFO_DESCR, 'Your monster lost the fight!')
winnerPlayer:teleportTo(MonsterArena.exitPosition)
loserPlayer:teleportTo(MonsterArena.exitPosition)
MonsterArena.exitPosition:sendMagicEffect(CONST_ME_MAGIC_BLUE)
for _, position in ipairs(MonsterArena.spawnPosition) do
local item = Tile(position):getItemById(MonsterArena.blockItemId)
if item then
item:remove()
end
end
killer:remove()
return true
end