-- Globalevent used to teleport players out of arena when server shuts down --
local globaleventPvPArena = GlobalEvent("PvP_Arena_Global")
function globaleventPvPArena.onShutdown()
for _, player in pairs(Game.getPlayers()) do
if player and player:isPvPArenaPlayer() then
local town = config[player:getTown():getId()]
if town then
player:setPvPArenaPlayer(false) -- added to remove player from event
player:teleportTo(town.exitPos)
player:setOutfit(PVP_ARENA_PLAYERS_OUTFIT[player:getName()])-- give player outfit back after removing from event
end
end
end
return true
end
globaleventPvPArena:register()
-- Prepare death. Handles players dying in arena. --
local creatureeventPvPArena = CreatureEvent("PvP_Arena_PrepareDeath")
function creatureeventPvPArena.onPrepareDeath(creature, killer)
if not creature:isPlayer() then return true end
if not creature:isPvPArenaPlayer() then return true end
local town = config[creature:getTown():getId()]
if not town then return true end
creature:teleportTo(town.exitPos)
creature:addHealth(creature:getMaxHealth())
creature:addMana(creature:getMaxMana())
print("PVP")
creature:setPvPArenaPlayer(false)
creature:setOutfit(PVP_ARENA_PLAYERS_OUTFIT[creature:getName()])-- give player outfit back
return false
end
creatureeventPvPArena:register()
-- Moveevent used to teleport players in and out of the arena --
local movementPvPArena = MoveEvent()
movementPvPArena:type("stepin")
-- change player looktype and save outfit before enter arena
local function setEventOutfit(player, typeA, typeB, colorA, colorB)
if player == nil or typeA == nil or typeB == nil or colorA == nil or colorB == nil then
return print("local function setEventOutfit with empty argument")
end
local looktype = typeA
local color = colorA
if player:getTown():getId() == 2 then
looktype = typeB
color = colorB
end
PVP_ARENA_PLAYERS_OUTFIT[player:getName()] = player:getOutfit() -- save players outfit
player:setOutfit({lookType = looktype, lookLegs = color, lookHead = color, lookFeet = color, lookBody = color})
end
function movementPvPArena.onStepIn(player, item, position, fromPosition)
if not player then return true end
local town = config[player:getTown():getId()]
if not town then
player:sendCancelMessage("You do not have a town set. Report to GM.")
player:teleportTo(fromPosition, true)
return true
end
if not player:isPvPArenaPlayer() then
if position ~= town.tileEnterPos then
player:sendCancelMessage("You do not have the correct town to enter here.")
player:teleportTo(fromPosition, true)
return true
end
--- Outfit
setEventOutfit(player, 60, 59, 94, 82) -- change players from town 1 to 60 and from town 2 to 59, and set color 94 and 82 for each one
-- teleport and add player to event
player:teleportTo(town.enterPos)
town.enterPos:sendMagicEffect(CONST_ME_TELEPORT)
player:setPvPArenaPlayer(true)
else
if position ~= town.tileExitPos then
player:sendCancelMessage("You do not have the correct town to exit here.")
player:teleportTo(fromPosition, true)
return true
end
player:teleportTo(town.exitPos)
town.exitPos:sendMagicEffect(CONST_ME_TELEPORT)
player:setPvPArenaPlayer(false)
player:setOutfit(PVP_ARENA_PLAYERS_OUTFIT[player:getName()])-- give player outfit back
end
return true
end