In this event, players will have to capture the opposing team's flag and return it to their base while protecting their own flag. The team with the most captured flags withn a given time wins.
Code:
local EVENT_NPC_ENTRY = 70000 -- Replace this with the entry ID of the NPC you want to use for the event
local ALLIANCE_FLAG_ENTRY = 80000 -- Replace this with the entry ID of the Alliance flag
local HORDE_FLAG_ENTRY = 80001 -- Replace this with the entry ID of the Horde flag
local EVENT_DURATION = 300 -- Duration of the event in seconds
local EVENT_REWARD_ITEM = 90000 -- Replace this with the item ID of the reward
local ALLIANCE_BASE_LOCATION = { x = 0, y = 0, z = 0, map = 0 } -- Replace these coordinates with the Alliance base location
local HORDE_BASE_LOCATION = { x = 0, y = 0, z = 0, map = 0 } -- Replace these coordinates with the Horde base location
local captureTheFlagActive = false
local allianceScore = 0
local hordeScore = 0
local eventTimer = EVENT_DURATION
local function CaptureTheFlagUpdate()
if captureTheFlagActive then
eventTimer = eventTimer - 1
if eventTimer <= 0 then
local winningTeam = "Draw"
if allianceScore > hordeScore then
winningTeam = "Alliance"
elseif hordeScore > allianceScore then
winningTeam = "Horde"
end
SendWorldMessage("The Capture the Flag event has ended! The winning team is: " .. winningTeam)
captureTheFlagActive = false
allianceScore = 0
hordeScore = 0
eventTimer = EVENT_DURATION
end
end
end
local function CaptureTheFlagOnGossipHello(event, player, creature)
if captureTheFlagActive then
player:SendBroadcastMessage("The Capture the Flag event is already in progress!")
else
captureTheFlagActive = true
player:SendBroadcastMessage("The Capture the Flag event has started! Capture the opposing team's flag and return it to your base!")
end
player:GossipComplete()
end
local function CaptureTheFlagOnFlagPickup(event, player, item)
local team = player:GetTeam()
local opposingFlagEntry = team == 0 and HORDE_FLAG_ENTRY or ALLIANCE_FLAG_ENTRY
if item:GetEntry() == opposingFlagEntry then
player:SendBroadcastMessage("You have picked up the opposing team's flag! Return it to your base!")
end
end
local function CaptureTheFlagOnFlagCapture(event, player, item)
local team = player:GetTeam()
local opposingFlagEntry = team == 0 and HORDE_FLAG_ENTRY or ALLIANCE_FLAG_ENTRY
if item:GetEntry() == opposingFlagEntry then
if team == 0 then
allianceScore = allianceScore + 1
else
hordeScore = hordeScore + 1
end
player:RemoveItem(item:GetEntry(), 1)
player:SendBroadcastMessage("You have captured the opposing team's flag! Current score: Alliance " .. allianceScore .. " - " .. hordeScore .. " Horde")
end
end
RegisterCreatureGossipEvent(EVENT_NPC_ENTRY, 1, CaptureTheFlagOnGossipHello)
RegisterPlayerEvent(18, CaptureTheFlagOnFlagPickup)
RegisterPlayerEvent(19, CaptureTheFlagOnFlagCapture)
local function ResetFlags()
local allianceFlag = PerformIngameSpawn(1, ALLIANCE_FLAG_ENTRY, ALLIANCE_BASE_LOCATION.map, 0, ALLIANCE_BASE_LOCATION.x, ALLIANCE_BASE_LOCATION.y, ALLIANCE_BASE_LOCATION.z, 0, true, false)
local hordeFlag = PerformIngameSpawn(1, HORDE_FLAG_ENTRY, HORDE_BASE_LOCATION.map, 0, HORDE_BASE_LOCATION.x, HORDE_BASE_LOCATION.y, HORDE_BASE_LOCATION.z, 0, true, false)
if allianceFlag and hordeFlag then
allianceFlag:SetRespawnDelay(30)
hordeFlag:SetRespawnDelay(30)
end
end
ResetFlags()
local function CaptureTheFlagEnd(eventId, delay, repeats)
captureTheFlagActive = false
allianceScore = 0
hordeScore = 0
eventTimer = EVENT_DURATION
ResetFlags()
end
local function CaptureTheFlagMain(eventId, delay, repeats)
CaptureTheFlagUpdate()
if captureTheFlagActive then
CreateLuaEvent(CaptureTheFlagMain, 1000, 1)
else
CreateLuaEvent(CaptureTheFlagEnd, EVENT_DURATION * 1000, 1)
end
end
CreateLuaEvent(CaptureTheFlagMain, 1000, 1)