• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Add one function to custom arena script

BugaS

Donżuan
Joined
Mar 12, 2009
Messages
1,219
Reaction score
9
Location
NYC
Hey guys!

I've got a arena system from this forum, and I want one modification. Here are scripts.

Area_Death (creaturescripts):

LUA:
local config = {
   reward_position = {x = 472, y = 12, z = 7}, -- Teleport location when Arena is Cleared.
   global_storage = 696969, -- any free storage
   top_left_corner = {x = 459, y = 15, z = 7}, -- top left corner of arena
   bottom_right_corner = {x = 470, y = 18, z = 7}, -- bottom right corner of arena
}
local monsters = { -- All monsters in arena (including joke monster)
   [1] = "Fighter",
   [2] = "Monster1",
   [3] = "Monster2",
   [4] = "Monster3"
}
local monster_config_wave_one = { -- wave 1
   [1] = {position = {x = 468, y = 16, z = 7}, name = "Monster1"}
}
local monster_config_wave_two = { -- wave 2
   [1] = {position = {x = 468, y = 16, z = 7}, name = "Monster2"}
}
local monster_config_wave_three = { -- wave 3
   [1] = {position = {x = 468, y = 16, z = 7}, name = "Monster3"}
}
function onKill(cid, target, damage, flags)
   -- check if target is player
   if isPlayer(target) then
     return true
   end
   -- check if target is on list of monsters in arena
   local name = getCreatureName(target):lower()
   count = 0
   for i = 1, #monsters do
     if name == monsters[i]:lower() then
       count = count + 1
     end
   end
   if count == 0 then -- if target is not on list
     return true
   end
   -- check if target is in area and add to global storage if it is
   for t = config.top_left_corner.x, config.bottom_right_corner.x do
     for f = config.top_left_corner.y, config.bottom_right_corner.y do
       pos = {x = t, y = f, z = 7}
       pid = getTopCreature(pos).uid
       if pid == target then
         setGlobalStorageValue(global_storage, getGlobalStorageValue(global_storage) + 1)
       end
     end
   end
   -- Start checks for waves of arena
   -- Wave 1
   if getGlobalStorageValue(global_storage) == 1 then
     for i = 1, #monster_config_wave_one do
       doCreateMonster(monster_config_wave_one[i].name, monster_config_wave_one[i].position)
     end
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wave 1.")
   end
   -- Wave 2
   if getGlobalStorageValue(global_storage) == 2 then
     for i = 1, #monster_config_wave_two do
       doCreateMonster(monster_config_wave_two[i].name, monster_config_wave_two[i].position)
     end
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wave 2.")
   end
   -- Wave 3
   if getGlobalStorageValue(global_storage) == 3 then
     for i = 1, #monster_config_wave_three do
       doCreateMonster(monster_config_wave_three[i].name, monster_config_wave_three[i].position)
     end
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Wave 3. Final Wave.")
   end
   -- When final wave ends
   -- Teleport player
   if getGlobalStorageValue(global_storage) == 4 then
     doTeleportThing(cid, config.reward_position)
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Congratulations! Go collect your reward.")
     setGlobalStorageValue(global_storage, 0)
   end
   return true
end

and action:

LUA:
---------------------------------- Start Config -------------------------------
local config = {
   arena_position = {x = 462, y = 17, z = 7}, -- Player Arena Position
   failed_position = {x = 473, y = 10, z = 7}, -- Player took too long position
   lever_reset_time = 10, -- in minutes (how long until another player can kick them out)
   global_storage = 696969, -- any free storage
   top_left_corner = {x = 459, y = 15, z = 7}, -- top left corner of arena
   bottom_right_corner = {x = 470, y = 18, z = 7}, -- bottom right corner of arena
   joke_monster = "Fighter" -- They will kill this monster to start the waves
}
----------------------------------- End Config --------------------------------
local function reset(p)
   doTransformItem(getTileItemById(p, 1946).uid, 1945)
end
local function teleport(cid)
   doTeleportThing(cid, config.arena_position)
   doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "---------------------------------------")
   doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Kill the training mate to start Tournament.")
   doCreateMonster(config.joke_monster, config.arena_position)
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
   -- check if lever is currently used
   if item.itemid == 1946 then
     return doPlayerSendTextMessage(cid, 22, "Wait for switch to reset. It resets automatically every ".. config.lever_reset_time .." minutes.")
   end
   -- check for players/monsters in arena, and kick them out/remove them
   for t = config.top_left_corner.x, config.bottom_right_corner.x do
     for f = config.top_left_corner.y, config.bottom_right_corner.y do
       pos = {x = t, y = f, z = 7}
       pid = getTopCreature(pos).uid
       if isPlayer(pid) then
         doTeleportThing(pid, config.failed_position)
         doPlayerSendTextMessage(pid, MESSAGE_STATUS_CONSOLE_BLUE, "Another player started the arena. You have been removed. Better luck next time!")
       end
       if isMonster(pid) then
         doRemoveCreature(pid)
       end
     end
   end
   -- tell player what to do
   doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Lever resets automatically every ".. config.lever_reset_time .." minutes.")
   doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Once the lever resets another player can start the arena.")
   doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "If your still inside when another player starts, you will be removed from the arena and unable to continue.")
   -- reset global storage
   setGlobalStorageValue(global_storage, 0)
   -- teleport player to arena, send start message, create start/joke monster
   addEvent(teleport, 5000, cid)
   -- transform lever, and add reset
   doTransformItem(item.uid, item.itemid + 1)
   addEvent(reset, ((config.lever_reset_time * 60 * 1000) + 5000), toPosition)
   return true
end

Everything works great, but I need a modification. I've got in map editor PVP tiles and now i want to make that after player dead on arena, he will be teleported to another place, not to the temple.
Can you help me?

Thanks!
 
Register an onPrepareDeath event on the player that is getting teleported inside then if it ever gets triggered check if the player is inside the arena if he is you teleport him to where you wanna and add his HP back.
 
Register an onPrepareDeath event on the player that is getting teleported inside then if it ever gets triggered check if the player is inside the arena if he is you teleport him to where you wanna and add his HP back.
Where to add it? Can you add this to these scripts? I'm noob in LUA
 
Register an onPrepareDeath event on the player that is getting teleported inside then if it ever gets triggered check if the player is inside the arena if he is you teleport him to where you wanna and add his HP back.
Would this actually work?
I thought that you were 100% dead when someone get's prepare death activated.
Hrrm. :/

Well try this then.
(Note: Do not use pvp-tiles in the arena. If you do, the script will not activate.)

creaturescript.xml
XML:
<event type="preparedeath" name="arena_death" event="script" value="arena_death.lua"/>
login.lua [somewhere near bottom with other registered events]
LUA:
registerCreatureEvent(cid, "arena_death")
arena_death.lua
LUA:
local config = {
   -- arena positions
   top_left_position = {x = 1000, y = 1000, z = 7},
   bot_right_position = {x = 1000, y = 1000, z = 7},
   -- if die in arena, teleport  here.
   teleport_position = {x = 1000, y = 1000, z = 7}
}

function onPrepareDeath(cid, deathList)
   local player_position = getCreaturePosition(cid)
   print("x = " .. player_position.x .. ", y = " .. player_position.y .. ", z = " .. player_position.z .. "")
   if player_position.x >= config.top_left_position.x and player_position.x <= config.bot_right_position.x then
       if player_position.x >= config.top_left_position.x and player_position.x <= config.bot_right_position.x then
           if player_position.z >= config.top_left_position.z and player_position.x <= config.bot_right_position.x then
               doTeleportThing(cid, config.teleport_position)
               doCreatureAddHealth(cid, getCreatureMaxHealth(cid), true)
               doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You failed in the arena. Better luck next time!")
               return false
           end
       end
   end
   return true
end




In the event that the above code doesn't work, and if you don't mind the player actually dying inside the arena..
Replace the above code with the code below.
(Note: Do not use pvp-tiles in the arena.)

creaturescript.xml
XML:
<event type="preparedeath" name="arena_death" event="script" value="arena_death.lua"/>
<event type="login" name="arena_death_login" event="script" value="arena_death_login.lua"/>
login.lua [somewhere near bottom with other registered events]
LUA:
registerCreatureEvent(cid, "arena_death")
registerCreatureEvent(cid, "arena_death_login")
arena_death.lua
LUA:
local config = {
   -- arena positions
   top_left_position = {x = 1000, y = 1000, z = 7},
   bot_right_position = {x = 1000, y = 1000, z = 7},
   player_storage = 11111 -- use any free storage
}

function onPrepareDeath(cid, deathList)
   local player_position = getCreaturePosition(cid)
   print("x = " .. player_position.x .. ", y = " .. player_position.y .. ", z = " .. player_position.z .. "")
   if player_position.x >= config.top_left_position.x and player_position.x <= config.bot_right_position.x then
       if player_position.x >= config.top_left_position.x and player_position.x <= config.bot_right_position.x then
           if player_position.z >= config.top_left_position.z and player_position.x <= config.bot_right_position.x then
               setPlayerStorageValue(cid, config.player_storage, 1)
           end
       end
   end
   return true
end
arena_death_login.lua
LUA:
local config = {
   teleport_position = {x = 1000, y = 1000, z = 7},
   player_storage = 11111 -- use any free storage (but same storage as other script)
}

function onLogin(cid)
   if getPlayerStorageValue(cid, config.player_storage) == 1 then
       setPlayerStorageValue(cid, config.player_storage, 0)
       doTeleportThing(cid, config.teleport_position)
       doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You died in the arena. Better luck next time!")
   end
   return true
end

--Edit

Just realized there is a third option, using onStatsChange.. But only if you really want/need it.
I'd personally suggest using the above solutions.
 
Last edited by a moderator:
arena_death.lua
Would this actually work?
I thought that you were 100% dead when someone get's prepare death activated.
Hrrm. :/

Well try this then.
(Note: Do not use pvp-tiles in the arena. If you do, the script will not activate.)

creaturescript.xml
XML:
<event type="preparedeath" name="arena_death" event="script" value="arena_death.lua"/>
login.lua [somewhere near bottom with other registered events]
LUA:
registerCreatureEvent(cid, "arena_death")
arena_death.lua
LUA:
local config = {
   -- arena positions
   top_left_position = {x = 1000, y = 1000, z = 7},
   bot_right_position = {x = 1000, y = 1000, z = 7},
   -- if die in arena, teleport  here.
   teleport_position = {x = 1000, y = 1000, z = 7}
}

function onPrepareDeath(cid, deathList)
   local player_position = getCreaturePosition(cid)
   print("x = " .. player_position.x .. ", y = " .. player_position.y .. ", z = " .. player_position.z .. "")
   if player_position.x >= config.top_left_position.x and player_position.x <= config.bot_right_position.x then
       if player_position.x >= config.top_left_position.x and player_position.x <= config.bot_right_position.x then
           if player_position.z >= config.top_left_position.z and player_position.x <= config.bot_right_position.x then
               doTeleportThing(cid, config.teleport_position)
               doCreatureAddHealth(cid, getCreatureMaxHealth(cid), true)
               doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You failed in the arena. Better luck next time!")
               return false
           end
       end
   end
   return true
end




In the event that the above code doesn't work, and if you don't mind the player actually dying inside the arena..
Replace the above code with the code below.
(Note: Do not use pvp-tiles in the arena.)

creaturescript.xml
XML:
<event type="preparedeath" name="arena_death" event="script" value="arena_death.lua"/>
<event type="login" name="arena_death_login" event="script" value="arena_death_login.lua"/>
login.lua [somewhere near bottom with other registered events]
LUA:
registerCreatureEvent(cid, "arena_death")
registerCreatureEvent(cid, "arena_death_login")
arena_death.lua
LUA:
local config = {
   -- arena positions
   top_left_position = {x = 1000, y = 1000, z = 7},
   bot_right_position = {x = 1000, y = 1000, z = 7},
   player_storage = 11111 -- use any free storage
}

function onPrepareDeath(cid, deathList)
   local player_position = getCreaturePosition(cid)
   print("x = " .. player_position.x .. ", y = " .. player_position.y .. ", z = " .. player_position.z .. "")
   if player_position.x >= config.top_left_position.x and player_position.x <= config.bot_right_position.x then
       if player_position.x >= config.top_left_position.x and player_position.x <= config.bot_right_position.x then
           if player_position.z >= config.top_left_position.z and player_position.x <= config.bot_right_position.x then
               setPlayerStorageValue(cid, config.player_storage, 1)
           end
       end
   end
   return true
end
arena_death_login.lua
LUA:
local config = {
   teleport_position = {x = 1000, y = 1000, z = 7},
   player_storage = 11111 -- use any free storage (but same storage as other script)
}

function onLogin(cid)
   if getPlayerStorageValue(cid, config.player_storage) == 1 then
       setPlayerStorageValue(cid, config.player_storage, 0)
       doTeleportThing(cid, config.teleport_position)
       doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You died in the arena. Better luck next time!")
   end
   return true
end

--Edit

Just realized there is a third option, using onStatsChange.. But only if you really want/need it.
I'd personally suggest using the above solutions.
Tell me one thing. I must edit the scripts from original (in the first post) and just select all, delete and paste your in this reply or make new files too? Cause i've got arena_death.lua from original, and you gave the same name.
 
Tell me one thing. I must edit the scripts from original (in the first post) and just select all, delete and paste your in this reply or make new files too? Cause i've got arena_death.lua from original, and you gave the same name.
Sorry. The scripts I posted are new files/functions.
Please rename to whatever you want. like.. arena_prepare_death.lua
(of course you could put them all into one file.. but if you don't know how, just do separate files.)
 
Sorry. The scripts I posted are new files/functions.
Please rename to whatever you want. like.. arena_prepare_death.lua
(of course you could put them all into one file.. but if you don't know how, just do separate files.)
Well you forgot to remove the "print" calls.
 
I never tested the scripts. :/
I just added it in case there was any issues.
I tried the second script. I died on the area and return to the temple, no to the position i set.
#edit

and it's impossible to die. I'm walking with 0 hp when i die on normal monsters outside of arena
 
Back
Top