How to count and show all players online in a DM zone.
#1

Hello, today I've started making a DM arenas script, and it will have like 8 arenas on it. I want to make a system to count players from arenas and show it on a dialog, here's how i want it:

PHP код:
new InDM[MAX_PLAYERS]; 
PHP код:
CMD:dm(playeridparams[])
{
    new 
arenas[1000], string[1000];
    if(
InDM[playerid]) return SendClientMessage(playeridCOLOR_LIGHTBLUE"You are already in a DM arena, do /lobby first.");
    
format(stringsizeof(string), "{11799C}ID\t{11799C}Name\t{11799C}Players Online\n"); strcat(arenasstring);
    
format(stringsizeof(string), "{9C9C9C}0\t{9C9C9C}Las Venturas Police Department\t%d players here\n"WHAT DO DO HERE"); strcat(arenas, string);
    format(string, sizeof(string), "
{9C9C9C}1\t{9C9C9C}Big Smoke's Crack Factory\t%dplayers here\n" WHAT DO I DO HERE); strcat(arenas, string);
    Dialog_Show(playerid, DIALOG_DM, DIALOG_STYLE_TABLIST_HEADERS, "DM Arenas List", arenas, "Enter", "Close");
    return 1;

So, how do i count players from Las Venturas Police Department and show to the player how players are there,
same for Big Smoke, count all players online in that arena and show it to the player on the dialog..

NOTICE: I don't want to count players in all arenas, i want to count people from each arena if you get what im saying.
Reply
#2

PHP код:
new 
    
PlayerCount[2],
    
bool:InDM[MAX_PLAYERS];  
CMD:dm(playeridparams[]) 
{
    if(
InDM[playerid]) return SendClientMessage(playeridCOLOR_LIGHTBLUE"You are already in a DM arena, do /lobby first."); 
    
    new 
str[350];
    
format(str350"{11799C}ID\t{11799C}Name\t{11799C}Players Online\n{9C9C9C}0\t{9C9C9C}Las Venturas Police Department\t%d players here\n{9C9C9C}1\t{9C9C9C}Big Smoke's Crack Factory\t%d players here"PlayerCount[0], PlayerCount[1]);
    
Dialog_Show(playeridDIALOG_DMDIALOG_STYLE_TABLIST_HEADERS"DM Arenas List"str"Enter""Close");
    return 
1

PHP код:
PlayerCount[0//players in the sand id 0
PlayerCount[1//players in the sand id 1 
Now when a player enters one of the arenas:

PHP код:
PlayerCount[0] += 1//when the player enters the arena "0"
PlayerCount[1] += 1//when the player enters the arena "1" 
Now when a player leaves one of the arenas:

PHP код:
PlayerCount[0] -= 1//when the player leaves the arena "0"
PlayerCount[1] -= 1; /when the player leaves the arena "1" 
If you are going to put more sands you must increase the variable "PlayerCount [2]"
Reply
#3

Now after doing Undef1ned's code, this is what happens when i do lobby:

https://imgur.com/a/Z6Y9vbl

Code:

PHP код:
CMD:lobby(playeridparams[])
{
    if(
InDM[playerid])
    {
        
SpawnUser(playerid);
        
SendClientMessage(playeridCOLOR_LIGHTBLUE"You have returned to the lobby.");
        
InDM[playerid] = false;
        
CountInDM[0] -= 1;
        
CountInDM[1] -= 1;
    }
    else
    {
        
SendClientMessage(playeridCOLOR_LIGHTBLUE"You are not inside any DM area.");
    }
    return 
1;

Reply
#4

Код:
new var; //Global variable
when the player enters the arena
Код:
var++
then show this on string formatted and when player leaves use
Код:
var--;
Reply
#5

Quote:
Originally Posted by Electrifying
Посмотреть сообщение
Код:
new var;
when the player enters the arena
Код:
var++
then show this on string formatted and when player leaves use
Код:
var--;
Are you blind or what? Undef1ned already posted a better code but i have an issue, you can check that if you want, thanks.
Reply
#6

Quote:
Originally Posted by Score
Посмотреть сообщение
Are you blind or what? Undef1ned already posted a better code but i have an issue, you can check that if you want, thanks.
If the code was good, it would work.
Reply
#7

Your code is wrong. You must have a variable to verify in which game the player is.

Example:

PHP код:
enum
{
    
Game_None,
    
Game_LV,
    
Game_BS
};
new 
    
PlayerCount[2],
    
InDM[MAX_PLAYERS];  
CMD:lobby(playeridparams[])
{
    if(
InDM[playerid] == Game_None) return  SendClientMessage(playeridCOLOR_LIGHTBLUE"You are not inside any DM area.");
    
    switch(
InDM[playerid])
    {
        case 
Game_LVCountInDM[0] -= 1;
        case 
Game_BSCountInDM[1] -= 1;
    }
    
    
SpawnUser(playerid);
    
InDM[playerid] = Game_None;
    
SendClientMessage(playeridCOLOR_LIGHTBLUE"You have returned to the lobby.");
    return 
1;

And when you enter a game it would be something like this:

PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch(
dialogid)
    {
        case 
DIALOG_DM:
        {
            if(
response)
            {
                switch(
listitem)
                {
                    case 
0:
                    {
                        
CountInDM[0] += 1;
                        
//code
                    
}
                    case 
1:
                    {
                        
CountInDM[1] += 1;
                        
//code
                    
}
                }
            }
            return 
1;
        }
    }
    return 
1;

Reply
#8

Thanks, but where do i put for example Game_LV ondialogresponse?

EDIT: Now it works, thank you +rep
Reply
#9

If you enter the game "Las Venturas Police Department"

PHP код:
InDM[playerid] = Game_LV
Or if you enter the game "Big Smoke's Crack Factory"

PHP код:
InDM[playerid] = Game_BS
EDIT: Use this in the DM command:

PHP код:
if(InDM[playerid] != Game_None) return SendClientMessage(playeridCOLOR_LIGHTBLUE"You are already in a DM arena, do /lobby first."); 
Reply
#10

PHP код:
CountDMPlayers()
{
    new 
cdmplayers;
    for(new 
ii<MAX_PLAYERS;i++)
    {
        if(
InDM[i] ==1)
        {
                
cdmplayers++;
        }
    }
    return 
cdmplayers;

as you asked to count dm players then use this method
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)