SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 14/02/2020, 07:03 PM   #1
BryGarcia
Little Clucker
 
Join Date: Jan 2020
Posts: 7
Reputation: 0
Default Count players in a game mode

[Ingles]
Good, I have put to my gm several game modes, and when someone enters a mode I put a variable such as ModeTDM [playerid] = 1;
And I want to put in a textdraw how many players have that variable or how many players are connected in that game mode, if anyone knows anything and can you please help me.

[Español]

Buenas, le he puesto a mi gm varios modos de juegos, y cuando alguien entra en un modo le pongo una variable como por ejemplo ModoTDM [playerid] = 1;
Y quiero poner en un textdraw cuantos jugadores tienen esa variable o cuantos jugadores están conectados en ese modo de juego, si alguien sabe algo y me pueda ayudar por favor.
BryGarcia is offline   Reply With Quote
Old 14/02/2020, 07:18 PM   #2
xRadical3
Gangsta
 
xRadical3's Avatar
 
Join Date: May 2017
Location: Iran
Posts: 562
Reputation: 20
Default Re: Count players in a game mode

pawn Code:
CountPlayers(mode)
{
    new count;
    foreach(new i : Player)
    {
        switch(mode)
        {
            case 1: if(ModeTDM[i]) count++;
            case 2: if(ModeCNR[i]) count++;
            case 3: if(ModeRP[i]) count++;
            default: count = -1, break;
        }
    }
    return count;
}

/*
CMD:test(playerid, params[])
{
    new string[28];
    format(string, 28, "%i Players play in TDM mode", CountPlayers(1));
    SendClientMessage(playerid, -1, string);
    return 1;
}
*/
xRadical3 is offline   Reply With Quote
Old 14/02/2020, 07:24 PM   #3
ApolloScripter
Huge Clucker
 
ApolloScripter's Avatar
 
Join Date: Sep 2018
Posts: 228
Reputation: 7
Default Re: Count players in a game mode

Hello BryGarcia all you need to do is just loop through all the players, checking how many have that variable with the specified value below a simple example of how it works, when calling this function it will return the number of players connected to the specified game mode

pawn Code:
Get_TDM_PlayerCount()
{
    new playerCount = 0;

    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && ModeTDM[i] == 1)
            playerCount++;
    }

    return playerCount;
}

Now just use this value, and apply it to a TextDraw using (remember to convert to an string):
pawn Code:
TextDrawSetString(Text:text, string[]);


You can check these links, they can help you a lot:
TextDraws: https://forum.sa-mp.com/showthread.php?t=508843
TextDrawEditors: https://forum.sa-mp.com/showthread.php?t=543002
TextDrawSetString: https://wiki.sa-mp.com/wiki/TextDrawSetString
Format: https://wiki.sa-mp.com/wiki/Format
Looping Structures: https://forum.sa-mp.com/showthread.php?t=305770
__________________
ApolloScripter is offline   Reply With Quote
Old 14/02/2020, 07:29 PM   #4
BryGarcia
Little Clucker
 
Join Date: Jan 2020
Posts: 7
Reputation: 0
Default Re: Count players in a game mode

Quote:
Originally Posted by Vizi10 View Post
pawn Code:
CountPlayers(mode)
{
    new count;
    foreach(new i : Player)
    {
        switch(mode)
        {
            case 1: if(ModeTDM[i]) count++;
            case 2: if(ModeCNR[i]) count++;
            case 3: if(ModeRP[i]) count++;
            default: count = -1, break;
        }
    }
    return count;
}

/*
CMD:test(playerid, params[])
{
    new string[28];
    format(string, 28, "%i Players play in TDM mode", CountPlayers(1));
    SendClientMessage(playerid, -1, string);
    return 1;
}
*/
Ups!

This error
error 010: invalid function or declaration
in this line
pawn Code:
CountPlayers(mode)
BryGarcia is offline   Reply With Quote
Old 14/02/2020, 07:36 PM   #5
BryGarcia
Little Clucker
 
Join Date: Jan 2020
Posts: 7
Reputation: 0
Default Re: Count players in a game mode

Quote:
Originally Posted by ApolloScripter View Post
Hello BryGarcia all you need to do is just loop through all the players, checking how many have that variable with the specified value below a simple example of how it works, when calling this function it will return the number of players connected to the specified game mode

pawn Code:
Get_TDM_PlayerCount()
{
    new playerCount = 0;

    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && ModeTDM[i] == 1)
            playerCount++;
    }

    return playerCount;
}

Now just use this value, and apply it to a TextDraw using (remember to convert to an string):
pawn Code:
TextDrawSetString(Text:text, string[]);


You can check these links, they can help you a lot:
TextDraws: https://forum.sa-mp.com/showthread.php?t=508843
TextDrawEditors: https://forum.sa-mp.com/showthread.php?t=543002
TextDrawSetString: https://wiki.sa-mp.com/wiki/TextDrawSetString
Format: https://wiki.sa-mp.com/wiki/Format
Looping Structures: https://forum.sa-mp.com/showthread.php?t=305770

This worked perfectly for me thanks friend for your help you are a genius
BryGarcia 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
[GameMode] IR FREEROAM , a Noob Game Mode ( My First Game Mode) AmirSlaYeR Gamemode Scripts 24 20/12/2014 12:12 PM
People In Mode count fails.... [MNC]Azz Scripting Help 12 24/08/2011 02:08 PM
[HELP] How to get players' count? RoCK'N'Rolla Help Archive 1 10/09/2010 09:42 AM
on all players death once restart game mode? lSCARl Help Archive 7 14/08/2010 07:11 AM
Restart game mode when no more players on team lSCARl Help Archive 1 12/08/2010 10:23 PM


All times are GMT. The time now is 02:39 PM.


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