Code:
local intFlagDespawn_A = 0
local intFlagDespawn_H = 0
local A_SCORECOUNT = 0
local H_SCORECOUNT = 0
function H_Flag_OnUse(Unit, Event, player) -- Tells the check npc the following; If the flag was dropped, It stops the npc from returning the flag to the base, Tells the checknpc the flag is active, Sets the new Horde Flag carrier. Buffs the Flag carrier, Despawns the Goobject flag
H_FC = player
Unit:FullCastSpellOnTarget(HORDEWSGSPELL, H_FC)
Unit:RemoveFromWorld()
H_FC_ACTIVE = 1
H_FC_DROPPED = 0
end
function A_Flag_OnUse(Unit, Event, player)- Tells the check npc the following; If the flag was dropped, It stops the npc from returning the flag to the base, Tells the checknpc the flag is active, Sets the new Alliance Flag carrier. Buffs the Flag carrier, Despawns the Goobject flag
A_FC = player
Unit:FullCastSpellOnPlayer(WSGSPELL, A_FC) -- May need to do a little extra for this.
Unit:RemoveFromWorld()
A_FC_ACTIVE = 1
A_FC_DROPPED = 0
end
function AreaCheck_OnLoad(Unit, Event) -- Check npc
Unit:RegisterEvent("CheckDead_A", 500, 0)
end
function CheckDead_A(Unit, Event) -- Checks for various events; First and foremost, if the FC is in world(Incase they logged out/dcd or porter), If the flag is at its base, If the flag is active, it checks if the player has died Until the player caps it, or actually dies. Also checks if the flag is dropped, to start a 6second count down.
if (A_FC:IsInWorld() == false) then -- Not sure if this will work. Might have to check for MapID/distance (Incase someone grabbed the flag and logged out or ported)
Unit:SpawnGameobject(A_BASELOCATION)
A_FLAG_ATBASE = 1
elseif (A_FC_ACTIVE == 1) then
if (A_FC:IsDead() == true) then
local x = A_FC:GetX()
local y = A_FC:GetY()
local z = A_FC:GetZ()
Unit:SpawnGameobject(x,y,z,0)
A_FC_DROPPED = 1
end
else
if (A_FLAG_ATBASE == 1) then
A_FC_ACTIVE = 0
elseif (A_FC_DROPPED == 1) then
intFlagDespawn_A = intFlagDespawn_A + 1
if (intFlagDespawn_A == 12) then
A_FLAG:RemoveFromWorld()
Unit:SpawnGameobject(A_BASELOCATION)
intFlagDespawn = 0
A_FC_ACTIVE = 0
A_FLAG_ATBASE = 1
end
end
end
if (H_FC:IsInWorld() == false) then
Unit:SpawnGameobject(BASELOCATION)
H_FLAG_ATBASE = 1
elseif (H_FC_ACTIVE == 1) then
if (H_FC:IsDead() == true) then
local x=H_FC:GetX()
local y=H_FC:GetY()
local z=H_FC:GetZ()
Unit:SpawnGameobject(x,y,z,0)
A_FC_DROPPED = 1
end
else
if (H_FLAG_ATBASE == 1) then
A_FC_ACTIVE = 0
elseif (H_FC_DROPPED == 1) then
intFlagDespawn_H = intFlagDespawn_H + 1
if (intFlagDespawn_H == 12) then
H_FLAG:RemoveFromWorld()
Unit:SpawnGameobject(H_BASELOCATION)
H_FC_ACTIVE = 0
H_FLAG_ATBASE = 1
end
end
end
end
function FlagCaptureA_OnLoad(Unit, Event)
FLAGCAP_A = Unit
FLAGCAP_A:RegisterEvent("CheckForFC_A", 2000, 0) -- FLagcapture area npc's
end
function FlagCaptureH_OnLoad(Unit, Event)
FLAGCAP_H = Unit
FLAGCAP_H:RegisterEvent("CheckForFC_H", 2000, 0) -- ^^
end
function CheckForFC_H(Unit, Event) -- Checks to see The player is in range of a flag cap, If they are it will reset both flags, give the Horde a point. After 3 points, the horde win, you can give them all a prize and send a broadcast message to the players about who won ect ect
local i
local v
if (H_FC_ACTIVE == 1) then
if (Unit:GetDistance(H_FC) <= 25) then
H_SCORECOUNT = H_SCORECOUNT + 1
H_FC:RemoveAura(A_FLAGAURA)
H_FC_ACTIVE = 0
Unit:SpawnGameObject(H_BASELOCATION)
if (A_FC_ACTIVE = 1) then
H_FC:RemoveAura(A_WSGSPELL)
REFEREE:SpawnGameobject(ALLYBASE)
A_FC_ACTIVE = 0
end
if (H_SCORECOUNT == 3) then
local InRangePlayers = REFEREE:GetInRangePlayers()
for i, v in pairs(InRangePlayers) do
local race=v:GetPlayerRace()
if race==1 or race==3 or race==4 or race==7 or race==11 then
v:SendBroadcastMessage("|cFF32CD32 You have been defeated")
v:SendAreaTriggerMessage("|cFF32CD32 The Horde Win!")
else
v:SendBroadcastMessage("|cFFFF0000 You are victorious!")
v:SendAreaTriggerMessage("|cFFFF0000 The Horde Win!")
-- This could also be a time to have something like v:AddItem(item, quantity)
end
end
end
end
end
end
function CheckForFC_A(Unit, Event)-- Checks to see The player is in range of a flag cap, If they are it will reset both flags, give the Alliance a point. After 3 points, the horde win, you can give them all a prize and send a broadcast message to the players about who won ect ect
local i
local v
if (A_FC_ACTIVE == 1) then
if (Unit:GetDistance(A_FC) <= 25) then
A_SCORECOUNT = A_SCORECOUNT + 1
A_FC:RemoveAura(FLAGAURA)
A_FC_ACTIVE = 0
Unit:SpawnGameObject(A_BASELOCATION)
if (H_FC_ACTIVE = 1) then
H_FC:RemoveAura(HORDEWSGSPELL)
REFEREE:SpawnGameobject(HORDEBASE)
H_FC_ACTIVE = 0
end
if (A_SCORECOUNT == 3) then
local InRangePlayers = REFEREE:GetInRangePlayers()
for i, v in pairs(InRangePlayers) do
local race=v:GetPlayerRace()
if race==1 or race==3 or race==4 or race==7 or race==11 then
v:SendBroadcastMessage("|cFF32CD32 You are victorious!")
v:SendAreaTriggerMessage("|cFF32CD32 The Alliance Win!")
-- This could also be a time to have something like v:AddItem(item, quantity)
else
v:SendBroadcastMessage("|cFFFF0000 You have been defeated")
v:SendAreaTriggerMessage("|cFFFF0000 The Alliance Win!")
end
end
end
end
end
end
RegisterGameObjectEvent(GoID, 4, "A_Flag_OnUse") -- The flag itself.
RegisterUnitEvent(NPCID, 18, "AreaCheck_OnLoad") -- Checks for generall flag events (Dropping, Picked up)
RegisterUnitEvent(NPCID, 18, "FlagCaptureA_OnLoad") -- \_____Invisible Flag Cap Area NPC's (To detect if the flag carrier is within capping range only)
RegisterUnitEvent(NPCID, 18, "FlagCaptureH_OnLoad") -- /
Anyway i've probably forgot a few things in that script. But hopefully it will be enough to point you in the right direction.