This event will teleport all participating players to a designated arena. The players will then fight each other, and the last player alive wins the event. Once the event is over, all participating players will be teleported back to their original locations.
Code:
local EVENT_NPC_ENTRY = 658
local ARENA_MAP_ID = 530
local ARENA_LOCATION = {x = -2485, y = 6562, z = 16}
local EVENT_DURATION = 300 -- 5 minutes in seconds
local JOIN_DURATION = 60 -- 1 minute in seconds
local eventActive = false
local players = {}
local function LastManStandingOnGossipHello(event, player, object)
if not eventActive then
player:GossipMenuAddItem(0, "Join the Last Man Standing event", 0, 1)
player:GossipSendMenu(1, object)
else
player:SendBroadcastMessage("The event is currently in progress. Please wait for the next round.")
end
end
local function LastManStandingOnGossipSelect(event, player, object, sender, intid, code, menuid)
if intid == 1 then
table.insert(players, {player = player, originalLocation = player:GetLocation()})
player:Teleport(ARENA_MAP_ID, ARENA_LOCATION.x, ARENA_LOCATION.y, ARENA_LOCATION.z, player:GetO())
player:SendBroadcastMessage("You have joined the Last Man Standing event!")
player:GossipComplete()
end
end
RegisterCreatureGossipEvent(EVENT_NPC_ENTRY, 1, LastManStandingOnGossipHello)
RegisterCreatureGossipEvent(EVENT_NPC_ENTRY, 2, LastManStandingOnGossipSelect)
local function LastManStandingEnd()
local lastPlayer = nil
for _, data in ipairs(players) do
local player = data.player
if player:IsAlive() and player:GetMapId() == ARENA_MAP_ID then
lastPlayer = player
player:Teleport(unpack(data.originalLocation))
end
end
if lastPlayer then
lastPlayer:SendBroadcastMessage("Congratulations! You are the Last Man Standing!")
end
players = {}
eventActive = false
end
local function LastManStandingBegin()
eventActive = true
CreateLuaEvent(LastManStandingEnd, EVENT_DURATION * 1000, 1)
end
local function LastManStandingSchedule(eventId, delay, repeats)
if not eventActive then
LastManStandingBegin()
end
CreateLuaEvent(LastManStandingSchedule, JOIN_DURATION * 1000, 1)
end
CreateLuaEvent(LastManStandingSchedule, JOIN_DURATION * 1000, 1)