CreatureEvent [TFS 1.1] Classic PVP Arena

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,530
Best answers
1
Reaction score
1,433
Location
Poland
If you playd on 7.6 you probably know how famous pvp arena from yur evo or sinteria worked.
This place allows you to test your pvp skills without risk of death.

Installation(lever script coming soon so I included stuff from action already)


creaturescripts.xml
Code:
	<event type="preparedeath" name="pvparena" script="pvparena.lua"/>
	<event type="login" name="pvparena_r" script="pvparena.lua"/>
pvparena.lua
Code:
local arena = {
	frompos = {x = 1041, y = 985, z = 9},
	topos = {x = 1052, y = 991, z = 9},
	exitpos = {x = 1038, y = 988, z = 8}
}

function onPrepareDeath(player, lastHitKiller, mostDamageKiller)
	if player:isPlayer() then
		local ppos = player:getPosition()
		if isInRange(ppos, arena.frompos, arena.topos) then
			local maxhp = player:getMaxHealth()
			player:addHealth(maxhp)
			addEvent(doCreatureAddHealth, 100, player:getId(), maxhp)
			player:sendTextMessage(MESSAGE_STATUS_WARNING,"[Arena]: You lost the duel.")
		end
		if isInRange(ppos, arena.frompos, arena.topos) then
			player:teleportTo(arena.exitpos)
			return true
		end
	end
	return true
end

function onLogin(player)
	player:registerEvent("pvparena")
	return true
end
 
OP
zbizu

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,530
Best answers
1
Reaction score
1,433
Location
Poland
action(not optimised, just copied from my old datapack)
Code:
<action uniqueid="6040" script="arenapvp.lua"/>
Code:
-- CONFIG BEGINS HERE --
local arena = {
  frompos = {x = 1041, y = 985, z = 9},
  topos = {x = 1052, y = 991, z = 9},
  exitpos = {x = 1038, y = 988, z = 8}
}
local checkpvparena = true -- checks if someone is blocking the arena
local duel_limit = 15 * 60 -- in seconds
local player1pos = {x = 1040, y = 987, z = 8}
local leverpos = {x = 1040, y = 988, z = 8}
local player2pos = {x = 1040, y = 989, z = 8}
local nplayer1pos = {x = 1042, y = 988, z = 9}
local nplayer2pos = {x = 1051, y = 988, z = 9}
-- CONFIG ENDS HERE --


function lever_back(uid)
   doTransformItem(uid,1945)
   return true
end

function kick_r()
if getCreaturesInQuestArea(TYPE_PLAYER, arena.frompos, arena.topos, GET_COUNT) > 1 then
   for a = arena.frompos.x, arena.topos.x do
   for b = arena.frompos.y, arena.topos.y do
     pos = {x=a,y=b,z=11,stackpos = 255}
     if(isPlayer(getTopCreature(pos).uid)) then
       doPlayerSendTextMessage(getTopCreature(pos).uid,MESSAGE_INFO_DESCR,"Time up. Round drawn.")
       doTeleportThing(getTopCreature(pos).uid,arena.exitpos)
     end
   end
   end
end
   return true
end

local TYPE_PLAYER = 1
local TYPE_MONSTER = 2
local TYPE_NPC = 3
local TYPE_ALL = 4
local GET_COUNT = 1
local GET_UID = 2

function getCreaturesInQuestArea(type, fromPos, toPos, get, countSummon)
   local types =
   {
     [TYPE_PLAYER] = isPlayer,
     [TYPE_MONSTER] = isMonster,
     [TYPE_NPC] = isNpc,
     [TYPE_ALL] = isCreature
   }
   local tmp = {}
   local t = types[type]
   if not t then
     return print("[!] --> [Warning - Function::getCreaturesInQuestArea] Unknown type " .. (type or "(nil value)"))
   end
   local thing
   local pos
   for x = fromPos.x, toPos.x do
     for y = fromPos.y, toPos.y do
       for z = fromPos.z, toPos.z do
         pos = {x = x, y = y, z = z}
         thing = getTopCreature(pos)
         if t(thing.uid) then
           table.insert(tmp, thing.uid)
           if not countSummon and isSummon(thing.uid) then
             for i = 1, #tmp do
               if tmp[i] == thing.uid then
                 table.remove(tmp, i)
                 break
               end
             end
           end
         end
       end
     end
   end
   return (get == GET_COUNT and #tmp or get == GET_UID and tmp or print("[Warning - Function::getCreaturesInQuestArea] Unknown type to get " .. (get or "(nil value)")))
end

function onUse(player, item, frompos, item2, topos)
local cid = player:getId()
   if item.itemid == 1945 then
     if isPlayer(getTopCreature(player1pos).uid) == true and isPlayer(getTopCreature(player2pos).uid) == true then
       if checkpvparena then
         if getCreaturesInQuestArea(TYPE_PLAYER, arena.frompos, arena.topos, GET_COUNT) > 0 then
           if getCreaturesInQuestArea(TYPE_PLAYER, arena.frompos, arena.topos, GET_COUNT) == 1 then
             for c = arena.frompos.x, arena.topos.x do
             for d = arena.frompos.y, arena.topos.y do
               pos = {x=c,y=d,z=11, stackpos = 255}
               if(isPlayer(getTopCreature(pos).uid)) then
                 doPlayerSendTextMessage(getTopCreature(pos).uid,MESSAGE_INFO_DESCR,"You have been kicked from the arena.")
                 doTeleportThing(getTopCreature(pos).uid,arena.exitpos)
               end
             end
             end
           else
           arena_counter = getGlobalStorageValue(24510) - os.time()
           if arena_counter < 0 then
             for c = arena.frompos.x, arena.topos.x do
             for d = arena.frompos.y, arena.topos.y do
               pos = {x=c,y=d,z=11, stackpos = 255}
               if(isPlayer(getTopCreature(pos).uid)) then
                 doPlayerSendTextMessage(getTopCreature(pos).uid,MESSAGE_INFO_DESCR,"You have been kicked from the arena.")
                 doTeleportThing(getTopCreature(pos).uid,arena.exitpos)
               end
             end
             end
           else
           doCreatureSay(cid, "There is still active duel.\n" .. showTimeLeft(arena_counter, true) .. " left.\nPlease wait for your turn.", TALKTYPE_ORANGE_1)
           pvpaback = addEvent(lever_back, 5000, item.uid)
           return false
           end
           end
         end
       end
       -- let the match begin
       doSendMagicEffect(player1pos,CONST_ME_POFF)
       doSendMagicEffect(player2pos,CONST_ME_POFF)
       doPlayerSendTextMessage(getTopCreature(player1pos).uid,MESSAGE_STATUS_WARNING,"Fight!")
       doPlayerSendTextMessage(getTopCreature(player2pos).uid,MESSAGE_STATUS_WARNING,"Fight!")
       doTeleportThing(getTopCreature(player1pos).uid,nplayer1pos)
       doTeleportThing(getTopCreature(player2pos).uid,nplayer2pos)
       doSendMagicEffect(nplayer1pos,CONST_ME_TELEPORT)
       doSendMagicEffect(nplayer2pos,CONST_ME_TELEPORT)
       doTransformItem(getTileItemById(leverpos, 1945).uid,item.itemid+1)
       setGlobalStorageValue(24510,os.time() + duel_limit)
       pvpaback = addEvent(lever_back, 5000, item.uid)
       if arena_kick_r then
       stopEvent(arena_kick_r)
       end
       arena_kick_r = addEvent(kick_r, duel_limit * 1000)
     else
       doCreatureSay(cid, "You need two players to enter the arena.", TALKTYPE_ORANGE_1)
       pvpaback = addEvent(lever_back, 5000, item.uid)
       return false
     end
   else
     -- if timer or checking is offline player can push the lever manually
     if pvpaback then
     doPlayerSendDefaultCancel(cid, RETURNVALUE_CANNOTUSETHISOBJECT)
     else
     doTransformItem(getTileItemById(leverpos, 1946).uid,1945)
     end
   end
return true
end
 
Last edited:

zygus0001

Member
Joined
Feb 26, 2015
Messages
210
Best answers
0
Reaction score
8
action(not optimised, just copied from my old datapack)
Code:
<action uniqueid="6040" script="arenapvp.lua"/>
Code:
-- CONFIG BEGINS HERE --
local arena = {
  frompos = {x = 1041, y = 985, z = 9},
  topos = {x = 1052, y = 991, z = 9},
  exitpos = {x = 1038, y = 988, z = 8}
}
local checkpvparena = true -- checks if someone is blocking the arena
local duel_limit = 15 * 60 -- in seconds
local player1pos = {x = 1040, y = 987, z = 8}
local leverpos = {x = 1040, y = 988, z = 8}
local player2pos = {x = 1040, y = 989, z = 8}
local nplayer1pos = {x = 1042, y = 988, z = 9}
local nplayer2pos = {x = 1051, y = 988, z = 9}
-- CONFIG ENDS HERE --


function lever_back(uid)
   doTransformItem(uid,1945)
   return true
end

function kick_r()
if getCreaturesInQuestArea(TYPE_PLAYER, arena.frompos, arena.topos, GET_COUNT) > 1 then
   for a = arena.frompos.x, arena.topos.x do
   for b = arena.frompos.y, arena.topos.y do
     pos = {x=a,y=b,z=11,stackpos = 255}
     if(isPlayer(getTopCreature(pos).uid)) then
       doPlayerSendTextMessage(getTopCreature(pos).uid,MESSAGE_INFO_DESCR,"Time up. Round drawn.")
       doTeleportThing(getTopCreature(pos).uid,arena.exitpos)
     end
   end
   end
end
   return true
end

local TYPE_PLAYER = 1
local TYPE_MONSTER = 2
local TYPE_NPC = 3
local TYPE_ALL = 4
local GET_COUNT = 1
local GET_UID = 2

function getCreaturesInQuestArea(type, fromPos, toPos, get, countSummon)
   local types =
   {
     [TYPE_PLAYER] = isPlayer,
     [TYPE_MONSTER] = isMonster,
     [TYPE_NPC] = isNpc,
     [TYPE_ALL] = isCreature
   }
   local tmp = {}
   local t = types[type]
   if not t then
     return print("[!] --> [Warning - Function::getCreaturesInQuestArea] Unknown type " .. (type or "(nil value)"))
   end
   local thing
   local pos
   for x = fromPos.x, toPos.x do
     for y = fromPos.y, toPos.y do
       for z = fromPos.z, toPos.z do
         pos = {x = x, y = y, z = z}
         thing = getTopCreature(pos)
         if t(thing.uid) then
           table.insert(tmp, thing.uid)
           if not countSummon and isSummon(thing.uid) then
             for i = 1, #tmp do
               if tmp[i] == thing.uid then
                 table.remove(tmp, i)
                 break
               end
             end
           end
         end
       end
     end
   end
   return (get == GET_COUNT and #tmp or get == GET_UID and tmp or print("[Warning - Function::getCreaturesInQuestArea] Unknown type to get " .. (get or "(nil value)")))
end

function onUse(player, item, frompos, item2, topos)
local cid = player:getId()
   if item.itemid == 1945 then
     if isPlayer(getTopCreature(player1pos).uid) == true and isPlayer(getTopCreature(player2pos).uid) == true then
       if checkpvparena then
         if getCreaturesInQuestArea(TYPE_PLAYER, arena.frompos, arena.topos, GET_COUNT) > 0 then
           if getCreaturesInQuestArea(TYPE_PLAYER, arena.frompos, arena.topos, GET_COUNT) == 1 then
             for c = arena.frompos.x, arena.topos.x do
             for d = arena.frompos.y, arena.topos.y do
               pos = {x=c,y=d,z=11, stackpos = 255}
               if(isPlayer(getTopCreature(pos).uid)) then
                 doPlayerSendTextMessage(getTopCreature(pos).uid,MESSAGE_INFO_DESCR,"You have been kicked from the arena.")
                 doTeleportThing(getTopCreature(pos).uid,arena.exitpos)
               end
             end
             end
           else
           arena_counter = getGlobalStorageValue(24510) - os.time()
           if arena_counter < 0 then
             for c = arena.frompos.x, arena.topos.x do
             for d = arena.frompos.y, arena.topos.y do
               pos = {x=c,y=d,z=11, stackpos = 255}
               if(isPlayer(getTopCreature(pos).uid)) then
                 doPlayerSendTextMessage(getTopCreature(pos).uid,MESSAGE_INFO_DESCR,"You have been kicked from the arena.")
                 doTeleportThing(getTopCreature(pos).uid,arena.exitpos)
               end
             end
             end
           else
           doCreatureSay(cid, "There is still active duel.\n" .. showTimeLeft(arena_counter, true) .. " left.\nPlease wait for your turn.", TALKTYPE_ORANGE_1)
           pvpaback = addEvent(lever_back, 5000, item.uid)
           return false
           end
           end
         end
       end
       -- let the match begin
       doSendMagicEffect(player1pos,CONST_ME_POFF)
       doSendMagicEffect(player2pos,CONST_ME_POFF)
       doPlayerSendTextMessage(getTopCreature(player1pos).uid,MESSAGE_STATUS_WARNING,"Fight!")
       doPlayerSendTextMessage(getTopCreature(player2pos).uid,MESSAGE_STATUS_WARNING,"Fight!")
       doTeleportThing(getTopCreature(player1pos).uid,nplayer1pos)
       doTeleportThing(getTopCreature(player2pos).uid,nplayer2pos)
       doSendMagicEffect(nplayer1pos,CONST_ME_TELEPORT)
       doSendMagicEffect(nplayer2pos,CONST_ME_TELEPORT)
       doTransformItem(getTileItemById(leverpos, 1945).uid,item.itemid+1)
       setGlobalStorageValue(24510,os.time() + duel_limit)
       pvpaback = addEvent(lever_back, 5000, item.uid)
       if arena_kick_r then
       stopEvent(arena_kick_r)
       end
       arena_kick_r = addEvent(kick_r, duel_limit * 1000)
     else
       doCreatureSay(cid, "You need two players to enter the arena.", TALKTYPE_ORANGE_1)
       pvpaback = addEvent(lever_back, 5000, item.uid)
       return false
     end
   else
     -- if timer or checking is offline player can push the lever manually
     if pvpaback then
     doPlayerSendDefaultCancel(cid, RETURNVALUE_CANNOTUSETHISOBJECT)
     else
     doTransformItem(getTileItemById(leverpos, 1946).uid,1945)
     end
   end
return true
end
optimize please this
 

Blaggo

New Member
Joined
Oct 23, 2014
Messages
10
Best answers
0
Reaction score
1
In my TFS 1.1 server, when the duel timer is up, players are not kicked from the arena and I get this message

Code:
 [!] --> [Warning - Function::getCreaturesInQuestArea] Unknown type (nil value)

Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/actions/scripts/arenapvp.lua:23: attempt to compare number with nil stack traceback:
[C]: in function '__lt'
data/actions/scripts/arenapvp.lua:23: in function <data/actions/scripts/arenapvp.lua:22>
I copied your scripts exactly and created an arena exactly like your image and only changed the config {x, y, z} coordinates.
 

EwR

New Member
Joined
Aug 28, 2013
Messages
94
Best answers
0
Reaction score
3
When you gona release it ? :D
Hope son ;)
 

Hugofasima

Website: thenosegang.servegame.com
Joined
Jun 24, 2015
Messages
206
Best answers
0
Reaction score
22
Here the player die and the corpse are teleported to exit positon. What I did wrong?
 

Awesomedudei

Revolutionot.com
Joined
Jan 20, 2010
Messages
313
Best answers
0
Reaction score
61
Location
Sweden


I fixed this by adding


Compat.lua
Code:
function isInRange(position, fromPosition, toPosition)
     return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.z >= fromPosition.z and position.x <= toPosition.x and position.y <= toPosition.y and position.z <= toPosition.z)
end

But yes as mentioned above my post you'll get teleported out of temple and die.
 
Last edited:

raganius

raganius.com
Joined
May 18, 2016
Messages
27
Best answers
0
Reaction score
8
Hey there,

Thank you for this great script and tutorial. I have followed it here and it is working fine, but I've had some problems, and that brings some questions:

Anyway, first of all, I've got TFS 1.0 here.

1 - My first question is that after doing everything as OP indicated, I was not able to login with any character, getting the following error:
Arena 02 has logged in.

Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/pvparenaArida.lua: onLogin
data/creaturescripts/scripts/pvparenaArida.lua:25: attempt to index local 'player' (a number value)
stack traceback:
[C]: in function '__index'
data/creaturescripts/scripts/pvparenaArida.lua:25: in function <data/creaturescripts/scripts/pvparenaArida.lua:24>
Arena 02 has logged out.

These were the scripts while I had that problem:

<?xml version="1.0" encoding="UTF-8"?>
<creaturescripts>
<event type="login" name="PlayerLogin" script="login.lua"/>
<event type="login" name="FirstItems" script="firstitems.lua"/>
<event type="death" name="PlayerDeath" script="playerdeath.lua"/>
<event type="extendedopcode" name="ExtendedOpcode" script="extendedopcode.lua"/>
<event type="preparedeath" name="pvparenaArida" script="pvparenaArida.lua"/>
<event type="login" name="pvparenaArida_r" script="pvparenaArida.lua"/>

</creaturescripts>
local arena = {

frompos = {x = 666, y = 1692, z = 8},

topos = {x = 677, y = 1698, z = 8},

exitpos = {x = 660, y = 1692, z = 7}

}


function onPrepareDeath(player, lastHitKiller, mostDamageKiller)

if player:isPlayer() then

local ppos = player:getPosition()

if isInRange(ppos, arena.frompos, arena.topos) then

local maxhp = player:getMaxHealth()

player:addHealth(maxhp)

addEvent(doCreatureAddHealth, 100, player:getId(), maxhp)

player:sendTextMessage(MESSAGE_STATUS_WARNING,"[Arena]: You lost the duel.")

end

if isInRange(ppos, arena.frompos, arena.topos) then

player:teleportTo(arena.exitpos)

return true

end

end

return true

end


function onLogin(player)

player:registerEvent("pvparenaArida")

return true

end

  • With that above mentioned error, as a solution, I have decided to simply eliminate
function onLogin(player)
player:registerEvent("pvparenaArida")
return true
end
that now is
-- function onLogin(player)
-- player:registerEvent("pvparenaArida")
-- return true
-- end

and also I have done this

<?xml version="1.0" encoding="UTF-8"?>
<creaturescripts>
<event type="login" name="PlayerLogin" script="login.lua"/>
<event type="login" name="FirstItems" script="firstitems.lua"/>
<event type="death" name="PlayerDeath" script="playerdeath.lua"/>
<event type="extendedopcode" name="ExtendedOpcode" script="extendedopcode.lua"/>
<!-- <event type="preparedeath" name="pvparenaArida" script="pvparenaArida.lua"/>
<event type="login" name="pvparenaArida_r" script="pvparenaArida.lua"/>
-->
</creaturescripts>

  • So, my first doubt is: Will it be a problem? I have tested the arena, and it seems to work fine, with the exception of the following next question:

2 - My second question is that after doing the above modifications, I decided to test "leaving the player on the arena", to check if it would be expelled from the arena after a long time inside it (as is desired), but the error I get is:
Arena 02 has logged in.
Arena 01 has logged in.
^[[B[!] --> [Warning - Function::getCreaturesInQuestArea] Unknown type (nil value)

Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/actions/scripts/arenapvpArida.lua:23: attempt to compare number with nil
stack traceback:
[C]: in function '__lt'
data/actions/scripts/arenapvpArida.lua:23: in function <data/actions/scripts/arenapvpArida.lua:22>
I have tried to find a solution, but as I am such a newbie, I was not able at all.

So, TLDR, I'd like to know
  1. if the modifications I have done in topic "1" might represent any potential problem for the server/arena functioning;
  2. How can I solve the error shown in topic "2", when limiting the time a character spends inside the arena.

Thank you so much in advance for clearing my doubts.

^^
 
Last edited:
OP
zbizu

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,530
Best answers
1
Reaction score
1,433
Location
Poland
There were some changes related to metatables and the script probably receives wrong data type at some point.
I need a reference so please paste here lines 23 and 25 of your arenapvpArida.lua
 

raganius

raganius.com
Joined
May 18, 2016
Messages
27
Best answers
0
Reaction score
8
Thank you, @zbizu

Here is line 23:
if getCreaturesInQuestArea(TYPE_PLAYER, arena.frompos, arena.topos, GET_COUNT) > 1 then
and here is line 25:
for b = arena.frompos.y, arena.topos.y do
And, in case it is necessary, here is the extract from that function area from anevaPVPArida.lua:
-- CONFIG ENDS HERE --

function lever_back(uid)
doTransformItem(uid,1945)
return true
end

function kick_r()
if getCreaturesInQuestArea(TYPE_PLAYER, arena.frompos, arena.topos, GET_COUNT) > 1 then
for a = arena.frompos.x, arena.topos.x do
for b = arena.frompos.y, arena.topos.y do
pos = {x=a,y=b,z=11,stackpos = 255}
if(isPlayer(getTopCreature(pos).uid)) then
doPlayerSendTextMessage(getTopCreature(pos).uid,MESSAGE_INFO_DESCR,"Time up. Round drawn.")
doTeleportThing(getTopCreature(pos).uid,arena.exitpos)
end
end
end
end
return true
end
local TYPE_PLAYER = 1
If you need I can post the whole script, but it is basically exactly the one in OP. It's quite a big script and it messes up when I copy from the linux terminal into this browser window :)
 
OP
zbizu

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,530
Best answers
1
Reaction score
1,433
Location
Poland
There is no "player" in your line 25 so I can't reproduce this error.

Regarding line 23:
try replacing your function to this:
Code:
function getCreaturesInQuestArea(type, fromPos, toPos, get, countSummon)
   local types =
   {
     [TYPE_PLAYER] = Creature:isPlayer,
     [TYPE_MONSTER] = Creature:isMonster,
     [TYPE_NPC] = Creature:isNpc,
     [TYPE_ALL] = Creature:isCreature
   }
   local tmp = {}
   local t = types[type]
   if not t then
     return print("[!] --> [Warning - Function::getCreaturesInQuestArea] Unknown type " .. (type or "(nil value)"))
   end
   local thing
   local pos
   for x = fromPos.x, toPos.x do
     for y = fromPos.y, toPos.y do
       for z = fromPos.z, toPos.z do
         pos = Position(x, y, z)
         thing = pos:getTopCreature()
         if t(thing) then
           table.insert(tmp, thing:getId())
           if not countSummon and thing:isSummon() then
             for i = 1, #tmp do
               if tmp[i] == thing:getId() then
                 table.remove(tmp, i)
                 break
               end
             end
           end
         end
       end
     end
   end
   return (get == GET_COUNT and #tmp or get == GET_UID and tmp or print("[Warning - Function::getCreaturesInQuestArea] Unknown type to get " .. (get or "(nil value)")))
end
oh and try moving this to the top:
Code:
local TYPE_PLAYER = 1
local TYPE_MONSTER = 2
local TYPE_NPC = 3
local TYPE_ALL = 4
local GET_COUNT = 1
local GET_UID = 2
 

raganius

raganius.com
Joined
May 18, 2016
Messages
27
Best answers
0
Reaction score
8
Thank you again, @zbizu , for taking the time to help me.

I have tested the modifications you have suggested, and my "arenapvp.lua" was updated to:

-- CONFIG BEGINS HERE --

local arena = {
frompos = {x = 666, y = 1692, z = 8},
topos = {x = 677, y = 1698, z = 8},
exitpos = {x = 660, y = 1692, z = 7}
}
local checkpvparena = true -- checks if someone is blocking the arena
local duel_limit = 15 * 60 -- in seconds
local player1pos = {x = 675, y = 1694, z = 7}
local leverpos = {x = 675, y = 1695, z = 7}
local player2pos = {x = 675, y = 1696, z = 7}
local nplayer1pos = {x = 679, y = 1695, z = 8}
local nplayer2pos = {x = 686, y = 1695, z = 8}

-- CONFIG ENDS HERE --

local TYPE_PLAYER = 1
local TYPE_MONSTER = 2
local TYPE_NPC = 3
local TYPE_ALL = 4
local GET_COUNT = 1
local GET_UID = 2

function lever_back(uid)
doTransformItem(uid,1945)
return true
end

function kick_r()
if getCreaturesInQuestArea(TYPE_PLAYER, arena.frompos, arena.topos, GET_COUNT) > 1 then
for a = arena.frompos.x, arena.topos.x do
for b = arena.frompos.y, arena.topos.y do
pos = {x=a,y=b,z=11,stackpos = 255}
if(isPlayer(getTopCreature(pos).uid)) then
doPlayerSendTextMessage(getTopCreature(pos).uid,MESSAGE_INFO_DESCR,"Time up. Round drawn.")
doTeleportThing(getTopCreature(pos).uid,arena.exitpos)
end
end
end
end
return true
end

function getCreaturesInQuestArea(type, fromPos, toPos, get, countSummon)
local types =
{
[TYPE_PLAYER] = Creature:isPlayer,
[TYPE_MONSTER] = Creature:isMonster,
[TYPE_NPC] = Creature:isNpc,
[TYPE_ALL] = Creature:isCreature
}
local tmp = {}
local t = types[type]
if not t then
return print("[!] --> [Warning - Function::getCreaturesInQuestArea] Unknown type " .. (type or "(nil value)"))
end
local thing
local pos
for x = fromPos.x, toPos.x do
for y = fromPos.y, toPos.y do
for z = fromPos.z, toPos.z do
pos = Position(x, y, z)
thing = pos:getTopCreature()
if t(thing) then
table.insert(tmp, thing:getId())
if not countSummon and thing:isSummon() then
for i = 1, #tmp do
if tmp == thing:getId() then
table.remove(tmp, i)
break
end
end
end
end
end
end
end
return (get == GET_COUNT and #tmp or get == GET_UID and tmp or print("[Warning - Function::getCreaturesInQuestArea] Unknown type to get " .. (get or "(nil value)")))
end

function onUse(player, item, frompos, item2, topos)
local cid = player:getId()
if item.itemid == 1945 then
if isPlayer(getTopCreature(player1pos).uid) == true and isPlayer(getTopCreature(player2pos).uid) == true then
if checkpvparena then
if getCreaturesInQuestArea(TYPE_PLAYER, arena.frompos, arena.topos, GET_COUNT) > 0 then
if getCreaturesInQuestArea(TYPE_PLAYER, arena.frompos, arena.topos, GET_COUNT) == 1 then
for c = arena.frompos.x, arena.topos.x do
for d = arena.frompos.y, arena.topos.y do
pos = {x=c,y=d,z=11, stackpos = 255}
if(isPlayer(getTopCreature(pos).uid)) then
doPlayerSendTextMessage(getTopCreature(pos).uid,MESSAGE_INFO_DESCR,"You have been kicked from the arena.")
doTeleportThing(getTopCreature(pos).uid,arena.exitpos)
end
end
end
else
arena_counter = getGlobalStorageValue(24510) - os.time()
if arena_counter < 0 then
for c = arena.frompos.x, arena.topos.x do
for d = arena.frompos.y, arena.topos.y do
pos = {x=c,y=d,z=11, stackpos = 255}
if(isPlayer(getTopCreature(pos).uid)) then
doPlayerSendTextMessage(getTopCreature(pos).uid,MESSAGE_INFO_DESCR,"You have been kicked from the arena.")
doTeleportThing(getTopCreature(pos).uid,arena.exitpos)
end
end
end
else
doCreatureSay(cid, "There is still active duel.\n" .. showTimeLeft(arena_counter, true) .. " left.\nPlease wait for your turn.", TALKTYPE_ORANGE_1)
pvpaback = addEvent(lever_back, 5000, item.uid)
return false
end
end
end
end
-- let the match begin
doSendMagicEffect(player1pos,CONST_ME_POFF)
doSendMagicEffect(player2pos,CONST_ME_POFF)
doPlayerSendTextMessage(getTopCreature(player1pos).uid,MESSAGE_STATUS_WARNING,"Fight!")
doPlayerSendTextMessage(getTopCreature(player2pos).uid,MESSAGE_STATUS_WARNING,"Fight!")
doTeleportThing(getTopCreature(player1pos).uid,nplayer1pos)
doTeleportThing(getTopCreature(player2pos).uid,nplayer2pos)
doSendMagicEffect(nplayer1pos,CONST_ME_TELEPORT)
doSendMagicEffect(nplayer2pos,CONST_ME_TELEPORT)
doTransformItem(getTileItemById(leverpos, 1945).uid,item.itemid+1)
setGlobalStorageValue(24510,os.time() + duel_limit)
pvpaback = addEvent(lever_back, 5000, item.uid)
if arena_kick_r then
stopEvent(arena_kick_r)
end
arena_kick_r = addEvent(kick_r, duel_limit * 1000)
else
doCreatureSay(cid, "You need two players to enter the arena.", TALKTYPE_ORANGE_1)
pvpaback = addEvent(lever_back, 5000, item.uid)
return false
end
else
-- if timer or checking is offline player can push the lever manually
if pvpaback then
doPlayerSendDefaultCancel(cid, RETURNVALUE_CANNOTUSETHISOBJECT)
else
doTransformItem(getTileItemById(leverpos, 1946).uid,1945)
end
end
return true
end

But, it didn't work, because it gave me the following error on loading the server:

>> Loading script systems
[Warning - Event::checkScript] Can not load script: scripts/arenapvp.lua
data/actions/scripts/arenapvp.lua:49: function arguments expected near ','
>> Loading monsters
So, I have tried to fix it by substituting

{
[TYPE_PLAYER] = Creature:isPlayer,
[TYPE_MONSTER] = Creature:isMonster,
[TYPE_NPC] = Creature:isNpc,
[TYPE_ALL] = Creature:isCreature
}
to the former version of

{
[TYPE_PLAYER] = isPlayer,
[TYPE_MONSTER] = isMonster,
[TYPE_NPC] = isNpc,
[TYPE_ALL] = isCreature
}
Then, it loaded everything, apparently without error messages, but the arena is actually not working, because when one tries to use it (the moment the player clicks the lever) I get the following error:

Lua Script Error: [Action Interface]
data/actions/scripts/arenapvp.lua: onUse
data/actions/scripts/arenapvp.lua:89: attempt to index local 'player' (a number value)
stack traceback:
[C]: in function '__index'
data/actions/scripts/arenapvp.lua:89: in function <data/actions/scripts/arenapvp.lua:88>
I have checked, and line 89 of "arenapvp.lua" is:

local cid = player:getId()
I have tried simply commenting it out, but then I get other errors :/

Am I doing anything wrong? Or maybe could you please look further into ths issue?

Thank you again, and sorry for the trouble ^^

BTW, I've still kept

-- function onLogin(player)
-- player:registerEvent("pvparena")
-- return true
-- end
and

<!-- <event type="preparedeath" name="pvparena" script="pvparena.lua"/>
<event type="login" name="pvparena_r" script="pvparena.lua"/>
-->
As the issue # 1, as mentioned in first post above, was still present.
 
Last edited:
Top