SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Scripting Help (https://forum.sa-mp.com/forumdisplay.php?f=12)
-   -   unjail only for ID 0 problem. (https://forum.sa-mp.com/showthread.php?t=348279)

MarkoN 04/06/2012 09:02 PM

unjail only for ID 0 problem.
 
pawn Code:
if(!strcmp(cmdtext, "/jail", true, 5))
{
  if(Admin[playerid] >= 1 )
  {
  SendClientMessage(playerid, COLOR_RED, "WARNING : AFTER JAILING A PLAYER UNJAIL HIM AFTER 2 MIN");
  if(!strlen(cmdtext[6]))
  {
    SendClientMessage(playerid, COLOR_RED, "Usage /jail [playerid]");
    return 1;
  }
  new ID = strval(cmdtext[6]);
  new strv[170];
  if(IsPlayerConnected(ID))
  {

    format(strv, 170, "You have been jailed");
    SendClientMessage(ID,COLOR_ORANGE, strv);
    SetPlayerPos(ID, 264.8763,78.9862,1001.0390);
    SetPlayerInterior(ID, 6);
  }
  }
  else
  {
    SendClientMessage(playerid,COLOR_RED,"You are not an admin!");
  }
  return 1;

}
    if(!strcmp(cmdtext, "/unjail", true, 7))
{
  if(Admin[playerid] >= 1 )
  {
  if(!strlen(cmdtext[8]))
  {
    SendClientMessage(playerid, COLOR_RED, "Usage : /unjail [playerid]");
    return 1;
  }
  new ID = strval(cmdtext[8]);
  new strv[171];
  if(IsPlayerConnected(ID))
  {

    format(strv, 171, "You have been Unjailed");
    SendClientMessage(ID,COLOR_ORANGE, strv);
    SetPlayerPos(ID, 1553.4637,-1675.6656,16.1953);
    SetPlayerInterior(ID, 0);
  }
  }
  else
  {
    SendClientMessage(playerid,COLOR_RED,"You are not an admin!");
  }
  return 1;

}

Jail works just fine, but /unjail only works for ID 0 .

Sandiel 04/06/2012 09:36 PM

Re: unjail only for ID 0 problem.
 
For this you will be needing ZCMD, and sscanf. ZCMD is far more better than strcmp, seriously.
pawn Code:
COMMAND:unjail(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 1)
    {
        new targetid;
        if(!sscanf(params, "u", targetid))
        {
            if(IsPlayerConnected(targetid))
            {
                if(IsPlayerInRangeOfPoint(targetid, 3, jailX, jailY, jailZ))
                {
                    SetPlayerPos(targetid, somewhereX, somewhereY, somewhereZ);
                    new pName[MAX_PLAYER_NAME], aName[MAX_PLAYER_NAME], str[128];
                    GetPlayerName(playerid, aName, sizeof(aName));
                    GetPlayerName(targetid, pName, sizeof(pName));
                    format(str, sizeof(str), "AdmCmd: %s has been released by %s from his jail time", pName, aName);
                    SendClientMessageToAll(COLOR_RED, str);
                }
            }
        }
    }
    return 1;
}

park4bmx 04/06/2012 09:39 PM

Re: unjail only for ID 0 problem.
 
All characters from a string count !
pawn Code:
if(!strlen(cmdtext[7))
Try that instead of 8
reason
Becouse you have selected the string after the 8 character it leave you with nothing!
So it retrieves it as ID 0
Becouse 0 = nothing


All times are GMT. The time now is 01:10 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.