Detecting a Timeout/Crash
#1

When I want to show the message of the reason he disconnected by that's alright but I want to do something like this and it doesn't work.

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    if(reason == 0) // Timeout/Crash
    {
        myVar = 1;
    }
    return 1;
}
Does it work like that? I've went on the wiki and it didn't state anything about this.

Cheers.
Reply
#2

Well, assuming it's a global variable, it should work.
Reply
#3

------
Reply
#4

It should work too, would you elaborate more and tell me what you're trying to do?

Edit: I got to go to bed, you take too long to respond..
Reply
#5

I'd recommend using a switch
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    switch(reason)
    {
        case 0: // Timeout / Crashed
        case 1: // Left
        case 2: // Kicked / Banned
    }
    return 1;
}
This example will return the correct values.
Reply
#6

Figured it out, thanks.
Reply
#7

What part of this page doesn't explain 'disconnect reasons'?

https://sampwiki.blast.hk/wiki/OnPlayerDisconnect

It clearly states what each reason stands for...
Reply
#8

Quote:
Originally Posted by Threshold
Посмотреть сообщение
What part of this page doesn't explain 'disconnect reasons'?

https://sampwiki.blast.hk/wiki/OnPlayerDisconnect

It clearly states what each reason stands for...
He said that he wanted to know if resetting/setting a variable under OnPlayerDisconnect would work, and the title of his topic says something else... Could you use a proper title for your topic next time? Thanks. You got us a bit confused here, therefore we responded regarding to the exact same thing "Detecting a Timeout/Crash" (for me, at first).
Reply
#9

new string[250];
switch(reason){
case 0: format(string,sizeof(string),"*Player %s(id:%d) has left the server [Leaving]",GetName(playerid),playerid);
case 1: format(string,sizeof(string),"*Player %s(id:%d) has left the server [Timeout]",GetName(playerid),playerid);
case 2: format(string,sizeof(string),"*Player %s(id:%d) has left the server [Kicked/Banned]",GetName(playerid),playerid);}
SendClientMessageToAll(0x696969AA,string);

stock GetName(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,MAX_PLAYER_NAME);
return name;
}
Reply
#10

Logically, changing variables works anywhere as long as it's within their scope.
Also, always use switch case statements over if statements when you can, as they have a shorter run time.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)