PDA

View Full Version : [LUA] Team Battles



Avidgamer
19-08-10, 09:03 PM
Okay, so I was going through my LUA folder when I noticed I had a lot of LUA's I had forgotten about. This hasn't been posted here, so I'll go ahead and post.

Team Battles - Pastebin (http://www.pastebin.org/616078)




-- Created by Grandelf

local PREFIX = "#ra"

local MSG_ON_QUEUE = "join"
local MSG_ON_LEAVE_QUEUE = "leave"
local MSG_CURRENTLY_IN = "in"

R_A = {
QUEUE_TBL = {},
BATTLE_TBL = {},
CLEAN_TBL = {},
KILL_TBL = {},
PHASE_TBL = {[1] = 1}
}

local Q_TBL = R_A.QUEUE_TBL
local B_TBL = R_A.BATTLE_TBL
local C_TBL = R_A.CLEAN_TBL
local K_TBL = R_A.KILL_TBL
local P_TBL = R_A.PHASE_TBL

function RA_MSG_HOOK(event, plr, msg)
if (string.lower(msg):find(PREFIX.." ") == 1) then
local s_msg = msg:gsub(PREFIX.." ", "")
if (string.lower(s_msg) == MSG_ON_QUEUE) then
if (not plr:IsInGroup() and not plr:GetInstanceID()) then
if (plr:GetPhase() > 1) then return 0; end
if (not R_A.IsPlayerQueued(plr)) then
table.insert(Q_TBL, plr)
plr:SendBroadcastMessage("You have been added to the queue.")
else
plr:SendBroadcastMessage("You are already in queue.")
end
else
plr:SendBroadcastMessage("You can't join when you are in a group or instance.")
end
end
if (string.lower(s_msg) == MSG_ON_LEAVE_QUEUE) then
if (R_A.IsPlayerQueued(plr)) then
table.remove(Q_TBL, R_A.IsPlayerQueued(plr))
plr:SendBroadcastMessage("You have been removed from the queue.")
else
plr:SendBroadcastMessage("You aren't in queue.")
end
end
if (string.lower(s_msg) == MSG_CURRENTLY_IN) then
if (#Q_TBL > 0) then
local A_PLR = 0
local H_PLR = 0
for _, v in pairs(Q_TBL) do
if (v:GetTeam() == 0) then
A_PLR = A_PLR + 1
else
H_PLR = H_PLR + 1
end
end
plr:SendBroadcastMessage("Currently in queue:\nAlliance: "..A_PLR.."\nHorde: "..H_PLR)
else
plr:SendBroadcastMessage("There are no players in queue at this time.")
end
end
return 0;
end
end

function R_A.IsPlayerQueued(plr)
for k, v in pairs(Q_TBL) do
if (tostring(v) == tostring(plr)) then
return k;
end
end
return false;
end

----------------------------------------
function TIMED_EVENTS()
CleanQueue();
CleanBattle();
end

function TIMED_REGISTER()
REGISTER_TEAMS();
end
----------------------------------------
function CleanQueue()
CLEAN_OFFLINE(Q_TBL);
CLEAN_INSTANCE(Q_TBL);
CLEAN_GROUP(Q_TBL);
if (#C_TBL > 0) then
CLEAN_TBL(Q_TBL);
end
end
function CleanBattle()
CLEAN_B_OFFLINE(B_TBL);
CLEAN_MOUNTED(B_TBL);
PLR_CHEAT(B_TBL);
TEAM_RAMPAGE();
if (#C_TBL > 0) then
CLEAN_TBL(B_TBL);
end
end
function CLEAN_OFFLINE(TBL)
for _, v in pairs(TBL) do
if (not v:IsInWorld()) then
table.insert(C_TBL, v)
end
end
end
function CLEAN_B_OFFLINE(TBL)
for _, _v in pairs(GetActiveRounds()) do
for k, v in pairs(TBL[_v]) do
if (not v:IsInWorld()) then
TBL[_v][k] = nil;
collectgarbage()
end
end
end
end
function CLEAN_INSTANCE(TBL)
for _, v in pairs(TBL) do
if (v:IsInWorld() and v:GetInstanceID()) then
table.insert(C_TBL, v)
end
end
end
function CLEAN_GROUP(TBL)
for _, v in pairs(TBL) do
if (v:IsInWorld() and v:IsInGroup()) then
table.insert(C_TBL, v)
end
end
end
function CLEAN_MOUNTED(TBL)
for _, _v in pairs(GetActiveRounds()) do
for _, v in pairs(TBL[_v]) do
if (v:IsMounted()) then
v:Dismount()
end
end
end
end
function CLEAN_TBL(TBL)
for _, v in pairs(C_TBL) do
for k, _v in pairs(TBL) do
if (v == _v) then
TBL[k] = nil;
end
if (_v:IsInWorld()) then
_v:SendBroadcastMessage("You have been removed from the queue because you joined a group or an instance.")
end
end
end
C_TBL = {}
collectgarbage()
end
----------------------------------------
function REGISTER_TEAMS()
while (true) do
local A_PLR = 0
local H_PLR = 0
for k, v in pairs(Q_TBL) do
if (v:GetTeam() == 0) then
A_PLR = A_PLR + 1
else
H_PLR = H_PLR + 1
end
end
if (A_PLR < 3 or H_PLR < 3) then break; end
local count = 0
local ROUND_ID = ReturnPhase()
local key
B_TBL[ROUND_ID] = {}
MixTable()
for k, v in pairs(Q_TBL) do
if (count < 6) then
table.insert(B_TBL[ROUND_ID], v)
Q_TBL[k] = nil;
count = count + 1
else
break;
end
end
for k in ipairs(P_TBL) do
key = k
end
P_TBL[key+1] = ROUND_ID
table.insert(K_TBL, ROUND_ID)
RegisterTimedEvent("RemoveK_TBL", 15000, 1, ROUND_ID)
PrepareTeam(ROUND_ID)
end
end
function PrepareTeam(ROUND_ID)
for _, v in pairs(B_TBL[ROUND_ID]) do
v:SendBroadcastMessage("You have 15 seconds to buff up after that the battle will start.")
v:PhaseSet(ROUND_ID)
if (v:GetTeam() == 0) then
v:Teleport(530, 2893, 5955, 5.1)
else
v:Teleport(530, 2784, 5902, 5)
end
end
RegisterTimedEvent("StartBattle", 15000, 1, ROUND_ID)
end
function DisbandTeams(ROUND_ID)
for _, v in pairs(B_TBL[ROUND_ID]) do
if (v:IsInWorld()) then
if (v:GetTeam() == 0) then
v:Teleport(0, -8913.23, 554.63, 94)
else
v:Teleport(1, 1502.70, -4415.42, 22)
end
if (not v:IsAlive()) then
RegisterTimedEvent("RA_ress", 3000, 1, v)
end
v:PhaseSet(1)
end
end
B_TBL[ROUND_ID] = nil;
for k, v in pairs(P_TBL) do
if (v == ROUND_ID) then
P_TBL[k] = nil;
end
end
collectgarbage()
end
function StartBattle(ROUND_ID)
local A_PLR = 0
local H_PLR = 0
if (not B_TBL[ROUND_ID]) then return; end
for k, v in pairs(B_TBL[ROUND_ID]) do
if (v:GetTeam() == 0) then
A_PLR = A_PLR + 1
else
H_PLR = H_PLR + 1
end
end
if (A_PLR == 0 or H_PLR == 0) then return; end
for _, v in pairs(B_TBL[ROUND_ID]) do
if (v:GetTeam() == 0) then
v:Teleport(530, 2880, 5941, 4.8)
else
v:Teleport(530, 2795, 5915, 4.1)
end
v:SendBroadcastMessage("Let the battle begin!")
end
end
function MixTable()
local Copy = DublicateTable(Q_TBL)
Q_TBL = {}
while (true) do
local k = math.random(1, #Copy)
table.insert(Q_TBL, Copy[k])
table.remove(Copy, k)
if (#Copy == 0) then
break;
end
end
collectgarbage()
end
function DublicateTable(O_TBL)
local N_TBL = {}
for _, v in pairs(O_TBL) do
table.insert(N_TBL, v)
end
return N_TBL;
end
function RemoveK_TBL(ROUND_ID)
for k, v in pairs(K_TBL) do
if (v == ROUND_ID) then
K_TBL[k] = nil;
end
end
collectgarbage()
end
function RA_ress(plr)
plr:ResurrectPlayer()
end
----------------------------------------
function TEAM_RAMPAGE()
for _, v in pairs(GetActiveRounds()) do
local A_PLR = 0
local H_PLR = 0
local A_AM, H_AM = ReturnTeamAmount(v)
for _, _v in pairs(B_TBL[v]) do
if (not _v:IsAlive()) then
if (_v:GetTeam() == 0) then
A_PLR = A_PLR + 1
else
H_PLR = H_PLR + 1
end
end
if (A_PLR == A_AM) or (H_PLR == H_AM) then
break;
end
end
if (A_PLR == A_AM) then
RegisterTimedEvent("DisbandTeams", 4000, 1, v)
for _, val in pairs(B_TBL[v]) do
val:SendBroadcastMessage("The horde has won this battle!")
end
elseif (H_PLR == H_AM) then
RegisterTimedEvent("DisbandTeams", 4000, 1, v)
for _, val in pairs(B_TBL[v]) do
val:SendBroadcastMessage("The alliance has won this battle!")
end
end
end
end
function PLR_CHEAT(TBL)
for _, _v in pairs(GetActiveRounds()) do
for k, v in pairs(TBL[_v]) do
if (v:GetAreaId() ~= 3775) then
v:CastSpell(5)
end
end
end
end
function GetActiveRounds()
local R_TBL = {}
for _, v in pairs(P_TBL) do
if (v ~= 1) then
if (not KillTbl(v)) then
table.insert(R_TBL, v)
end
end
end
return R_TBL;
end
function KillTbl(ROUND_ID)
for _, v in pairs(K_TBL) do
if (v == ROUND_ID) then
return true;
end
end
return false;
end
function ReturnTeamAmount(ROUND_ID)
local A_PLR = 0
local H_PLR = 0
for k, v in pairs(B_TBL[ROUND_ID]) do
if (v:GetTeam() == 0) then
A_PLR = A_PLR + 1
else
H_PLR = H_PLR + 1
end
end
return A_PLR, H_PLR;
end
----------------------------------------
function ReturnPhase()
local phase
for k in ipairs(P_TBL) do
phase = k
end
return 2^phase;
end
----------------------------------------
function RA_ENTER_ARENA(event, plr)
if (plr:GetAreaId() == 3775) and (plr:GetPhase() > 1) then
if (not ReturnStatus(plr)) then
plr:PhaseSet(1)
end
end
end

function RA_REPOP_ARENA(event, plr)
if (plr:GetAreaId() == 3775) and (plr:GetPhase() > 1) then
if (ReturnStatus(plr)) then
return 0;
end
end
end

function RA_RESS_ARENA(event, plr)
if (plr:GetAreaId() == 3775) and (plr:GetPhase() > 1) then
if (ReturnStatus(plr)) then
plr:SendBroadcastMessage("You can't ress in this battle.")
return 0;
end
end
end

function GetRounds()
local R_TBL = {}
for _, v in pairs(P_TBL) do
if (v ~= 1) then
table.insert(R_TBL, v)
end
end
return R_TBL;
end

function ReturnStatus(plr)
local found = false
for _, v in pairs(GetRounds()) do
if (KillTbl(v)) then
found = true;
break;
end
for _, _v in pairs(B_TBL[v]) do
if (tostring(_v) == tostring(plr)) then
found = true
break;
end
end
if (found) then
break;
end
end
return found;
end

RegisterServerHook(4, "RA_ENTER_ARENA")
RegisterServerHook(7, "RA_REPOP_ARENA")
RegisterServerHook(16, "RA_MSG_HOOK")
RegisterServerHook(32, "RA_RESS_ARENA")
RegisterTimedEvent("TIMED_EVENTS", 5000,

Alexeng
22-08-10, 09:33 AM
Get out leecher. [Lua] Random Team Battles! - AC Web (http://www.ac-web.org/forums/showthread.php?t=96992)

Dimman
22-08-10, 09:55 AM
Avid add credits.

Avidgamer
22-08-10, 11:50 AM
I couldn't without knowing who created it. If people bothered to read they'd know I didn't create it, I never said I did, all I said was I found it in my LUA folder. Read before posting tbh...

Avidgamer
22-08-10, 11:51 AM
Get out leecher. [Lua] Random Team Battles! - AC Web (http://www.ac-web.org/forums/showthread.php?t=96992)

Yeah, I'm a leecher. Oh, wait, I'm not, but you sure are. So next time, don't bother commeting, it means nothing to anyone.

zwroblewski
01-09-10, 11:27 AM
HAHA Pwn xD