public OnPlayerDisconnect(playerid, reason)
{
// Login Register system, and leaving messages here!
// From here is the alive counter!
new alive[3];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if (pInfo[playerid][DM] && pInfo[i][DM] == 1)
{
SetPlayerHealth(playerid, 0);
AlivePlayers-=1;
if (AlivePlayers < 10)
{
format(alive, sizeof(alive), "0%i", AlivePlayers);
}
else if (AlivePlayers > 9)
{
format(alive, sizeof(alive), "%i", AlivePlayers);
}
TextDrawSetString(numberal, alive);
TextDrawShowForPlayer(i, albox1);
TextDrawShowForPlayer(i, albox2);
TextDrawShowForPlayer(i, Alive);
TextDrawShowForPlayer(i, numberal);
}
}
return 1;
}
pInfo[playerid][DM] = 0;
pInfo[playerid][DM] && pInfo[i][DM] == 1
I don't really get it but I doubt that you have created
Код:
pInfo[playerid][DM] = 0; 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 Just guessing xd And btw, why you are setting the health of the player to 0 when he disconnects? xD |
pInfo[playerid][DM] = 1;
/*
~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;
}
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;
}
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;
}
Please, try this:
Be sure that the textdraws are showing before you disconnected. It can only set the string when it is showing. |
[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)
printf("[playerid][DM]: %i || [i][DM]: %i || Alive Players: %i",pInfo[playerid][DM],pInfo[i][DM],AlivePlayers);
printf("AlivePlayers - 1: %i",AlivePlayers);
printf("I: %i",i);
printf("Highest Player ID: %i",j);
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;
}