Vice City: Multiplayer

Server Development => Scripting and Server Management => Script and Content Requests => Topic started by: Kewun on Jul 21, 2016, 07:16 PM

Title: Team Balancing
Post by: Kewun on Jul 21, 2016, 07:16 PM
I would like to request a team balancing script

Because it sucks when there is 5 humans on 1 zombie at server
i would like to use a auto balancer script like 3 players humans 3 players zombies after the 5 humans on 1 zombie..
like in call of duty servers
Title: Re: Team Balancing
Post by: vito on Jul 21, 2016, 09:40 PM
function onPlayerSpawn( player ){
local team0 = 0;
local team1 = 0;
for(local i=0;i<GetMaxPlayers();i++){
local plr = FindPlayer(i);
if(plr){
if(plr.Team==0){
team0++;
} else if(plr.Team==1){
team1++;
}
}
if(team0 > team1){
player.Team=1;
} else if(team0 < team1){
player.Team=0;
}
}
}
You're also need to change .Color and .Skin, get to player specific weapon of his team and set health (as I know you use different HP for teams). So it's just simple example (untested, from phone).
Title: Re: Team Balancing
Post by: Kewun on Jul 22, 2016, 06:25 AM
the player.Team=1 and player.Team=0 i change to the ids of spawn classes?
Title: Re: Team Balancing
Post by: vito on Jul 22, 2016, 06:38 AM
Quote from: Kewun on Jul 22, 2016, 06:25 AMthe player.Team=1 and player.Team=0 i change to the ids of spawn classes?
You can't change classes. You can cange team only. Class = combination of weapons (3 max), color RGB, team ID and skin ID. Class is not a Team.
Title: Re: Team Balancing
Post by: Kewun on Jul 22, 2016, 06:52 AM
last line error expresion

column 1
last line is
}

not even in the onplayerspawn code :/
Title: Re: Team Balancing
Post by: vito on Jul 22, 2016, 08:41 AM
sorry, it's hard to code from chrome mobile into forum. It's just an example.
Title: Re: Team Balancing
Post by: Finch Real on Jul 22, 2016, 08:55 AM
Add one more } at end
Title: Re: Team Balancing
Post by: Kewun on Jul 22, 2016, 10:00 AM
Thanks, guys., it works.
Title: Re: Team Balancing
Post by: Kewun on Nov 11, 2016, 08:19 AM
the problem now is, i discovered that
function onPlayerSpawn( player ){
local team1 = 0;
local team2 = 0;
for(local i=0;i<GetMaxPlayers();i++) {
if ( GetPlayers() == 1 ) player.Spawn()
local plr = FindPlayer(i);
if(plr) {
if(plr.Team==2) {
team2++;
}
else if (plr.Team==1) {
team1++;
}
}
if(team2 > team1) {
player.Disarm()
player.Team=1;
player.Skin = 4
player.SetWeapon(25,250)
player.SetWeapon(17,200)
player.Pos = Vector(-1095.36,99.199,12.8119)
}
else if (team2 < team1) {
player.Disarm()
player.Team=2;
player.Skin = 129
player.SetWeapon(1,0)
player.SetWeapon(9,0)
player.Pos = Vector(-1034.91,41.1358,11.3537)
}
}
}

When there is only 1 player in server, ( me for example ) when i select humans, i spawn as zombie
how fix ?
Title: Re: Team Balancing
Post by: Kewun on Jan 02, 2017, 04:45 PM
BUMP
Title: Re: Team Balancing
Post by: Shadow on Jan 03, 2017, 05:55 AM
Here's an untested snippet. Maybe you'll have more patience next time... Didn't touch squirrel in ages

http://pastebin.com/VJ02gGHg
Title: Re: Team Balancing
Post by: Mötley on Jan 03, 2017, 02:11 PM
Quote from: Shadow on Jan 03, 2017, 05:55 AMHere's an untested snippet. Maybe you'll have more patience next time... Didn't touch squirrel in ages

http://pastebin.com/VJ02gGHg

Looks good to me :)



Pst @Shadow I know you really have not touched Squirrel in a really long time but do you still find this useful?

http://forum.liberty-unleashed.co.uk/index.php/topic,1266.msg7795.html#msg7795

Quote from: Shadow. on Oct 17, 2012, 10:41 AMThis method that I've learned from AdTec shows a nice way to reduce else blocks memory and this is how I do it, maybe results are not visible, but it's certainly an improvement.

function onPlayerCommand( player, cmd, params ) // the actual function
{ // the opening bracket
if( player && cmd ) // Check if player and command exist, not really mandatory..
{ // opening bracket of above 'if'


local delim = cmd.slice( 0, 1 ); // get the first letter from the "cmd" string
switch(delim) // create a switch in which we have our cases.
{// opening bracket of the switch

case "e": // first case

                       if( cmd == "examplecmd" )
                       {
                                 Message("Example command1");
                        }
                        else if( cmd == "examplecmd2" )
                         {
                                Message("Example command2");
                          }
                          break; // break first case to start another one, dunno if it's mandatory

                         case "b":
                                   if( cmd == "blah" )
                                   {
                                               Message("blahblahblah");
                                    }
                     break;
            } // end switch
} // end first bracket
} // end function bracket


Sorry for the awful identation.

Quote from: Juppi on Oct 17, 2012, 12:45 PMChecking the first character of a command will be a big help performance-wise when your script contains lots of commands. There is also a way to optimise the code even further, and it also makes it a bit simpler.

Strings in Squirrel behave much like strings in C. They're basically arrays of characters, and so you can refer to each character by using the array syntax. To get the first character in a string you would do string[0]. This lets us get rid of the relatively expensive slice() call, and each case will become a single character instead of a string.

Notice the difference - 'a' is the character a while "a" is a string containing the text a. The first one will use less memory and comparing characters will always be cheaper than comparing strings.

function onPlayerCommand( player, cmd, params )
{
switch ( cmd[0] ) // Check the first character of the command
{
case 'e': // Commands starting with 'e'
if ( cmd == "examplecmd" )
{
Message("Example command1");
}
else if ( cmd == "examplecmd2" )
{
Message("Example command2");
}
break;

case 'b': // Commands starting with 'b'
if ( cmd == "blah" )
{
Message("blahblahblah");
}
break;
}

return 1; // Returning is not really required but its a good practice to do so
}

Edit: Removed the validity check for player and cmd, LU guarantees that those two will always exist (however that's not always the case with params)

Or did you recall finding a different method?

Sorry always wanted to ask this after all of the time that has passed..
Title: Re: Team Balancing
Post by: jWeb on Jan 03, 2017, 02:55 PM
Quote from: Mötley on Jan 03, 2017, 02:11 PMOr did you recall finding a different method?

Sorry always wanted to ask this after all of the time that has passed..

Commands are much more efficiently handled if stored in a table and then retrieved by their name: http://forum.vc-mp.org/?topic=424.0

This way, the actual comparison is done by native code rather than squirrel code. Therefore, yields a much better performance.

Functions are supposed to be short, few dozen lines of code at most and not thousands. Having an amalgamated function of that size that performs all the commands code is a sure path to performance loss.
Title: Re: Team Balancing
Post by: Shadow on Jan 03, 2017, 04:25 PM
Pretty much what jWeb said.
Title: Re: Team Balancing
Post by: Kewun on Jan 08, 2017, 10:37 AM
ok thx for the examples
heres mine ( from my cs server from lu )
function onClientRequestSpawn( spawnclass )
{
if ( GetPlayers() == 3 ) {
SmallMessage("Sorry, you cant spawn, there are 3 players and its a imbalance, wait for another player to join",3000,1)
return false;
}
local terrorists = 0;
local cterrorists = 0;
for ( local i = 0; i <= 50; i++ ) {
local player = FindPlayer(i)
if ( player ) {
if ( player.Skin == 2 ) cterrorists++;
if ( player.Skin == 116 ) terrorists++;
}
}
if ( terrorists < cterrorists ) { FindLocalPlayer().Spawn(FindSpawnClass(1)) }
else if ( cterrorists < terrorists ) { FindLocalPlayer().Spawn(FindSpawnClass(0)) }
return 1;
}
Title: Re: Team Balancing
Post by: KAKAN on Jan 08, 2017, 04:43 PM
What shall we do with that script?
Title: Re: Team Balancing
Post by: Kewun on Jan 08, 2017, 05:14 PM
nothing i just posted example from my lu server