When a player disconnects... -
Zh3r0 - 02.04.2010
When a player disconnects,, sometimes, instead of saying that guys name says another's...
If i disconnect to others appears that someone else disconnected.
Here is the code i have at OnPlayerDisconnect.
pawn Код:
public OnPlayerDisconnect(playerid,reason)
{
new string[128];
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
switch(reason)
{
case 0: format(string, sizeof(string), "~w~%s ~b~has ~y~joined ~b~the server~w~ (~r~TIME-OUT~W~)",GetPlayerNameEx(i));
case 1: format(string, sizeof(string), "~w~%s ~b~has ~y~joined ~b~the server~w~ (~r~LEAVING~W~)",GetPlayerNameEx(i));
case 2: format(string, sizeof(string), "~w~%s ~b~has ~y~joined ~b~the server~w~ (~r~KICK~w~/~r~BAN~W~)",GetPlayerNameEx(i));
}
TextDrawSetString(Connect,string);
TextDrawShowForAll(Text:Connect);
SetTimer("SendConnectMessageStop",6000,0);
}
}
return 1;
}
Here's the GetPlayerNameEx if needed:
pawn Код:
GetPlayerNameEx(playerid)
{
new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid,PlayerName,MAX_PLAYER_NAME);
for(new i=0; i <strlen(PlayerName); i++)
{
if(PlayerName[i]==']'){PlayerName[i]=')';}
if(PlayerName[i]=='['){PlayerName[i]='(';}
if(PlayerName[i]=='*'){PlayerName[i]=']';}
}
return PlayerName;
}
Help would be very appreciated.
Re: When a player disconnects... -
Ragidon - 02.04.2010
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
new pname[MAX_PLAYER_NAME], string[39 + MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
switch(reason)
{
case 0: format(string, sizeof(string), "%s has left the server. (Lost Connection)", pname);
case 1: format(string, sizeof(string), "%s has left the server. (Leaving)", pname);
case 2: format(string, sizeof(string), "%s has left the server. (Kicked)", pname);
}
SendClientMessageToAll(0xAAAAAAAA, string);
return 1;
}
That actually works to me...
Re: When a player disconnects... -
ZeRo_HUN - 02.04.2010
You must get that player's name, who disconnects( without iteration ).
pawn Код:
public OnPlayerDisconnect(playerid,reason)
{
new string[ 128 ];
switch( reason ) {
case 0 : format( string, sizeof string, "~w~%s ~b~has ~y~joined ~b~the server~w~ (~r~TIME-OUT~W~)", GetPlayerNameEx( playerid ) );
case 1 : format( string, sizeof string, "~w~%s ~b~has ~y~joined ~b~the server~w~ (~r~LEAVING~W~)", GetPlayerNameEx( playerid ) );
case 2 : format( string, sizeof string, "~w~%s ~b~has ~y~joined ~b~the server~w~ (~r~KICK~w~/~r~BAN~W~)", GetPlayerNameEx( playerid ) );
TextDrawSetString( Connect, string );
TextDrawShowForAll( Text:Connect );
SetTimer( "SendConnectMessageStop", 6000, 0 );
}
return 1;
}
E: Ragidon was faster..
Re: When a player disconnects... -
Zh3r0 - 02.04.2010
Quote:
Originally Posted by Ragidon
pawn Код:
public OnPlayerDisconnect(playerid, reason) { new pname[MAX_PLAYER_NAME], string[39 + MAX_PLAYER_NAME]; GetPlayerName(playerid, pname, sizeof(pname)); switch(reason) { case 0: format(string, sizeof(string), "%s has left the server. (Lost Connection)", pname); case 1: format(string, sizeof(string), "%s has left the server. (Leaving)", pname); case 2: format(string, sizeof(string), "%s has left the server. (Kicked)", pname); } SendClientMessageToAll(0xAAAAAAAA, string); return 1; }
That actually works to me...
|
Well i'm using textdraws, does it matters?
I will try both, thanks guys
Edit://I don't need the IsPlayerConnected thingy , do i?
Re: When a player disconnects... -
Carlton - 02.04.2010
Quote:
Originally Posted by ZeRo_HUN
You must get that player's name, who disconnects( without iteration ).
pawn Код:
public OnPlayerDisconnect(playerid,reason) { new string[ 128 ]; switch( reason ) { case 0 : format( string, sizeof string, "~w~%s ~b~has ~y~joined ~b~the server~w~ (~r~TIME-OUT~W~)", GetPlayerNameEx( playerid ) ); case 1 : format( string, sizeof string, "~w~%s ~b~has ~y~joined ~b~the server~w~ (~r~LEAVING~W~)", GetPlayerNameEx( playerid ) ); case 2 : format( string, sizeof string, "~w~%s ~b~has ~y~joined ~b~the server~w~ (~r~KICK~w~/~r~BAN~W~)", GetPlayerNameEx( playerid ) ); TextDrawSetString( Connect, string ); TextDrawShowForAll( Text:Connect ); SetTimer( "SendConnectMessageStop", 6000, 0 ); } return 1; }
E: Ragidon was faster.. 
|
You're wrong, you can't put functions in switch.
Re: When a player disconnects... -
Ragidon - 02.04.2010
Quote:
Originally Posted by PlayON
Quote:
Originally Posted by Ragidon
pawn Код:
public OnPlayerDisconnect(playerid, reason) { new pname[MAX_PLAYER_NAME], string[39 + MAX_PLAYER_NAME]; GetPlayerName(playerid, pname, sizeof(pname)); switch(reason) { case 0: format(string, sizeof(string), "%s has left the server. (Lost Connection)", pname); case 1: format(string, sizeof(string), "%s has left the server. (Leaving)", pname); case 2: format(string, sizeof(string), "%s has left the server. (Kicked)", pname); } SendClientMessageToAll(0xAAAAAAAA, string); return 1; }
That actually works to me...
|
Well i'm using textdraws, does it matters?
I will try both, thanks guys
Edit://I don't need the IsPlayerConnected thingy , do i?
|
Nope. You donґt need to have an IsPlayerConnect. Using textdraws doesn't matter.
Re: When a player disconnects... -
Zh3r0 - 02.04.2010
Quote:
Originally Posted by Ragidon
Quote:
Originally Posted by PlayON
Quote:
Originally Posted by Ragidon
pawn Код:
public OnPlayerDisconnect(playerid, reason) { new pname[MAX_PLAYER_NAME], string[39 + MAX_PLAYER_NAME]; GetPlayerName(playerid, pname, sizeof(pname)); switch(reason) { case 0: format(string, sizeof(string), "%s has left the server. (Lost Connection)", pname); case 1: format(string, sizeof(string), "%s has left the server. (Leaving)", pname); case 2: format(string, sizeof(string), "%s has left the server. (Kicked)", pname); } SendClientMessageToAll(0xAAAAAAAA, string); return 1; }
That actually works to me...
|
Well i'm using textdraws, does it matters?
I will try both, thanks guys
Edit://I don't need the IsPlayerConnected thingy , do i?
|
Nope. You donґt need to have an IsPlayerConnect. Using textdraws doesn't matter.
|
One more thing, may you exaplin to what exaclt the IsPlayerConnected does?
I know it checks if the player is connected but more detailed?

Thanks fo such a fast answer.
Re: When a player disconnects... -
Ragidon - 02.04.2010
https://sampwiki.blast.hk/wiki/IsPlayerConnected
It's all it does. It checks if it the player is connected. If it isn't, most people use an "else" to send a message when the player isn't connected. It's mostly used in PM's and such.
Re: When a player disconnects... -
Zh3r0 - 02.04.2010
Quote:
Originally Posted by Ragidon
|
So i guess it's not needed on a disconnect,.
Re: When a player disconnects... -
Ragidon - 02.04.2010
Quote:
Originally Posted by PlayON
Quote:
Originally Posted by Ragidon
|
So i guess it's not needed on a disconnect,.
|
Not really no...