SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 14/10/2019, 09:51 PM   #1
josh
Big Clucker
 
Join Date: Jul 2019
Posts: 73
Reputation: 3
Default Random Team

I don't really know how to make a random team for players... I want players to spawn in random 2 teams. Can anyone help me in making random teams?


Code:
#include <a_samp>

#define Police 0
#define SUSPECT 1

new Count[MAX_PLAYERS];
new Timer[MAX_PLAYERS];


public OnPlayerSpawn(playerid)
{
    Count[playerid] = 15;
   	Timer[playerid] = SetTimerEx("Countdown", 1000, true, "i", playerid);
    return 1;
}

new Float:TSpawns[][4] =
{ //Terrorists spawns
    {1228.2720,300.3950,19.2926,154.3934}, // Police
    {1223.5419,303.3046,19.3042,154.7037}, // Police
    {1204.1593,267.4443,19.2766,334.2290}, // Police
    {1253.9531,246.2603,19.2754,335.7074}, // Police
    {1317.6305,243.0101,19.1987,65.7550} // Police
};

new Float:SSpawns[][4] =
{ //Swat Spawns
	{1280.1948,218.7540,19.1277,337.3705}// SuSpect
};

forward Countdown(playerid);
public Countdown(playerid)
{
    new str[20];
    Count[playerid] --;
    format(str, 20, "~w~LOADING... %i", Count[playerid]);
    GameTextForAll(str, 1000, 3);
    if(Count[playerid] == 0)
    {
            KillTimer(Timer[playerid]);
            Timer[playerid] = 0;
     	    new randomteam = 1+random(2);
	    SetPlayerTeam(playerid, randomteam); //Depends your "Team" variable defined on..
	    {
			new rnd = random(sizeof(TSpawns));
			SetPlayerPos(playerid,TSpawns[rnd][0],TSpawns[rnd][1],TSpawns[rnd][2]);
                        rnd = CreateVehicle(596, TSpawns[rnd][0], TSpawns[rnd][1], TSpawns[rnd][2],TSpawns[rnd][3], 0, 1, 0);
                       PutPlayerInVehicle(playerid, rnd, 0);
		}
  		SetPlayerTeam(playerid, randomteam); //Depends your "Team" variable defined on..
		{
			new rnd = random(sizeof(SSpawns));
			SetPlayerPos(playerid,SSpawns[rnd][0],SSpawns[rnd][1],SSpawns[rnd][2]);
   			rnd = CreateVehicle(599, SSpawns[rnd][0], SSpawns[rnd][1], SSpawns[rnd][2],SSpawns[rnd][3], 0, 1, 0);
                        PutPlayerInVehicle(playerid, rnd, 0);
		}
	}
 	return 1;
}
josh is offline   Reply With Quote
Old 14/10/2019, 11:27 PM   #2
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,636
Reputation: 1653
Default Re: Random Team

https://wiki.sa-mp.com/wiki/Random
__________________
Do not click on this URL -It is secret information
RIP Slayer 1981-2019 \m/
Discord: Kwarde#1991
Kwarde is online now   Reply With Quote
Old 15/10/2019, 12:07 AM   #3
josh
Big Clucker
 
Join Date: Jul 2019
Posts: 73
Reputation: 3
Default Re: Random Team

Quote:
Originally Posted by Kwarde View Post
I already used it didn't work.
josh is offline   Reply With Quote
Old 15/10/2019, 12:52 AM   #4
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,636
Reputation: 1653
Default Re: Random Team

Quote:
The range of values (from 0 to this value minus one) that can be returned.
Code:
new randomteam = 1+random(2);

#define Police 0
#define SUSPECT 1
So if you start calculating, what values can 'randomteam' become?

Also this does make zero sense. Why did you do this?:
Code:
SetPlayerTeam(playerid, randomteam); //Depends your "Team" variable defined on..
	    {
			new rnd = random(sizeof(TSpawns));
			SetPlayerPos(playerid,TSpawns[rnd][0],TSpawns[rnd][1],TSpawns[rnd][2]);
                        rnd = CreateVehicle(596, TSpawns[rnd][0], TSpawns[rnd][1], TSpawns[rnd][2],TSpawns[rnd][3], 0, 1, 0);
                       PutPlayerInVehicle(playerid, rnd, 0);
		}
  		SetPlayerTeam(playerid, randomteam); //Depends your "Team" variable defined on..
		{
			new rnd = random(sizeof(SSpawns));
			SetPlayerPos(playerid,SSpawns[rnd][0],SSpawns[rnd][1],SSpawns[rnd][2]);
   			rnd = CreateVehicle(599, SSpawns[rnd][0], SSpawns[rnd][1], SSpawns[rnd][2],SSpawns[rnd][3], 0, 1, 0);
                        PutPlayerInVehicle(playerid, rnd, 0);
		}
Genuinly wondering. Do you actually think it works like this or was it an accident? (Which would still be very bad).

In the first case, check my signature and scripting basics @samp wiki before proceeding with scripting

I have more comments on this script but let us focus on this first

P.s.
+1 for re-using 'rnd'
__________________
Do not click on this URL -It is secret information
RIP Slayer 1981-2019 \m/
Discord: Kwarde#1991
Kwarde is online now   Reply With Quote
Old 15/10/2019, 08:10 AM   #5
Beckett
High-roller
 
Beckett's Avatar
 
Join Date: Feb 2012
Location: www.finalnights-rp.com
Posts: 1,794
Reputation: 104
Default Re: Random Team

Randomize between zero and one ` random(1) ` and assign the `Team` variable accordingly. Simple!
__________________
Final Nights Roleplay
The first SA-MP server that is not regulated by administrators.
No OOC hierarchy. Strictly directed by players. Utopian vision.

El primer servidor SA-MP que no está regulado por los administradores.
Sin jerarquías OOC. Estrictamente dirigido por jugadores. Visión utópica.

Primul server de SA-MP care nu este regulat de administratori.
Fără ierarhie OOC. Strict dictat de jucători. Visiune utopică.

Yöneticiler tarafından düzenlenmeyen ilk SA-MP sunucusu.
OOC hiyerarşisi yok. Kesinlikle oyuncular tarafından yönetiliyor. Ütopik görme.


Become a Member of our Discord Channel
Beckett is offline   Reply With Quote
Old 15/10/2019, 08:40 AM   #6
josh
Big Clucker
 
Join Date: Jul 2019
Posts: 73
Reputation: 3
Default Re: Random Team

Quote:
Originally Posted by DaniceMcHarley View Post
Randomize between zero and one ` random(1) ` and assign the `Team` variable accordingly. Simple!
Can you explain more?
josh is offline   Reply With Quote
Old 15/10/2019, 09:38 AM   #7
Beckett
High-roller
 
Beckett's Avatar
 
Join Date: Feb 2012
Location: www.finalnights-rp.com
Posts: 1,794
Reputation: 104
Default Re: Random Team

Yes, it is very basic. Assign a variable to store the `Team` in, let's say this variable is called `team` then randomize it OnPlayerSpawn.

PHP Code:
new team[MAX_PLAYERS];


public 
OnPlayerSpawn(playerid)
{
    
Count[playerid] = 15;
       
Timer[playerid] = SetTimerEx("Countdown"1000true"i"playerid);
    
team[playerid] = random(2);
    if(
team[playerid] = POLICE)
    {
        
// Do your thing here
    
}
    else if(
team[playerid] = SUSPECT)
    {
        
// Do your thing here
    
}
    return 
1;

Just take it easy, and think of it logically and you'll understand how to code. Don't think of it as a code, but as a logical thought process.
__________________
Final Nights Roleplay
The first SA-MP server that is not regulated by administrators.
No OOC hierarchy. Strictly directed by players. Utopian vision.

El primer servidor SA-MP que no está regulado por los administradores.
Sin jerarquías OOC. Estrictamente dirigido por jugadores. Visión utópica.

Primul server de SA-MP care nu este regulat de administratori.
Fără ierarhie OOC. Strict dictat de jucători. Visiune utopică.

Yöneticiler tarafından düzenlenmeyen ilk SA-MP sunucusu.
OOC hiyerarşisi yok. Kesinlikle oyuncular tarafından yönetiliyor. Ütopik görme.


Become a Member of our Discord Channel
Beckett is offline   Reply With Quote
Old 15/10/2019, 11:33 AM   #8
josh
Big Clucker
 
Join Date: Jul 2019
Posts: 73
Reputation: 3
Default Re: Random Team

Quote:
Originally Posted by DaniceMcHarley View Post
Yes, it is very basic. Assign a variable to store the `Team` in, let's say this variable is called `team` then randomize it OnPlayerSpawn.

PHP Code:
new team[MAX_PLAYERS];


public 
OnPlayerSpawn(playerid)
{
    
Count[playerid] = 15;
       
Timer[playerid] = SetTimerEx("Countdown"1000true"i"playerid);
    
team[playerid] = random(2);
    if(
team[playerid] = POLICE)
    {
        
// Do your thing here
    
}
    else if(
team[playerid] = SUSPECT)
    {
        
// Do your thing here
    
}
    return 
1;

Just take it easy, and think of it logically and you'll understand how to code. Don't think of it as a code, but as a logical thought process.
OK. This problem is fixed but I have a new problem. I want the timer to start when 2 players are on the server.
josh is offline   Reply With Quote
Old 15/10/2019, 11:48 AM   #9
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 375
Reputation: 92
Default Re: Random Team

store amount of connected players

PHP Code:
new connected;  //where we store amount of connected players.

public OnPlayerConnect(playerid)
{
    if(!
IsPlayerNPC(playerid))
    {
        
connected ++; //on player join if not npc connected ++ (+1)
    
}
    return 
1;
}

public 
OnPlayerDisconnect(playeridreason)
{
    if(!
IsPlayerNPC(playerid))
    {
        
connected --; //on player leave if not npc connected -- (-1)
    
}
    return 
1;

then

PHP Code:
if(connected 1//if more than 1 player connected so 2+
{
     
//timer here

__________________
Lokii is offline   Reply With Quote
Old 19/10/2019, 09:20 AM   #10
MrAuto
Little Clucker
 
Join Date: Sep 2019
Posts: 9
Reputation: 2
Default Re: Random Team

you don't need table Count[MAX_PLAYERS] to count down

PHP Code:
#include <a_samp>

#define Police 0
#define SUSPECT 1
new Timer[MAX_PLAYERS];


public 
OnPlayerSpawn(playerid)
{
       
Timer[playerid] = SetTimerEx("Countdown"1000false"ii"playerid15);
    return 
1;
}

new 
Float:TSpawns[][4] =
//Terrorists spawns
    
{1228.2720,300.3950,19.2926,154.3934}, // Police
    
{1223.5419,303.3046,19.3042,154.7037}, // Police
    
{1204.1593,267.4443,19.2766,334.2290}, // Police
    
{1253.9531,246.2603,19.2754,335.7074}, // Police
    
{1317.6305,243.0101,19.1987,65.7550// Police
};

new 
Float:SSpawns[][4] =
//Swat Spawns
    
{1280.1948,218.7540,19.1277,337.3705}// SuSpect
};

forward Countdown(playeridcount);
public 
Countdown(playeridcount)
{
    new 
str[20];
    
format(str20"~w~LOADING... %i", (count 1));
    
GameTextForAll(str10003);
    if(
count == 1)
    {
            
Timer[playerid] = 0;
             new 
randomteam 1+random(2);
        
SetPlayerTeam(playeridrandomteam); //Depends your "Team" variable defined on..
        
{
            new 
rnd random(sizeof(TSpawns));
            
SetPlayerPos(playerid,TSpawns[rnd][0],TSpawns[rnd][1],TSpawns[rnd][2]);
                        
rnd CreateVehicle(596TSpawns[rnd][0], TSpawns[rnd][1], TSpawns[rnd][2],TSpawns[rnd][3], 010);
                       
PutPlayerInVehicle(playeridrnd0);
        }
          
SetPlayerTeam(playeridrandomteam); //Depends your "Team" variable defined on..
        
{
            new 
rnd random(sizeof(SSpawns));
            
SetPlayerPos(playerid,SSpawns[rnd][0],SSpawns[rnd][1],SSpawns[rnd][2]);
               
rnd CreateVehicle(599SSpawns[rnd][0], SSpawns[rnd][1], SSpawns[rnd][2],SSpawns[rnd][3], 010);
                        
PutPlayerInVehicle(playeridrnd0);
        }
    }
    else
    {
        
Timer[playerid] = SetTimerEx("Countdown"1000false"ii"playerid, (count 1));
    }

    return 
1;

MrAuto is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
random team spawns Fantje Scripting Help 2 24/04/2016 07:52 PM
Selecting someone random from team XStreeter Scripting Help 12 16/12/2015 09:29 PM
Random team assigning, team members limit: Twizted Scripting Help 2 20/07/2014 01:05 PM
random team AhmedMohamed Scripting Help 4 03/04/2014 01:41 AM
Random team xganyx Scripting Help 0 20/07/2013 06:11 AM


All times are GMT. The time now is 03:03 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.