[TFS 1.1] Monster Arena

Discussion in 'GlobalEvents, Spells & CreatureEvents' started by Summ, Mar 19, 2015.

  1. Summ

    Summ (\/)(;,,;)(\/) Y not? Staff Member Global Moderator

    Joined:
    Oct 15, 2008
    Messages:
    4,130
    Likes Received:
    1,025
    Best Answers:
    2
    [​IMG] Monster Arena Player vs. Player

    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
    [​IMG]

    Scripts:

    Actions
    actions.xml
    Code (Text):
    1. <action actionid="1500" script="monsterarena.lua"/>
    actions/scripts/monsterarena.lua
    Code (Text):
    1.  
    2. MonsterArena = {
    3.     fromPosition = { Position(1022, 1030, 7), Position(1024, 1030, 7) },
    4.     toPosition = { Position(1020, 1021, 7), Position(1022, 1021, 7) },
    5.     spawnPosition = { Position(1020, 1022, 7), Position(1022, 1020, 7) },
    6.     area = {
    7.         from = Position(1015, 1016, 7),
    8.         to = Position(1027, 1026, 7)
    9.     },
    10.     exitPosition = Position(1022, 1028, 7),
    11.     reward = {itemId = 2160, count = 10},
    12.  
    13.     blockItemId = 3402,
    14.  
    15.     -- Only convincable / summonable monsters
    16.     -- You can create custom monsters which are stronger and convincable
    17.     monsters = {'Troll', 'Rat', 'Tortoise', 'Orc Berserker', 'Minotaur'},
    18.     event = 'MonsterArenaDeath',
    19.  
    20.     players = {}
    21. }
    22.  
    23. function MonsterArena.hasPlayer(player)
    24.     local position = player:getPosition()
    25.     return position.x >= MonsterArena.area.from.x and position.y >= MonsterArena.area.from.y
    26.             and position.x <= MonsterArena.area.to.x and position.y <= MonsterArena.area.to.y
    27.             and position.z == MonsterArena.area.from.z
    28. end
    29.  
    30. function MonsterArena.isOccupied()
    31.     for _, pid in ipairs(MonsterArena.players) do
    32.         local player = Player(pid)
    33.         if player and MonsterArena.hasPlayer(player) then
    34.             return true
    35.         end
    36.     end
    37.     return false
    38. end
    39.  
    40. function MonsterArena.clean()
    41.     for i = 1, #MonsterArena.players do
    42.         MonsterArena.players[i] = nil
    43.     end
    44. end
    45.  
    46. function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    47.     if item.itemid ~= 1945 then
    48.         item:transform(1946)
    49.         return true
    50.     end
    51.  
    52.     if MonsterArena.isOccupied() then
    53.         player:sendCancelMessage('The monster arena is currently occupied.')
    54.         return true
    55.     end
    56.  
    57.     local players = {}
    58.     for _, fromPosition in ipairs(MonsterArena.fromPosition) do
    59.         local creature = Tile(fromPosition):getTopCreature()
    60.         if not creature or not creature:isPlayer() then
    61.             player:sendCancelMessage('You need another player for the monster arena.')
    62.             return true
    63.         end
    64.         table.insert(players, creature)
    65.     end
    66.  
    67.     MonsterArena.clean()
    68.  
    69.     local summons = {}
    70.     for i, player in ipairs(players) do
    71.         player:teleportTo(MonsterArena.toPosition[i])
    72.         MonsterArena.fromPosition[i]:sendMagicEffect(CONST_ME_POFF)
    73.         MonsterArena.toPosition[i]:sendMagicEffect(CONST_ME_TELEPORT)
    74.  
    75.         local monsterName = MonsterArena.monsters[math.random(#MonsterArena.monsters)]
    76.         local monster = Game.createMonster(monsterName, MonsterArena.spawnPosition[i], true)
    77.         monster:setMaster(player)
    78.         monster:registerEvent(MonsterArena.event)
    79.         table.insert(summons, monster)
    80.  
    81.         Game.createItem(MonsterArena.blockItemId, 1, MonsterArena.spawnPosition[i])
    82.  
    83.         player:sendTextMessage(MESSAGE_INFO_DESCR, string.format('A %s is fighting for you this round!', monsterName))
    84.         table.insert(MonsterArena.players, player.uid)
    85.     end
    86.  
    87.     players[1]:setTarget(summons[2])
    88.     players[2]:setTarget(summons[1])
    89.  
    90.     item:transform(1945)
    91.     return true
    92. end
    93.  
    Creaturescript
    creaturescripts.xml
    Code (Text):
    1. <event type="death" name="MonsterArenaDeath" script="monsterarenadeath.lua"/>
    creaturescripts/scripts/monsterarenadeath.lua
    Code (Text):
    1.  
    2. function onDeath(monster, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    3.     local winnerPlayer = killer:getMaster()
    4.     local loserPlayer = monster:getMaster()
    5.  
    6.     local reward = MonsterArena.reward
    7.     if reward then
    8.         winnerPlayer:sendTextMessage(MESSAGE_INFO_DESCR, 'Your monster won the fight and earned a reward for you!')
    9.         winnerPlayer:addItem(reward.itemId, reward.count)
    10.     else
    11.         winnerPlayer:sendTextMessage(MESSAGE_INFO_DESCR, 'Your monster won the fight!')
    12.     end
    13.  
    14.     loserPlayer:sendTextMessage(MESSAGE_INFO_DESCR, 'Your monster lost the fight!')
    15.  
    16.     winnerPlayer:teleportTo(MonsterArena.exitPosition)
    17.     loserPlayer:teleportTo(MonsterArena.exitPosition)
    18.     MonsterArena.exitPosition:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    19.  
    20.     for _, position in ipairs(MonsterArena.spawnPosition) do
    21.         local item = Tile(position):getItemById(MonsterArena.blockItemId)
    22.         if item then
    23.             item:remove()
    24.         end
    25.     end
    26.  
    27.     killer:remove()
    28.     return true
    29. end
    30.  
     
  2. Eldin

    Eldin Eldin Projects Premium User

    Joined:
    Jun 12, 2008
    Messages:
    1,260
    Likes Received:
    503
    Best Answers:
    0
    Looking forward to test this out! :)

    Kind Regards,
    Eldin.
     
  3. StreamSide

    StreamSide Joseluis Gonzalez

    Joined:
    Aug 31, 2007
    Messages:
    2,586
    Likes Received:
    512
    Best Answers:
    2
    can I kiss u? great job again bro
     
  4. abbe

    abbe Premium User Premium User

    Joined:
    Dec 21, 2008
    Messages:
    233
    Likes Received:
    4
    Best Answers:
    0
    "You need another player for the monster Arena", 2 people standing on the tiles, tried setting the tiles to actionid 1500 aswell but it didnt work
     
  5. Hugofasima

    Hugofasima Website: thenosegang.servegame.com

    Joined:
    Jun 24, 2015
    Messages:
    206
    Likes Received:
    23
    Best Answers:
    0
    Perfect!!!!
     
  6. Scrappy Coco

    Scrappy Coco Member

    Joined:
    Dec 27, 2014
    Messages:
    95
    Likes Received:
    12
    Best Answers:
    0
    Good Job Summ tenks for much.
     
  7. Hugofasima

    Hugofasima Website: thenosegang.servegame.com

    Joined:
    Jun 24, 2015
    Messages:
    206
    Likes Received:
    23
    Best Answers:
    0
    Hi! My TFS is 1.1, I did something wrong?

    I'm getting this error on Distro


    Code (Text):
    1. Lua Script Error: [CreatureScript Interface]
    2. data/creaturescripts/scripts/events/monsterarenadeath.lua:onDeath
    3. data/creaturescripts/scripts/events/monsterarenadeath.lua:7: attempt to index lo
    4. cal 'winnerPlayer' (a nil value)
    5. stack traceback:
    6.         [C]: in function '__index'
    7.         data/creaturescripts/scripts/events/monsterarenadeath.lua:7: in function
    8. <data/creaturescripts/scripts/events/monsterarenadeath.lua:1>
    9.  
    The script is:

    Code (Text):
    1. function onDeath(monster, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    2.     local winnerPlayer = killer:getMaster()
    3.     local loserPlayer = monster:getMaster()
    4.  
    5.     local reward = MonsterArena.reward
    6.     if reward then
    7.         winnerPlayer:sendTextMessage(MESSAGE_INFO_DESCR, 'Your monster won the fight and earned a reward for you!')
    8.         winnerPlayer:addItem(reward.itemId, reward.count)
    9.     else
    10.         winnerPlayer:sendTextMessage(MESSAGE_INFO_DESCR, 'Your monster won the fight!')
    11.     end
    12.  
    13.     loserPlayer:sendTextMessage(MESSAGE_INFO_DESCR, 'Your monster lost the fight!')
    14.  
    15.     winnerPlayer:teleportTo(MonsterArena.exitPosition)
    16.     loserPlayer:teleportTo(MonsterArena.exitPosition)
    17.     MonsterArena.exitPosition:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    18.  
    19.     for _, position in ipairs(MonsterArena.spawnPosition) do
    20.         local item = Tile(position):getItemById(MonsterArena.blockItemId)
    21.         if item then
    22.             item:remove()
    23.         end
    24.     end
    25.  
    26.     killer:remove()
    27.     return true
    28. end
    If is needed:
    local deathListEnabled = true
    local maxDeathRecords = 5

    function onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    local playerId = player:getId()
    if nextUseStaminaTime[playerId] ~= nil then
    nextUseStaminaTime[playerId] = nil
    end

    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are dead.")
    if not deathListEnabled then
    return
    end

    local byPlayer = 0
    local killerName
    if killer ~= nil then
    if killer:isPlayer() then
    byPlayer = 1
    else
    local master = killer:getMaster()
    if master and master ~= killer and master:isPlayer() then
    killer = master
    byPlayer = 1
    end
    end
    killerName = killer:getName()
    else
    killerName = "field item"
    end

    local byPlayerMostDamage = 0
    local mostDamageKillerName
    if mostDamageKiller ~= nil then
    if mostDamageKiller:isPlayer() then
    byPlayerMostDamage = 1
    else
    local master = mostDamageKiller:getMaster()
    if master and master ~= mostDamageKiller and master:isPlayer() then
    mostDamageKiller = master
    byPlayerMostDamage = 1
    end
    end
    mostDamageName = mostDamageKiller:getName()
    else
    mostDamageName = "field item"
    end

    local playerGuid = player:getGuid()
    db.query("INSERT INTO `player_deaths` (`player_id`, `time`, `level`, `killed_by`, `is_player`, `mostdamage_by`, `mostdamage_is_player`, `unjustified`, `mostdamage_unjustified`) VALUES (" .. playerGuid .. ", " .. os.time() .. ", " .. player:getLevel() .. ", " .. db.escapeString(killerName) .. ", " .. byPlayer .. ", " .. db.escapeString(mostDamageName) .. ", " .. byPlayerMostDamage .. ", " .. (unjustified and 1 or 0) .. ", " .. (mostDamageUnjustified and 1 or 0) .. ")")
    local resultId = db.storeQuery("SELECT `player_id` FROM `player_deaths` WHERE `player_id` = " .. playerGuid)

    local deathRecords = 0
    local tmpResultId = resultId
    while tmpResultId ~= false do
    tmpResultId = result.next(resultId)
    deathRecords = deathRecords + 1
    end

    if resultId ~= false then
    result.free(resultId)
    end

    local limit = deathRecords - maxDeathRecords
    if limit > 0 then
    db.asyncQuery("DELETE FROM `player_deaths` WHERE `player_id` = " .. playerGuid .. " ORDER BY `time` LIMIT " .. limit)
    end

    if byPlayer == 1 then
    local targetGuild = player:getGuild()
    targetGuild = targetGuild and targetGuild:getId() or 0
    if targetGuild ~= 0 then
    local killerGuild = killer:getGuild()
    killerGuild = killerGuild and killerGuild:getId() or 0
    if killerGuild ~= 0 and targetGuild ~= killerGuild and isInWar(playerId, killer:getId()) then
    local warId = false
    resultId = db.storeQuery("SELECT `id` FROM `guild_wars` WHERE `status` = 1 AND ((`guild1` = " .. killerGuild .. " AND `guild2` = " .. targetGuild .. ") OR (`guild1` = " .. targetGuild .. " AND `guild2` = " .. killerGuild .. "))")
    if resultId ~= false then
    warId = result.getDataInt(resultId, "id")
    result.free(resultId)
    end

    if warId ~= false then
    db.asyncQuery("INSERT INTO `guildwar_kills` (`killer`, `target`, `killerguild`, `targetguild`, `time`, `warid`) VALUES (" .. db.escapeString(killerName) .. ", " .. db.escapeString(player:getName()) .. ", " .. killerGuild .. ", " .. targetGuild .. ", " .. os.time() .. ", " .. warId .. ")")
    end
    end
    end
    end
    end

    -------------------------------------- @edit


    SOLVED!

    https://otland.net/threads/error-attempt-to-index-local-a-nil-value.234683/#post-2263964
     
    Last edited: Jul 20, 2015
  8. Ahead

    Ahead Member

    Joined:
    Dec 27, 2013
    Messages:
    167
    Likes Received:
    2
    Best Answers:
    0
    Which would i have to add to the code if i want people to get removed certain item to take part in the event?

    Thanks!. Awesome script.
     
  9. Frikx

    Frikx Maroxy Scripts (XenoBot)

    Joined:
    Mar 10, 2013
    Messages:
    97
    Likes Received:
    12
    Best Answers:
    0
    Why do you "killer:remove()"? : (((
     
  10. silveralol

    silveralol Well-Known Member

    Joined:
    Mar 16, 2010
    Messages:
    1,297
    Likes Received:
    151
    Best Answers:
    3
    the killers is the summon of the winner player, if not remove it, if he fight again will have two summons
     
  11. Frikx

    Frikx Maroxy Scripts (XenoBot)

    Joined:
    Mar 10, 2013
    Messages:
    97
    Likes Received:
    12
    Best Answers:
    0
    You are right.
     
  12. Oualid

    Oualid Active Member

    Joined:
    Aug 24, 2014
    Messages:
    312
    Likes Received:
    42
    Best Answers:
    0
    Is it possible to make it impossible to stop attacking the other summon? Because people can block the spawn if they attack their opponents monster and then stop attacking it because then their summon will stop attacking either. Or maybe add something like kick after "X" amount of time if there still is no winner kick all players and send a message.
     
    Last edited: Nov 3, 2016
  13. Oualid

    Oualid Active Member

    Joined:
    Aug 24, 2014
    Messages:
    312
    Likes Received:
    42
    Best Answers:
    0
  14. Oualid

    Oualid Active Member

    Joined:
    Aug 24, 2014
    Messages:
    312
    Likes Received:
    42
    Best Answers:
    0
  15. Oualid

    Oualid Active Member

    Joined:
    Aug 24, 2014
    Messages:
    312
    Likes Received:
    42
    Best Answers:
    0
    Couple months later...... Bump
     
  16. Oualid

    Oualid Active Member

    Joined:
    Aug 24, 2014
    Messages:
    312
    Likes Received:
    42
    Best Answers:
    0
  17. Oualid

    Oualid Active Member

    Joined:
    Aug 24, 2014
    Messages:
    312
    Likes Received:
    42
    Best Answers:
    0
  18. Oualid

    Oualid Active Member

    Joined:
    Aug 24, 2014
    Messages:
    312
    Likes Received:
    42
    Best Answers:
    0

Share This Page

Loading...