LUA Scripting for Team Balance for a Source SDK 2006 HL2 mod
2 replies, posted
Hi,
I'm new to lua scripting and the game I play doesn't natively support a team balance function, though it has a character limit function and I know someone who even made a class balance script. This is for a game similar to Team Fortress Classic called Fortress Forever. With their script below, is it possible to balance each team so that if there is 1 person on a team and 0 on another, they would be unable to choose the team with the 1 person already on it instead of balancing per class? Reason I posted the script is so you would see the correct format of each team name such as RED_TEAM, BLUE_TEAM, GREEN_TEAM or YELLOW_TEAM based on other hardcoded game information that requires that format.
Here's the script:
[CODE]
--local player_connected = player_connected
function player_connected( player )
--if player_connected ~= nil then player_connected( player ) end
local player = CastToPlayer(player)
--AddSchedule("startup", 1, class_deny)
class_deny()
end
function class_deny()
local BLUE_TEAM = GetTeam(Team.kBlue)
local RED_TEAM = GetTeam(Team.kRed)
local numplayers = 0
local playing_players = RED_TEAM:GetNumPlayers() + BLUE_TEAM:GetNumPlayers()
ConsoleToAll("Total: ".. playing_players.." Red: "..RED_TEAM:GetNumPlayers().." Blue: "..BLUE_TEAM:GetNumPlayers())
--2v2 or less
if playing_players <= 4 then
--Blue Team
BLUE_TEAM:SetClassLimit(Player.kScout, 2)
BLUE_TEAM:SetClassLimit(Player.kMedic, 2)
BLUE_TEAM:SetClassLimit(Player.kSpy, 2)
BLUE_TEAM:SetClassLimit(Player.kSoldier, -1)
BLUE_TEAM:SetClassLimit(Player.kDemoman, -1)
BLUE_TEAM:SetClassLimit(Player.kHwguy, -1)
BLUE_TEAM:SetClassLimit(Player.kEngineer, -1)
BLUE_TEAM:SetClassLimit(Player.kSniper, -1)
BLUE_TEAM:SetClassLimit(Player.kPyro, -1)
BLUE_TEAM:SetClassLimit(Player.kCivilian, -1)
--Red Team
-- Red Offy
RED_TEAM:SetClassLimit(Player.kScout, -1)
RED_TEAM:SetClassLimit(Player.kMedic, -1)
RED_TEAM:SetClassLimit(Player.kSpy, -1)
-- Red Deffy
RED_TEAM:SetClassLimit(Player.kSoldier, 2)
RED_TEAM:SetClassLimit(Player.kDemoman, 1)
RED_TEAM:SetClassLimit(Player.kHwguy, 1)
RED_TEAM:SetClassLimit(Player.kEngineer, 1)
-- Red Other Guys
RED_TEAM:SetClassLimit(Player.kSniper, -1)
RED_TEAM:SetClassLimit(Player.kPyro, -1)
RED_TEAM:SetClassLimit(Player.kCivilian, -1)
-- 3v3 to 3v4
elseif playing_players >= 6 and playing_players < 8 then
--Red Team
-- +1 HWGuy
RED_TEAM:SetClassLimit(Player.kHwguy, 2)
-- 4v4 to 4v5
elseif playing_players >= 8 and playing_players < 10 then
-- Red Team
-- +1 Engi
RED_TEAM:SetClassLimit(Player.kEngineer, 2)
-- Blue Team
-- +1 Scout
BLUE_TEAM:SetClassLimit(Player.kScout, 3)
--5v5 or more
elseif playing_players >= 10 then
-- Red Team
--Give Def more guys
RED_TEAM:SetClassLimit(Player.kSoldier, 3)
RED_TEAM:SetClassLimit(Player.kDemoman, 2)
RED_TEAM:SetClassLimit(Player.kHwguy, 2)
RED_TEAM:SetClassLimit(Player.kEngineer, 3)
-- Allow Red to play offense
RED_TEAM:SetClassLimit(Player.kScout, 4)
RED_TEAM:SetClassLimit(Player.kMedic, 3)
RED_TEAM:SetClassLimit(Player.kSpy, 3)
-- Let Pyros and Snipers Join in
RED_TEAM:SetClassLimit(Player.kSniper, 1)
RED_TEAM:SetClassLimit(Player.kPyro, 1)
-- Blue Team
-- Allow Blue to Defend
BLUE_TEAM:SetClassLimit(Player.kSoldier, 3)
BLUE_TEAM:SetClassLimit(Player.kDemoman, 2)
BLUE_TEAM:SetClassLimit(Player.kHwguy, 2)
BLUE_TEAM:SetClassLimit(Player.kEngineer, 3)
-- Give Blue Some more guys
BLUE_TEAM:SetClassLimit(Player.kScout, 4)
BLUE_TEAM:SetClassLimit(Player.kMedic, 3)
BLUE_TEAM:SetClassLimit(Player.kSpy, 3)
-- Let Pyros and Snipers Join in
BLUE_TEAM:SetClassLimit(Player.kSniper, 1)
BLUE_TEAM:SetClassLimit(Player.kPyro, 1)
end
end
--[[
Trigger_Test = trigger_ff_script:new({})
function Trigger_Test:ontrigger( trigger_entity )
local player = CastToPlayer ( trigger_entity )
local player = CastToPlayer(player)
local team = GetTeam(Team.kBlue)
team:SetClassLimit(Player.kSniper, 1)
team = GetTeam(Team.kRed)
team:SetClassLimit(Player.kSniper, 1)
ConsoleToAll("YELLING")
end
--]][/CODE]
I attempted to teach myself how to do it, but I didn't get very far, seen below lol:
[CODE]--local player_connected = player_connected
function player_connected( player )
--if player_connected ~= nil then player_connected( player ) end
local player = CastToPlayer(player)
--AddSchedule("startup", 1, team_deny)
team_deny()
end
function team_deny()
local BLUE_TEAM = GetTeam(Team.kBlue)
local RED_TEAM = GetTeam(Team.kRed)
local GREEN_TEAM = GetTeam(Team.kGREEN)
local YELLOW_TEAM = GetTeam(Team.kYELLOW)
local numplayers = 0
local playing_players = RED_TEAM:GetNumPlayers() + BLUE_TEAM:GetNumPlayers() + GREEN_TEAM:GetNumPlayers() + YELLOW_TEAM:GetNumPlayers()
ConsoleToAll("Total: ".. playing_players.." Red: "..RED_TEAM:GetNumPlayers().." Blue: "..BLUE_TEAM:GetNumPlayers().." Green: "..GREEN_TEAM:GetNumPlayers().." Yellow: "..YELLOW_TEAM:GetNumPlayers())
--Player trying to join a team that has the same amount of players as other teams
if playing_players = RED_TEAM = 0
RED_TEAM:SetClassLimit(Player, 1)
BLUE_TEAM:SetClassLimit(Player, 1)
GREEN_TEAM:SetClassLimit(Player, 1)
YELLOW_TEAM:SetClassLimit(Player, 1)
end
if playing_players = RED_TEAM = 1
RED_TEAM:SetClassLimit(Player, 2)
BLUE_TEAM:SetClassLimit(Player, 2)
GREEN_TEAM:SetClassLimit(Player, 2)
YELLOW_TEAM:SetClassLimit(Player, 2)
end
end
--]][/CODE]
I'm sure there's an easier way to set the limit than by my convoluted method which probably wouldn't even work. I've been at this for hours but my brain hurts and I need some help.
This scripting is specific to FF so the best place to ask would be their forums: [url]http://forums.fortress-forever.com/forumdisplay.php?f=44[/url]
And holy shit they're still on Source 2006?
Yeahh jesus christ source 06 still? how are they still alive?
Sorry, you need to Log In to post a reply to this thread.