¥Weeds¥ Advanced Bot Team Balance v1.4 
24 comments Advanced Bot Team Balance v1.4
This Lua script for Counter-Strike 2D will automatically add or remove bots to a server in order to maintain a specified number of total players (bots plus humans) within the game.
Settings can be changed (and the script can be enabled or disabled) by issuing simple console commands on a "listen" server (when starting a new game), as well as on a dedicated server via RCon.
(Click Spoiler for complete readme and usage instructions, also included in the ZIP)
This Lua script for Counter-Strike 2D will automatically add or remove bots to a server in order to maintain a specified number of total players (bots plus humans) within the game.
Settings can be changed (and the script can be enabled or disabled) by issuing simple console commands on a "listen" server (when starting a new game), as well as on a dedicated server via RCon.
(Click Spoiler for complete readme and usage instructions, also included in the ZIP)
edited 7×, last 04.01.13 09:58:21 am

Comments
24 commentsLog in!
You need to log in to be able to write comments!Log in
Disreguard my comment below... I'm well on my way to adding config file support
(EDIT) Configuration file support added!
(EDIT 2) v1.4: A few changes here and there (see "Spoiler").

(EDIT) Configuration file support added!

(EDIT 2) v1.4: A few changes here and there (see "Spoiler").
edited 4×, last 02.01.13 02:33:25 pm
Folks,
One thing that I've recently discovered is that CS2D flushes all of the variables in a Lua script when the map cycles on a listen or dedicated server. This resets the main team balancing variable to 5 (the default "bot_balance = 5" line included in the Lua script).
Now, being that the 'bot team balance' can be configured via commands (listen server, as well as RCon for a dedicated server) in the console ("bot_balance 6" etc...), it would be SUPER if there was some way to save it to a config file, and then read the variable from the config file after the map cycles (and the Lua script is re-executed).
Anyhow, could anyone give any pointers on how to:
1 - Open a config file: e.g.
Open the filename "AdvancedBotTeamBalance.cfg" (which would be located in the same directory as the "AdvancedBotTeamBalance.lua" script).
2 - Read a line from the config file (in this case, there would be only one line to store the team balance number... BUT, POSSIBLY two lines; a second for if the team balancing routine is enabled or disabled): e.g.
bot_balance = 4
bot_balance_enabled = 1
3 - Read the "4" from the top line, and then pass it on to the Lua script's variable (as well as the "1" and also pass it on as another Lua script variable).
...and ALSO, WRITE to the config file if/when any of the settings have been changed in-game (listen server, or via RCon).
I've read a LOT from this site -> http://www.lua.org/manual/5.1/manual.html , and I THINK it probably would have something to do with using the "io.open", "io.read", "io.write" commands, etc... but it's WAY over my understanding of Lua coding (unless I could see a simple and an easy-to-understand code example).
One thing that I've recently discovered is that CS2D flushes all of the variables in a Lua script when the map cycles on a listen or dedicated server. This resets the main team balancing variable to 5 (the default "bot_balance = 5" line included in the Lua script).
Now, being that the 'bot team balance' can be configured via commands (listen server, as well as RCon for a dedicated server) in the console ("bot_balance 6" etc...), it would be SUPER if there was some way to save it to a config file, and then read the variable from the config file after the map cycles (and the Lua script is re-executed).
Anyhow, could anyone give any pointers on how to:
1 - Open a config file: e.g.
Open the filename "AdvancedBotTeamBalance.cfg" (which would be located in the same directory as the "AdvancedBotTeamBalance.lua" script).
2 - Read a line from the config file (in this case, there would be only one line to store the team balance number... BUT, POSSIBLY two lines; a second for if the team balancing routine is enabled or disabled): e.g.
bot_balance = 4
bot_balance_enabled = 1
3 - Read the "4" from the top line, and then pass it on to the Lua script's variable (as well as the "1" and also pass it on as another Lua script variable).
...and ALSO, WRITE to the config file if/when any of the settings have been changed in-game (listen server, or via RCon).
I've read a LOT from this site -> http://www.lua.org/manual/5.1/manual.html , and I THINK it probably would have something to do with using the "io.open", "io.read", "io.write" commands, etc... but it's WAY over my understanding of Lua coding (unless I could see a simple and an easy-to-understand code example).
edited 3×, last 23.12.12 05:30:57 am
Just updated the script (currently version 1.1) with the extremely minor changes that I refered to below.
@
sheeL: And yes you copied my method. While changing 3-5 things without my permission. Also your code will not work, deal with it.


@
Yates: and @
Jynxxx: There are many ways to do this
http://www.unrealsoftware.de/files_show.php?file=12891&start=0#com137567


http://www.unrealsoftware.de/files_show.php?file=12891&start=0#com137567
@
sheeL: Are you BR or something? - That is basically stealing.

@
sheeL: your a fucking idiot. I made the code and you just change one little thing. Are you seriously that retarded?
BR? HUEHUEHEUHEUHEUEHUEHEUHEUE

BR? HUEHUEHEUHEUHEUEHUEHEUHEUE
Admin/mod comment:

21.12.12 05:07:43 pm

Code:
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
addhook("parse","OnCommand")
addhook("rcon","OnCommand")
function OnCommand(param)
local avg = param:sub(13,14)
if param == "bot_balance "..avg then
msg(string.format("©255255255Bot balance has been changed to "..avg))
botbalance=avg
return 1
end
end
addhook("rcon","OnCommand")
function OnCommand(param)
local avg = param:sub(13,14)
if param == "bot_balance "..avg then
msg(string.format("©255255255Bot balance has been changed to "..avg))
botbalance=avg
return 1
end
end
edited 2×, last 21.12.12 06:23:53 pm
@Jynxxx,
But that is using the "say" command, correct? The first experimental version of the script that I created I was using the "say" command.
But, later decided to use console commands to control the script.
But that is using the "say" command, correct? The first experimental version of the script that I created I was using the "say" command.
But, later decided to use console commands to control the script.
Shortened down that hideous parse function.
Code:
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
_balance = 0
addhook("say","_say")
function _say(id,text)
local botbalance = text:sub(13,14)
if text == "bot_balance "..botbalance then
msg("©255255255Bot balance has been change to "..botbalance.."!@C")
_balance = botbalance
return 1
end
end
addhook("say","_say")
function _say(id,text)
local botbalance = text:sub(13,14)
if text == "bot_balance "..botbalance then
msg("©255255255Bot balance has been change to "..botbalance.."!@C")
_balance = botbalance
return 1
end
end
Glad ya'll liked it
As a newbie to CS2D, this was a little feature that I wished that the game had. So... after a little 'crash course' in Lua scripting (and a LOT of cussing LOL!), this is what I came up with
P.S. Look for a slightly updated version later today (will still have the same version number though, 1.0):
I discovered later that it probably would be better to make the 'server join message' ONLY be displayed to the current player that is actually joining the game (verses having that message printed on the screen to ALL of the players on the server when another player joins the game).
Also, I'm gonna add a little clarification about human spectators in the game when the script is running:
Spectators are NOT counted in the 'total players' count... which is by design (and how I prefered it), but I need to clarify that.

As a newbie to CS2D, this was a little feature that I wished that the game had. So... after a little 'crash course' in Lua scripting (and a LOT of cussing LOL!), this is what I came up with

P.S. Look for a slightly updated version later today (will still have the same version number though, 1.0):
I discovered later that it probably would be better to make the 'server join message' ONLY be displayed to the current player that is actually joining the game (verses having that message printed on the screen to ALL of the players on the server when another player joins the game).
Also, I'm gonna add a little clarification about human spectators in the game when the script is running:
Spectators are NOT counted in the 'total players' count... which is by design (and how I prefered it), but I need to clarify that.