Players Alive counter doesn't go down OnPlayerDisconnect
#1

Hello, with my project partner we have been working on an alive counter, i've been working on it since 02:19 and it's already 05:23
We are doing the Race DM mode of our Multi Mode
and we have been the players alive counter go down and up when a player dies, spawns, is spectating, gets in a vehicle etc...
There was many bugs, and made it to fix all of them (yay)
The problem comes when the player disconnects, i want to make the counter go down when a player on the Race DM mode disconnects, the problem is that it doesn't, it stays at the same place!

There is no errors nor warnings when i compile and everything seems to be fine, so i came here asking for help ^^

Here is my code:
PHP код:
public OnPlayerDisconnect(playeridreason)
{
    
// Login Register system, and leaving messages here!
    // From here is the alive counter!
    
new alive[3];
    for(new 
0MAX_PLAYERSi++)
    {
        if (
pInfo[playerid][DM] && pInfo[i][DM] == 1)
        {
            
SetPlayerHealth(playerid0);
            
AlivePlayers-=1;
            if (
AlivePlayers 10)
            {
                
format(alivesizeof(alive), "0%i"AlivePlayers);
            }
            else if (
AlivePlayers 9)
            {
                
format(alivesizeof(alive), "%i"AlivePlayers);
            }
            
TextDrawSetString(numberalalive);
            
TextDrawShowForPlayer(ialbox1);
            
TextDrawShowForPlayer(ialbox2);
            
TextDrawShowForPlayer(iAlive);
            
TextDrawShowForPlayer(inumberal);
        }
    }
    return 
1;

Reply
#2

I don't really get it but I doubt that you have created
Код:
pInfo[playerid][DM] = 0;
in OnPlayerDisconnect before your timer

That means when the player disconnects, the DM info sets to 0
before your alive counter starts

So when the counter checks the player, it won't work because you are checking if the DM info sets to 1
Код:
pInfo[playerid][DM] && pInfo[i][DM] == 1
Which is not

Just guessing xd

And btw, why you are setting the health of the player to 0 when he disconnects? xD
Reply
#3

Quote:
Originally Posted by UnDetectable
Посмотреть сообщение
I don't really get it but I doubt that you have created
Код:
pInfo[playerid][DM] = 0;
in OnPlayerDisconnect before your timer

That means when the player disconnects, the DM info sets to 0
before your alive counter starts

So when the counter checks the player, it won't work because you are checking if the DM info sets to 1
Код:
pInfo[playerid][DM] && pInfo[i][DM] == 1
Which is not

Just guessing xd

And btw, why you are setting the health of the player to 0 when he disconnects? xD
Код:
pInfo[playerid][DM] = 1;
is used to check if the player is in the DM mode or not when the player leave it automatically sets it to 0

and i'm setting the hp to 0
cuz when the player dies it removes 1 from the alive counter, so i thought that would work, but it didn't, and i forgot to remove it!
Reply
#4

Check this!

pawn Код:
/*
    ~Changelog~

    - You had everything done inside the loop which caused some problems. Now everything related to 'playerid' (who disconnects) is done outside the loop.
    - After moving code outside the for loop, I realized that the loop was only used for those TextDrawShowForPlayer which I don't think you need at all.
        So I completely deleted the loop code because it wasn't needed at all. You're just wasting RPCs. Just show the textdraws once they enter DM mode.
    - Fixed string size and used some trick instead of that if/elseif statement.
    - Removed SetPlayerHealth because it wasn't needed at all.

*/


public OnPlayerDisconnect(playerid, reason)
{
    if(pInfo[playerid][DM]) // If this player is in DM mode
    {
        new alive[4]; // Size needs to be 4 not 3. You probably forgot to count the null terminator: '\0'
        AlivePlayers -=1; // Decrease the alive players count
        /*
        the '%02d' trick will do what you wanted to do with those if/elseif statements
        i.e. 01, 02, 03, ... 10, 11 ...
        */

        format(alive, sizeof(alive), "%02d", AlivePlayers);
        TextDrawSetString(numberal, alive); // This will update the textdraw for whoever it was shown to, therefore you don't need to keep showing it over and over.
    }
    return 1;
}
Reply
#5

@Khalid

That didn't work, it still doesn't lower it :/
Reply
#6

Please, try this:
PHP код:
public OnPlayerDisconnect(playerid,reason)
{
    
// Login Register system, and leaving messages here!
    // From here is the alive counter!
    
new alive[3];
    if(
pInfo[playerid][DM] > 0)
    {
        
AlivePlayers --;
        if(
AlivePlayers 10)format(alive,sizeof alive,"0%i",AlivePlayers);
        else if(
AlivePlayers 9)format(alive,sizeof alive,"%i",AlivePlayers);
        
TextDrawSetString(numberal,alive);
    }
    return 
1;

Be sure that the textdraws are showing before you disconnected. It can only set the string when it is showing.
Reply
#7

Perhaps your textdraws are bugged, have you tried debugging it?

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new alive[3];
    for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
    {
        printf("I: %i",i);
        if (pInfo[playerid][DM] && pInfo[i][DM] == 1)
        {
            printf("[playerid][DM]: %i || [i][DM]: %i || Alive Players: %i",pInfo[playerid][DM],pInfo[i][DM],AlivePlayers);
            AlivePlayers -= 1;
            printf("AlivePlayers - 1: %i",AlivePlayers);
            format(alive, sizeof(alive), "%02d", AlivePlayers);
            TextDrawSetString(numberal, alive);
            TextDrawShowForPlayer(i, albox1);
            TextDrawShowForPlayer(i, albox2);
            TextDrawShowForPlayer(i, Alive);
            TextDrawShowForPlayer(i, numberal);
        }
    }
    printf("Highest Player ID: %i",j);
    return 1;
}
Post the results please.

Quote:
Originally Posted by MarvinPWN
Посмотреть сообщение
Please, try this:

Be sure that the textdraws are showing before you disconnected. It can only set the string when it is showing.
That's irrelevant, he's changing the TextDraw String for the other player, not the disconnected player.

PS: You don't need to Hide/Show the TextDraw when you set it's text.
Reply
#8

Im sorry for the big delay, i've been abit busy this days
I've done what you sent me @Danice
and here are the results according to the code you gave me:
Код:
[22:47:24] [chat] [Andre]: u want to leave or i do ?
[22:47:42] I: 0
[22:47:42] Highest Player ID: 1
[22:47:42] I: 1
[22:47:42] Highest Player ID: 1
[22:47:42] [part] Jonny has left the server (1:1)
and it still doesn't remove 1 when the player leaves

also it's weird because it didn't print the:
PHP код:
printf("[playerid][DM]: %i || [i][DM]: %i || Alive Players: %i",pInfo[playerid][DM],pInfo[i][DM],AlivePlayers); 
nor
PHP код:
printf("AlivePlayers - 1: %i",AlivePlayers); 
but
PHP код:
printf("I: %i",i);
printf("Highest Player ID: %i",j); 
twice

here is my code:
PHP код:
    new alive[3];
    for(new 
0GetPlayerPoolSize(); <= ji++)
    {
        
printf("I: %i",i);
        if (
pInfo[playerid][DM] && pInfo[i][DM] == 1)
        {
            
printf("[playerid][DM]: %i || [i][DM]: %i || Alive Players: %i",pInfo[playerid][DM],pInfo[i][DM],AlivePlayers);
            
AlivePlayers -= 1;
            
printf("AlivePlayers - 1: %i",AlivePlayers);
            
format(alivesizeof(alive), "%02d"AlivePlayers);
            
TextDrawSetString(numberalalive);
            
TextDrawShowForPlayer(ialbox1);
            
TextDrawShowForPlayer(ialbox2);
            
TextDrawShowForPlayer(iAlive);
            
TextDrawShowForPlayer(inumberal);
        }
        
printf("Highest Player ID: %i",j);
    }
    return 
1;

Reply
#9

Try
AlivePlayers--;
Replace this with it
AlivePlayers-=1;
Reply
#10

Quote:
Originally Posted by Roberto80
Посмотреть сообщение
Try
AlivePlayers--;
Replace this with it
AlivePlayers-=1;
That is exactly the same thing..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)