When a player disconnects...
#1

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.

Reply
#2

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...
Reply
#3

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..
Reply
#4

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?
Reply
#5

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.
Reply
#6

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.
Reply
#7

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.
Reply
#8

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.
Reply
#9

Quote:
Originally Posted by Ragidon
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.
So i guess it's not needed on a disconnect,.
Reply
#10

Quote:
Originally Posted by PlayON
Quote:
Originally Posted by Ragidon
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.
So i guess it's not needed on a disconnect,.
Not really no...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)