help with invalid id
#1

i have admin command /slap it all works fine, no errors/warnings but you can do '/slap 4' it works but if you type '/slap aaron' or '/slap awrhsetjnsrnmrdykrukm' it always slaps id 0.. why? please can sum one help me! may admin is get angry beacuse i cant fix this!
here is example of my code:
pawn Код:
dcmd_Slap(playerid,params[])
{
   if(PlayerData[playerid][AdminLevel] >= 4) //need be level 4 to slap
  {
  new tmp[256],idx;
  tmp = strtok(params,idx);
  new pid = strval(tmp);
  if(!strlen(tmp))
  {
    SendClientMessage(playerid, COLOR_GREY, "USAGE: /Slap [playersidnumber]");
    return true;
  }
  if(IsPlayerConnected(pid))
  {
    new Float:posX, Float:posY, Float:posZ, Float:health;
    new pname[MAX_PLAYER_NAME], pname2[MAX_PLAYER_NAME], string[256];
    GetPlayerName(pid,pname,sizeof(pname));
    GetPlayerName(playerid,pname2,sizeof(pname2));
    GetPlayerPos(pid, posX, posY, posZ);
    SetPlayerPos(pid, posX, posY, posZ+10);
    SetCameraBehindPlayer(pid);
    format(string,sizeof(string),"player %s has got slapped in the face by a admin called %s!",pname,pname2);
    SendClientMessageToAll(COLOR_RED, string);
    return true;
  }
  else return SendClientMessage(playerid, COLOR_YELLOW, "that not a valid id");
  }
  else return SendClientMessage(playerid,COLOR_YELLOW,"only level 2 admin use this!");
}
So if anyone can know what to help thanks!
Reply
#2

User ReturnUser.
new pid = strval(tmp) means you can use numbers only, you can't use a name if you want to slap someone, that's why I recommend ReturnUser.
Reply
#3

The name/id thing isn't built in, you either need to use ReturnUser (cough) or SSCANF function "u" (millions of times more reliable). It is also important to note that things like /slap k4hj34jk4h344nbj,4hg23jk4b often break strtok, because it fails.

ReturnUser (link)

SSCANF (link)
Reply
#4

um.. please a bit of help i have like
pawn Код:
dcmd_Slap(playerid,params[])
{
   if(PlayerData[playerid][AdminLevel] >= 2)
  {
  new tmp[256],idx;
  tmp = strtok(params,idx);
  new pid = strval(tmp);
  new id;
  new reason[64];
  if(!strlen(tmp))

    if (sscanf(params, "uz", id, reason)) SendClientMessage(playerid, COLOR_GREY, "use: /Slap [Player id number]");


    new Float:posX, Float:posY, Float:posZ;
    new pname[MAX_PLAYER_NAME], pname2[MAX_PLAYER_NAME], string[256];
    GetPlayerName(pid,pname,sizeof(pname));
    GetPlayerName(playerid,pname2,sizeof(pname2));
    GetPlayerPos(pid, posX, posY, posZ);
    SetPlayerPos(pid, posX, posY, posZ+5);
    SetCameraBehindPlayer(pid);
    format(string,sizeof(string),"%s got slapped in the face by %s!",pname,pname2);
    SendClientMessageToAll(COLOR_GREEN, string);
}
  else if (playerid == INVALID_PLAYER_ID)SendClientMessage(playerid, COLOR_YELLOW, "not online player");

  else
  {
    SendClientMessage(playerid,COLOR_YELLOW,"not admin level 4");
}
return 1;
}
That being my only try without errors

Yeah, Im stupid (SSCANF)
Reply
#5

You don't want strtok AND sscanf, you only want sscanf! Let me fix it up for you! Will take a min or too, I'll pm you it incase you don't check back...

pawn Код:
dcmd_slap(playerid,params[])
{
    if(PlayerData[playerid][AdminLevel] < 2)
      {
      SendClientMessage(playerid,COLOR_YELLOW,"Not admin level 4");
      return 1;
      }
    new
      pid,
    if (sscanf(params, "u", pid))
        {
        SendClientMessage(playerid, COLOR_YELLOW, "use: /Slap [Player id number]");
        return 1;
        }
    if (IsPlayerConnected(pid) == 0)
      {
      SendClientMessage(playerid, COLOR_YELLOW, "Not online player");
      return 1;
      }
    else
      {
      new
            Float:posX,
            Float:posY,
            Float:posZ,
            name[MAX_PLAYER_NAME],
            pname2[MAX_PLAYER_NAME],
            string[128];
        GetPlayerName(pid,name,sizeof(name));
        GetPlayerName(playerid,pname2,sizeof(pname2));
        GetPlayerPos(pid, posX, posY, posZ);
        SetPlayerPos(pid, posX, posY, posZ+5);
        SetCameraBehindPlayer(pid);
        format(string,sizeof(string),"%s got slapped in the face by %s!",name,pname2);
        SendClientMessageToAll(COLOR_YELLOW, string);
        return 1;
        }
}
I've compiled it now, but I changed all your colors to COLOR_YELLOW< you'll want to change these back again probably.. I can't guarantee it'll work, but hey it compiles!

P.S I took out the reason bit, because you haven't used it yet, if you want it back i'll put it there...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)