What happened to OC? - CLOSED Carnage?!
Sign in to follow this  
Followers 0
stunt_man

Autobalance teams based on score of previous match

Hi OC it's your favorite script-requester, stunt_man :)

So a few of you have played in my servers and maybe have played against some of the savages that are frequently stomping other players on the regular.

I'm using NeX's timer script, which performs a map reset about 15-20 seconds into the match.

I'm looking for a script to automate team balancing. The problem with SAPP's balance_teams command is that it only looks at current scores. And it doesn't work after a match has ended (ex: during Post-Game Carnage Reprot). What I would like to do is have the teams balanced according to the score of the previous match. For example:

End score of Match 1:

  • Red Team: 50
  • Player A: 30 kills
  • Player B: 20 kills
  • Blue Team: 18
  • Player C: 10 kills
  • Player D: 8 kills

***Autobalance takes place***

Beginning of Match 2:

  • Red Team:
  • Player A
  • Player D
  • Blue Team:
  • Player B
  • Player C

The auto-balance should take place at the start of the match (let's say, a couple of seconds in). The script does not need to include the map reset that occurs after 15-20 seconds, as that's handled by NeX's timer script.

Bonus points if the script can be easily disabled using SAPP's event system (I would create a custom command for low-level admins that can disable the automatic team balancing for when players want to keep their teammates).

Thanks a bunch

NeX and swamp like this

Share this post


Link to post
Share on other sites

Tiddy-bits:

I'm using 002's Team Shuffler script (http://opencarnage.net/index.php?/topic/4165-team-shuffler/), to shuffle the teams before every match starts as an alternative. But in 2v2 there's a 50% chance that the teams will be exactly the same, so it doesn't work that well.

A member of my Discord group, Hootspa, is going to look into an autobalance script like I'm requesting here, but he's never done any SAPP scripting so it could be some time before it's fully-functional. I'll post it here if anything comes out of it.

In the meantime, if someone else wants to take a swing at it I surely won't stop you!

Edited by stunt_man

Share this post


Link to post
Share on other sites

well,

since this is getting late for you,

i made something using sapp ^_^

 

here is the script. with messages to see if its working or not.

 

add this to event.txt

event_end  $so=0 $pn=4 'var_set sccloseb1 0;var_set sccloseb2 1;var_set sccloser1 0;var_set sccloser2 1;wait 200;cevent sc 1;wait 200;cevent sc 2;wait 200;cevent sc 3;wait 200;cevent sc 4;say * "players send to save scores and names" '
event_end $so=0 $pn!=4 'say * "score saving failed. need 4 players to save scores" '

event_custom $ename:sc $pn=4 $sccloser1=0 $team:red  'var_set red_ps1 $score $n;var_set red_pn1 "$name";wait 100;var_set sccloser1 1;var_set sccloser2 0;say * "a. red_ps1 and red_pn1 set" '
event_custom $ename:sc $pn=4 $sccloser2=0 $team:red $red_ps1>$score 'var_set red_ps2 $score $n;var_set red_pn2 "$name";say * "b. red_ps2 and red_pn2 set" '
event_custom $ename:sc $pn=4 $sccloser2=0 $team:red $red_ps1<$score 'var_set red_ps2 $red_ps1;wait 100;var_set red_ps1 $score;var_set red_pn2 "$red_pn1";wait 100;var_set red_pn1 "$name";say * "c. red_ps2 set with red_ps1 , red_pn2 set with red_pn1" '
event_custom $ename:sc $pn=4 $sccloseb1=0 $team:blue 'var_set blue_ps1 $score $n;var_set blue_pn1 "$name";wait 100;var_set sccloseb1 1;var_set sccloseb2 0;wait 10;say * "d. blue_ps set, blue_pn1 set" '
event_custom $ename:sc $pn=4 $sccloseb2=0 $team:blue $blue_ps1>$score 'var_set blue_ps2 $score $n;var_set blue_pn2 "$name";w8 1;say * "e. blue_ps2 set, blue_pn2 set" '
event_custom $ename:sc $pn=4 $sccloseb2=0 $team:blue $blue_ps1<$score 'var_set blue_ps2 $blue_ps1;wait 100;var_set blue_ps1 $score;var_set blue_pn2 "$blue_pn1";wait 100;var_set blue_pn1 "$name";w8 1;say * "f. blue_ps2 set with blue_ps1 , blue_pn2 set with blue_pn1" '


event_start $so=0 'w8 10;cevent bl;say * "send to balance" '
event_custom $pn=4 $ename:bl $red_ps1>$blue_ps1 $red_ps2>=$blue_ps2 'w8 2;st "$red_pn1" blue;wait 100;st "$blue_pn1" red;w8 1;say * "g. $red_pn1 switched to blue team. $blue_pn1 switched to red team " '
event_custom $pn=4 $ename:bl $blue_ps1>$red_ps1 $blue_ps2>=$red_ps2 'w8 3;st $red_pn1 blue;wait 100;st $blue_pn1 red;w8 1;say * "h. $blue_pn1 switched to blue team. $red_pn1 switched to red team " '
event_custom $pn=4 $ename:bl $red_ps1>$blue_ps1 $red_ps2<$blue_ps2 'w8 4;say * "i. no balance needed" '
event_custom $pn=4 $ename:bl $blue_ps1>$red_ps1 $blue_ps2<$red_ps2 'w8 5;say * "k. no balance needed " '
event_custom $pn!=4 $ename:bl 'w8 1;say * "balance faild. need 4 players to balance " '

event_start 'w8 15;var_set blue_ps1 0;var_set blue_ps2 0;var_set red_ps1 0;var_set red_ps2 0;say * "scores deleted" '



add this to sapp init.txt

var_add sccloser1 1
var_add sccloser2 1
var_add sccloseb1 1
var_add sccloseb2 1

var_add blue_ps1 1
var_add blue_ps2 1
var_add red_ps1 1
var_add red_ps2 1

var_add blue_pn1 0
var_add blue_pn2 0
var_add red_pn1 0
var_add red_pn2 0

var_add so 1

so, if you see these things on messages, they means followings;

 

blue_pn1 = name of the highest scored player of blue team

blue_pn2 = name of the lowest scored player of blue team

red_pn1 = name of the highest scored player of red team

red_pn2= name of the highest scored player of red team

 

blue_ps1 = score of the highest scored player of blue team

blue_ps1 = score of the lowest scored player of blue team

red_ps1 = score of the highest scored player of red team

red_ps1 = score of the lowest scored player of red team

 

TEST VIDEO

 

 

this is the test script i use in the video. only works for one player. just adding this here just in case, like, if you want to follow what happen in the video step by step maybe?...

 

event_custom $ename:sc  $sccloser1=0 $team:red  'var_set red_ps1 $score $n;var_set red_pn1 "$name";wait 100;var_set sccloser1 1;var_set sccloser2 0;say * "a. red_ps1 and red_pn1 set" '
event_custom $ename:sc  $sccloser2=0 $team:red $red_ps1>$score 'var_set red_ps2 $score $n;var_set red_pn2 "$name";say * "b. red_ps2 and red_pn2 set" '
event_custom $ename:sc  $sccloser2=0 $team:red $red_ps1<$score 'var_set red_ps2 $red_ps1;wait 100;var_set red_ps1 $score;var_set red_pn2 "$red_pn1";wait 100;var_set red_pn1 "$name";say * "c. red_ps2 set with red_ps1 , red_pn2 set with red_pn1" '
event_custom $ename:sc  $sccloseb1=0 $team:blue 'var_set blue_ps1 $score $n;var_set blue_pn1 "$name";wait 100;var_set sccloseb1 1;var_set sccloseb2 0;wait 10;say * "d. blue_ps set, blue_pn1 set" '
event_custom $ename:sc  $sccloseb2=0 $team:blue $blue_ps1>$score 'var_set blue_ps2 $score $n;var_set blue_pn2 "$name";w8 1;say * "e. blue_ps2 set, blue_pn2 set" '
event_custom $ename:sc  $sccloseb2=0 $team:blue $blue_ps1<$score 'var_set blue_ps2 $blue_ps1;wait 100;var_set blue_ps1 $score;var_set blue_pn2 "$blue_pn1";wait 100;var_set blue_pn1 "$name";w8 1;say * "f. blue_ps2 set with blue_ps1 , blue_pn2 set with blue_pn1" '

event_custom  $ename:bl $red_ps1>$blue_ps1 $red_ps2>=$blue_ps2 'w8 2;st "$red_pn1" blue;wait 100;st "$blue_pn1" red;w8 1;say * "g. $red_pn1 switched to blue team. $blue_pn1 switched to red team " '
event_custom  $ename:bl $blue_ps1>$red_ps1 $blue_ps2>=$red_ps2 'w8 3;st $red_pn1 blue;wait 100;st $blue_pn1 red;w8 1;say * "h. $blue_pn1 switched to red team. $red_pn1 switched to blue team " '
event_custom  $ename:bl $red_ps1>$blue_ps1 $red_ps2<$blue_ps2 'w8 4;say * "i. no balance needed" '
event_custom  $ename:bl $blue_ps1>$red_ps1 $blue_ps2<$red_ps2 'w8 5;say * "k. no balance needed " '

commands

scme # 'slayer_score $n #' -1
sc 'cevent sc $n' -1
ck 'say * "red_pn1 = $red_pn1.  red_pn2 = $red_pn2.  red_ps1 = $red_ps1. red_ps2 = $red_ps2. blue_pn1=$blue_pn1. blue_pn2=$blue_pn2.  blue_ps1=$blue_ps1.   blue_pn2=$blue_ps2" ' -1
bl 'w8 1;cevent bl' -1

sc= send the scores and names to save it.

ck = check whether names and scores saved.

bl = balance

 

-----------------------------------------------------------------------

 

i dont remember whether i forgot to tell something or not  :/

 

edit: re uploaded a new video.

edit: fixed a wrong message

edit: edited the script to set it on/off now.

 

commands.txt

yourcommand1 'var_set so 1;say $n "script is now off" '
yourcommand2 'var_set so 0;say $n "script is now on" '
Edited by no offence
stunt_man likes this

 

 

Share this post


Link to post
Share on other sites

Hey thanks for giving this a shot! I'll test it out this weekend. Come join our Discord if you haven't already, we can get some games going

Share this post


Link to post
Share on other sites

Alright finally got around to testing this. It works as advertised: when four players are in the match, it splits up the teams. However, if there are less than 4 players in the match, no balance takes place. Haven't encountered any bugs.

 

Someone else in our Discord group created a script. I'm hosting the one from this thread in the Los Angeles server, and the other one in Montreal.

 

Here's the other script (Lua): https://www.dropbox.com/s/otypravpzyy2vii/balanceteams.zip?dl=0

 

They both do their jobs, though I'm pretty sure the one I posted handles 2v1 situations more gracefully (ex: it will still split up the two best players and pair the best with the worst).

Share this post


Link to post
Share on other sites

good to know that its working.

yeah, need exact 4 players. i didn't want to go further variations since making this was hard enough by it self ^^

and this is the balance logic (you maybe already know)

GdVp2Hc.png

 

anyway i dont mind if you stop using this script, since the script you wanted available now. (after all this is just a "hold me until its available" script hehe)

and it was a good experience making this script since this is kind a sapp pushing to its limits.. (i guess)

making this scrips would have been easy if the sapp variable system was based on player names or IPs. but since it was just player slot based, i had to go deep and make the player name based variables by my self.

 

thanks for using this. and good to know the script works that i made.

Edited by no offence
stunt_man likes this

 

 

Share this post


Link to post
Share on other sites

good to know that its working.

yeah, need exact 4 players. i didn't want to go further variations since making this was hard enough by it self ^^

and this is the balance logic (you maybe already know)

GdVp2Hc.png

 

anyway i dont mind if you stop using this script, since the script you wanted available now. (after all this is just a "hold me until its available" script hehe)

and it was a good experience making this script since this is kind a sapp pushing to its limits.. (i guess)

making this scrips would have been easy if the sapp variable system was based on player names or IPs. but since it was just player slot based, i had to go deep and make the player name based variables by my self.

 

thanks for using this. and good to know the script works that i made.

 

No problem. Actually we played in the Los Angeles server tonight (the one hosting your script), and it only bugged out once. I ended up with a 3v1. I don't remember there being any abnormal circumstances either. Wish I had more info for you :/

 

The only other gripe is that we would finish a really close match and it would still re-balance, though the teams were perfect. Suggestion: If the score of the previous match is 50 to 40+, don't re-balance.

Edited by stunt_man

Share this post


Link to post
Share on other sites

Heh. Heheh. Yeah, not.....no.

 

no lua was used. just sapp.

and just sapp is very limited u know(?)

 

btw why you said this step with Eschaton, a map editing tool;

http://opencarnage.net/index.php?/topic/5845-3-weapons/?p=80115

instead of this simple sapp step.

event_spawn 'wdel $n;spawn weap "weapons\shotgun\shotgun" $n;wadd $n;spawn weap "weapons\pistol\pistol" $n;wadd $n;w8 1;spawn weap "weapons\rocket launcher\rocket launcher" $n;wadd $n;w8 1;ammo $n 999 5'

are you following sapp and still prefer eschaton method over sapp method?

special reason for this?

 

 

 

 

-------------------------------------------

 

 

 

and it only bugged out once. I ended up with a 3v1. I don't remember there being any abnormal circumstances either. Wish I had more info for you :/

 

if anything from my last pm didn't happen, this is not a good sign. now im worried :/

 

Suggestion: If the score of the previous match is 50 to 40+, don't re-balance.

 

without editing the current script, im trying to use $so variable which was used to on/off the script, and a new variable with it. as a result u may still see "a. red_ps1 and red_pn1 set" messages. but it wont balance at next game.

 

add to event

event_end $bo=0 $so=0 $redscore=50 $bluescore>40 'var_set so 1;var_set bo 1;say * "l. good match, no balance need for next match" '
event_end $bo=0 $so=0 $bluescore=50 $redscore>40 'var_set so 1;var_set bo 1;say * "m. good match, no balance need for next match" '
event_start $bo=1 $so=1 'w8 16;var_set bo 0;var_set so 0;say * "bo=o, so=0" '

this part could have been more 'less cheap' looking if i knew how to use sapp $arguments with + , - , / ,x in them.

like;

"$redscore-$bluascore>10"

its either i dont know how to do it or sapp does not support them.

heee

 

add to init

var_add bo 1

well.... its should work.

oh please work! :(

Edited by no offence

 

 

Share this post


Link to post
Share on other sites

I'll put it up on the LA server tonight, where it will stay at least until the weekend. Ultimately I may stick with the LUA script for organizational purposes, but don't let that discourage you!

Share this post


Link to post
Share on other sites
Sign in to follow this  
Followers 0
  • Recently Browsing   0 members

    No registered users viewing this page.