pm command with id o
#1

Ok, when i type /pm 0 [text] it says 65535 is not an active player but when i do other ids it works fine, I have to use part of name to send a pm to id 0, What could be causing this

pawn Код:
if(strcmp(cmd, "/pm", true) == 0 || strcmp(cmd, "/p", true) == 0)
{
if(IsPlayerConnected(playerid))
     {
        if(gPlayerLogged[playerid] == 0)
        {
          SendClientMessage(playerid, COLOR_GREY, "  You havent logged in yet!");
          return 1;
           }
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "USAGE: (/p)m [playerid/PartOfName] [text]");
                return 1;
            }
            giveplayerid = GetPlayerID(tmp);
            if (IsPlayerConnected(giveplayerid))
            {
              if(giveplayerid != INVALID_PLAYER_ID)
              {
                if(HidePM[giveplayerid] > 1)
                {
                  SendClientMessage(playerid, COLOR_GREY, "  That player is blocking messages!");
                  return 1;
                }
                    GetPlayerName(playerid, sendername, sizeof(sendername));
                    GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                    if(giveplayerid == playerid)
                    {
                        return SendClientMessage(playerid, COLOR_GREY, "  You can`t send private message to yourself.");
                    }
                    new length = strlen(cmdtext);
                    while ((idx < length) && (cmdtext[idx] <= ' '))
                    {
                        idx++;
                    }
                    new offset = idx;
                    new result[64];
                    while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
                    {
                        result[idx - offset] = cmdtext[idx];
                        idx++;
                    }
                    result[idx - offset] = EOS;
                    if(!strlen(result))
                    {
                        SendClientMessage(playerid, COLOR_GRAD2, "USAGE: (/p)m [playerid/PartOfName] [text]");
                        return 1;
                    }
                    /*new namestring = strfind(result, ":", true);
                    if(namestring != -1)
                    {
                      new pmsplit[4][256];
                      new str[256];
                      for(new l=0;l<256;l++) str[l]=result[l];
                        split((str), pmsplit, '.');
                        if(strval(pmsplit[1]) != 0 && strval(pmsplit[2]) != 0)
                        {
                          new year, month,day;
                            getdate(year, month, day);
                            format(string, sizeof(string), "AdmCmd: %s was kicked, reason: Server advert in PM(%d-%d-%d)", giveplayer, sendername, (result),day,month,year);
                            KickLog(string);
                            SendClientMessageToAll(COLOR_LIGHTRED, string);
                            Kick(playerid);
                            return 1;
                        }
                    }*/

                    CheckPM(playerid,(result));
                    format(string, sizeof(string), "[ID:%d] %s pm: %s", playerid, sendername, (result));
                    SendClientMessage(giveplayerid, 0xBBA033AA, string);
                    format(string, sizeof(string), "PM sent to [ID:%d]%s: %s", giveplayerid, giveplayer, (result));
                    SendClientMessage(playerid, 0xE5C43EAA, string);
                    format(string, sizeof(string), ">>PM from [%d]%s to [%d]%s: %s", playerid,sendername,giveplayerid, giveplayer, (result));
                    PMLog(string);
                    for(new z=0;z<MAX_PLAYERS;z++)
                if (BigEar[z])
                SendClientMessage(z, 0x1ED5C7FF, string);
                    return 1;
                }
            }
            else
            {
                    format(string, sizeof(string), "  %d is not an active player.", giveplayerid);
                    SendClientMessage(playerid, COLOR_GRAD1, string);
            }
        }
        return 1;
    }
Reply
#2

I am new at scripting so I'm not sure if this works,

try:
Код:
if(strcmp(cmd, "/pm", true) == 0 || strcmp(cmd, "/p", true) == 0)
{
if(IsPlayerConnected(playerid))
	 {
	    if(gPlayerLogged[playerid] == -1)
	    {
	      SendClientMessage(playerid, COLOR_GREY, "  You havent logged in yet!");
	      return 1;
	       }
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: (/p)m [playerid/PartOfName] [text]");
				return 1;
			}
			giveplayerid = GetPlayerID(tmp);
			if (IsPlayerConnected(giveplayerid))
			{
			  if(giveplayerid != INVALID_PLAYER_ID)
			  {
			    if(HidePM[giveplayerid] > 1)
			    {
			      SendClientMessage(playerid, COLOR_GREY, "  That player is blocking messages!");
			      return 1;
			    }
					GetPlayerName(playerid, sendername, sizeof(sendername));
					GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
					if(giveplayerid == playerid)
					{
						return SendClientMessage(playerid, COLOR_GREY, "  You can`t send private message to yourself.");
					}
					new length = strlen(cmdtext);
					while ((idx < length) && (cmdtext[idx] <= ' '))
					{
						idx++;
					}
					new offset = idx;
					new result[64];
					while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
					{
						result[idx - offset] = cmdtext[idx];
						idx++;
					}
					result[idx - offset] = EOS;
					if(!strlen(result))
					{
						SendClientMessage(playerid, COLOR_GRAD2, "USAGE: (/p)m [playerid/PartOfName] [text]");
						return 1;
					}
					/*new namestring = strfind(result, ":", true);
				 	if(namestring != -1)
					{
					  new pmsplit[4][256];
					  new str[256];
					  for(new l=0;l<256;l++) str[l]=result[l];
						split((str), pmsplit, '.');
						if(strval(pmsplit[1]) != 0 && strval(pmsplit[2]) != 0)
						{
						  new year, month,day;
							getdate(year, month, day);
							format(string, sizeof(string), "AdmCmd: %s was kicked, reason: Server advert in PM(%d-%d-%d)", giveplayer, sendername, (result),day,month,year);
							KickLog(string);
							SendClientMessageToAll(COLOR_LIGHTRED, string);
							Kick(playerid);
							return 1;
						}
					}*/
					CheckPM(playerid,(result));
					format(string, sizeof(string), "[ID:%d] %s pm: %s", playerid, sendername, (result));
					SendClientMessage(giveplayerid, 0xBBA033AA, string);
					format(string, sizeof(string), "PM sent to [ID:%d]%s: %s", giveplayerid, giveplayer, (result));
					SendClientMessage(playerid, 0xE5C43EAA, string);
					format(string, sizeof(string), ">>PM from [%d]%s to [%d]%s: %s", playerid,sendername,giveplayerid, giveplayer, (result));
					PMLog(string);
					for(new z=0;z<MAX_PLAYERS;z++)
	  			if (BigEar[z])
	    		SendClientMessage(z, 0x1ED5C7FF, string);
					return 1;
				}
			}
			else
			{
					format(string, sizeof(string), "  %d is not an active player.", giveplayerid);
					SendClientMessage(playerid, COLOR_GRAD1, string);
			}
		}
		return 1;
	}
I changed this line:
if(gPlayerLogged[playerid] == 0)

Now it is if(gPlayerLogged[playerid] == -1)
I don't think it will work. But just give it a try
Reply
#3

No its nothing to do with that. It seems to be something to do with tmp being "0" and GetPlayerID.
A quick fix would be to do
giveplayerid = (strval(tmp)==0) ? 0 : GetPlayerID(tmp);

Although it would be better to figure out why that is happening, haven't used this that much.
Reply
#4

ok well, I just tried :P
Reply
#5

No harm in trying. Initially I thought it might have been something to do with that.
Then i took a look in notepad++ and realized that the brackets for his printouts were within that if statement.
Reply
#6

Quote:
Originally Posted by mansonh
No its nothing to do with that. It seems to be something to do with tmp being "0" and GetPlayerID.
A quick fix would be to do
giveplayerid = (strval(tmp)==0) ? 0 : GetPlayerID(tmp);

Although it would be better to figure out why that is happening, haven't used this that much.
this seems to be working, When i did /pm 0 it said i can't send messages to myself, I was id 0 so that means it should be working, I will find truly if its working when i get someone on the server, Thank you for the help.

I tried figured out why it was happing i couldn't figure out why. thanks again
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)