OnPlayerConnect and Disconnect
#1

Hello, I am adding OnPlayerConnect and OnPlayerDisconnect messages, but I have a slight question about the nick formatting. A player will join with an RP nick for example John_Epic and when he connects, it has to say ''John Epic has joined the server'' without the underline. Is it possible? If yes, how?

P.S - Is case 3 under OnPlayerDisconnect correct? Just being curious

Код:
public OnPlayerConnect(playerid)
{
  new pName[24];
  new str[128];
  GetPlayerName(playerid, pName, 24);
  format(str, 128, "%s has joined the server", pName);
  SendClientMessageToAll(COLOR_LIGHTGREEN, str);
  return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
  new pName[24];
  new str[128];
  GetPlayerName(playerid, pName, 24);

  switch(reason)
    {
      case 0: format(str, 128, "%s has left the server. (Timeout)", pName);
      case 1: format(str, 128, "%s has left the server. (Leaving)", pName);
      case 2: format(str, 128, "%s has left the server. (Kicked)", pName);
      case 3: format(str, 128, "%s has left the server. (Banned)", pName);
    }
  SendClientMessageToAll(COLOR_GREY, str);
  return 1;
}
// EDIT: One Error.

Код:
C:\Users\PUZI\Desktop\RP\gamemodes\rp-main.pwn(138) : error 017: undefined symbol "reason"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Thanks and Regards
Puzi
Reply
#2

I think Kicked & Banned is same reason. Try to make case 2: Kicked/Banned

Not sure, but maybe it works...


And the John_Epic to John Epic, i dont know...
Reply
#3

Quote:
Originally Posted by Puzi
Hello, I am adding OnPlayerConnect and OnPlayerDisconnect messages, but I have a slight question about the nick formatting. A player will join with an RP nick for example John_Epic and when he connects, it has to say ''John Epic has joined the server'' without the underline. Is it possible? If yes, how?
pawn Код:
stock PlayerNameEx(playerid) // credits to the creator (i'm not sure who's the original creator).
{
  new
      playername[MAX_PLAYER_NAME];
  strmid(playername, PlayerName(playerid), 0, strlen(PlayerName(playerid)), MAX_PLAYER_NAME);
  for(new i = 0; i < MAX_PLAYER_NAME; i++)
  {
    if(playername[i] == '_') playername[i] = ' ';
  }
  return playername;
}

stock PlayerName(playerid)
{
  new
      playername[MAX_PLAYER_NAME];
  GetPlayerName(playerid, playername, sizeof(playername));
  return playername;
}
Reply
#4

Thanks a lot pal, but how can I fix the error?
Reply
#5

This code compiles just great for me, i don't see a reason why the reason could be undefined + kick and ban reasons are using the same ID, that's 2.
Reply
#6

I've no idea, there are no other errors. Maybe I need to add strtok? Does this have something in common? Anyways, this is mine script:

Код:
public OnPlayerConnect(playerid)
{
  IsLogged[playerid] = 0;
  SendClientMessage(playerid, 0xFFFFFFFF, "Welcome to BETA RP");
  SendClientMessage(playerid, 0xFFFFFFFF, "Type /cmd for a list of commands");
  
  new pName[24];
  new str[128];
  GetPlayerName(playerid, pName, 24);
  format(str, 128, "|| San Andreas Customs Office || %s has joined the server.", pName);
  SendClientMessageToAll(COLOR_LIGHTGREEN, str);
	return 1;
}

public OnPlayerDisconnect(playerid)
{
  IsLogged[playerid] = 0;

  new pName[24];
  new str[128];
  GetPlayerName(playerid, pName, 24);

  switch(reason)
    {
      case 0: format(str, 128, "|| San Andreas Customs Office || %s has left the server. (Timeout)", pName);
      case 1: format(str, 128, "|| San Andreas Customs Office || %s has left the server. (Leaving)", pName);
      case 2: format(str, 128, "|| San Andreas Customs Office || %s has left the server. (Kicked/Banned)", pName);
    }
  SendClientMessageToAll(COLOR_GREY, str);
	return 1;
}
Quote:
Originally Posted by Don Correlli
This code compiles just great for me, i don't see a reason why the reason could be undefined + kick and ban reasons are using the same ID, that's 2.
I have made it correct in the above code... But still get the error.
Reply
#7

Reason "3" not exists.
Use the case 2 for kicks. Ban = kick + IP blacklisted, whatever kick and ban is the same.
Reply
#8

If you look, I have corrected it.

I only have the error left and no one wants to help me
Reply
#9

Can anyone help please? Sorry for double posting, I need this.
Reply
#10

Код:
forward OnPlayerDisconnect(playerid);
Код:
public OnPlayerDisconnect(playerid, reason)
{
  SendDeathMessage(INVALID_PLAYER_ID, playerid, 201);
	new string[128];
	switch (reason)
  	{
  	case 0:
  	{
   		GetPlayerName(playerid, playername, sizeof(playername));
   		format(string,sizeof(string), "*** %s has left the server (Timeout).", playername);
   		SendClientMessageToAll(COLOR_GREY, string);
		}
  		case 1:
  	{
  		GetPlayerName(playerid, playername, sizeof(playername));
   		format(string,sizeof(string), "*** %s has left the server (Leaving).", playername);
   		SendClientMessageToAll(COLOR_GREY, string);

  		}
  		case 2:
  		{
   		GetPlayerName(playerid, playername, sizeof(playername));
   		format(string,sizeof(string), "*** %s has left the server (Kicked).", playername);
   		SendClientMessageToAll(COLOR_GREY, string);
	  }
	}
return 1;
}
This is mine onplayerdisconnect and it works fine
Reply
#11

Код:
C:\Users\PUZI\Desktop\RP\gamemodes\rp-main.pwn(136) : error 017: undefined symbol "reason"
C:\Users\PUZI\Desktop\RP\gamemodes\rp-main.pwn(140) : error 017: undefined symbol "playername"
C:\Users\PUZI\Desktop\RP\gamemodes\rp-main.pwn(140) : error 017: undefined symbol "playername"
C:\Users\PUZI\Desktop\RP\gamemodes\rp-main.pwn(140) : error 029: invalid expression, assumed zero
C:\Users\PUZI\Desktop\RP\gamemodes\rp-main.pwn(140) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


5 Errors.
Reply
#12

Quote:
Originally Posted by Puzi
I have made it correct in the above code... But still get the error.
Change
pawn Код:
public OnPlayerDisconnect(playerid)
to
pawn Код:
public OnPlayerDisconnect(playerid, reason)
Reply
#13

I fixed it myself.
No problem with my script, there was reason missing by playerid on public OnPlayerDisconnect.

Thanks all for help
Reply
#14

Quote:
Originally Posted by Don Correlli
Quote:
Originally Posted by Puzi
Hello, I am adding OnPlayerConnect and OnPlayerDisconnect messages, but I have a slight question about the nick formatting. A player will join with an RP nick for example John_Epic and when he connects, it has to say ''John Epic has joined the server'' without the underline. Is it possible? If yes, how?
pawn Код:
stock PlayerNameEx(playerid) // credits to the creator (i'm not sure who's the original creator).
{
  new
      playername[MAX_PLAYER_NAME];
  strmid(playername, PlayerName(playerid), 0, strlen(PlayerName(playerid)), MAX_PLAYER_NAME);
  for(new i = 0; i < MAX_PLAYER_NAME; i++)
  {
    if(playername[i] == '_') playername[i] = ' ';
  }
  return playername;
}

stock PlayerName(playerid)
{
  new
      playername[MAX_PLAYER_NAME];
  GetPlayerName(playerid, playername, sizeof(playername));
  return playername;
}
Actually, I have tested that, and I still get the underdash (_) when a player connects.
Reply
#15

Quote:
Originally Posted by Puzi
Actually, I have tested that, and I still get the underdash (_) when a player connects.
It works just great for me. You need to use the PlayerNameEx function.
Reply
#16

What is that function?
I tried adding new PlayerNameEx; and new PlayerNameEx[MAX_PLAYERS];

They both come up with quite a few errors and say that PlayerNameEx is already defined, because of the stock.
Reply
#17

Example:
pawn Код:
new
    myArray[48];
format(myArray, sizeof(myArray), "%s connected.", PlayerNameEx(playerid));
SendClientMessage(playerid, 0xFFFFFFAA, myArray);
Reply
#18

Код:
public OnPlayerConnect(playerid)
{
// str defined here

  IsLogged[playerid] = 0;
  SendClientMessage(playerid, 0xFFFFFFFF, "Blablabla...");  

  new
  myArray[48];
  format(myArray, sizeof(myArray), "%s connected.", PlayerNameEx(playerid));
  SendClientMessageToAll(playerid, COLOR_LIGHTGREEN, myArray);
  return 1;
}
Would this be correct then or not really? (I know, I fail...)
Reply
#19

You don't need the playerid param at SendClientMessageToAll function.
Reply
#20

Oh yeah, forgot about that, sorry.

I will test it now, thanks for your help

// EDIT: Thanks a lot, worked.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)