/arrest /cuff problem
#1

I am having little problem with my /arrest and /cuff commands

If i type /cuff 0 (me) it says

You cannot arrest another police officer and same with arrest

And if i type /arrest or /cuff 2 (random id)

It won't say player is not connected so could you help

here is my two commands.
PHP код:
CMD:cuff(playerid,params[])
{
  new 
targetid;
  if(
IsPlayerPolice[playerid] < 1)
  return 
SendClientMessage(playerid, -1"{ff0000}This command only for cops");
  if(
sscanf(params"u"targetid)) return SendClientMessage(playerid, -1"USAGE: /cuff [Part of Name/Player ID]");
  if(
IsPlayerPolice[targetid] >= 1) return  SendClientMessage(playerid, -2,  "{ff0000}You cant arrest another police officer!");
  if(!
IsPlayerConnected(targetid)) return SendClientMessage(playerid0xFFFFFFF,"{ff0000}[ERROR]: This player is not connected!");
  if(
playerid == targetid) return SendClientMessage(playerid0xFF0000FF"ERROR: You can't cuff yourself");
  new 
Float:xFloat:yFloat:z;
  
GetPlayerPos(playeridx,y,z);
  if(
IsPlayerInRangeOfPoint(targetid5.0xyz))
  {
        new 
str[512];
        new 
name[MAX_PLAYER_NAME];
        
GetPlayerName(playeridname,sizeof(name));
        new 
target[MAX_PLAYER_NAME];
        
GetPlayerName(targetidtargetsizeof(target));
        
format(strsizeof(str), "{ff0000}You cuffed %s!",target);
        
SendClientMessage(playerid0xE01B1Bstr);
        
SetPlayerAttachedObject(targetid0194186, -0.0110000.028000, -0.022000, -15.600012, -33.699977,-81.7000350.8919991.0000001.168000);
        
SetPlayerSpecialAction(targetid,SPECIAL_ACTION_CUFFED);
        return 
1;
  }
  return 
1;
}
CMD:ar(playerid,params[]) return cmd_arrest(playeridparams);
CMD:arrest(playerid,params[])
{
 new 
targetidstr[512];
 if(
IsPlayerPolice[playerid] < 1) return SendClientMessage(playerid,-1,"{ff0000}[ERROR]: You are not cop.");
 if(
sscanf(params"u"targetid)) return SendClientMessage(playerid, -1,"USAGE: /arrest [Part of Name/Player ID]");
 if(
IsPlayerPolice[targetid] >= 1) return SendClientMessage(playerid, -2"{ff0000}You cant arrest another police officer!");
 if(!
SetPlayerAttachedObject(targetid0194186, -0.0110000.028000, -0.022000, -15.600012, -33.699977,-81.7000350.8919991.0000001.168000)) return SendClientMessage(playerid,-1,"[ERROR] This player is not cuffed!");
 if(!
IsPlayerConnected(targetid)) return SendClientMessage(playerid0xFFFFFFF,"ERROR: This player is not connected!");
 if(
playerid == targetid) return SendClientMessage(playerid0xFFFFFFF"{ff0000}ERROR: You can't arrest yourself");
 new 
name [MAX_PLAYER_NAME];
 
GetPlayerName(playeridname,sizeof(name));
 new 
target[MAX_PLAYER_NAME];
 
GetPlayerName(targetidtargetsizeof(target));
 
format(strsizeof(str), "{ff0000}You have arrested %s",target);
 
SendClientMessage(playerid0xE01B1Bstr);
 
GameTextForPlayer(playerid"ARRESTED",5000,2);
 
SendClientMessageToAll(-1"%s Has been sent to jail");
 
SetPlayerInterior(playerid6);
 
ResetPlayerWeapons(playerid);
 return 
1;

Reply
#2

Код:
CMD:cuff(playerid,params[]) 
{ 
  new targetid;
  if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "USAGE: /cuff [Part of Name/Player ID]"); 
  if(IsPlayerPolice[playerid] < 1) 
  return SendClientMessage(playerid, -1, "{ff0000}This command only for cops"); 
  if(IsPlayerPolice[targetid] > 0) return  SendClientMessage(playerid, -2,  "{ff0000}You cant arrest another police officer!"); 
  if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, 0xFFFFFFF,"{ff0000}[ERROR]: This player is not connected!"); 
  if(playerid == targetid) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You can't cuff yourself"); 

  new Float:x, Float:y, Float:z; 
  GetPlayerPos(playerid, x,y,z); 
  if(IsPlayerInRangeOfPoint(targetid, 5.0, x, y, z)) 
  { 
        new str[512]; 
        new name[MAX_PLAYER_NAME]; 
        GetPlayerName(playerid, name,sizeof(name)); 
        new target[MAX_PLAYER_NAME]; 
        GetPlayerName(targetid, target, sizeof(target)); 
        format(str, sizeof(str), "{ff0000}You cuffed %s!",target); 
        SendClientMessage(playerid, 0xE01B1B, str); 
        SetPlayerAttachedObject(targetid, 0, 19418, 6, -0.011000, 0.028000, -0.022000, -15.600012, -33.699977,-81.700035, 0.891999, 1.000000, 1.168000); 
        SetPlayerSpecialAction(targetid,SPECIAL_ACTION_CUFFED); 
        return 1; 

  } 
  return 1; 
} 

CMD:ar(playerid,params[]) 
{
	return cmd_arrest(playerid, params); 
}

CMD:arrest(playerid,params[]) 
{ 
 new targetid, str[512]; 
 if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1,"USAGE: /arrest [Part of Name/Player ID]"); 
 if(IsPlayerPolice[playerid] < 1) return SendClientMessage(playerid,-1,"{ff0000}[ERROR]: You are not cop."); 
 if(IsPlayerPolice[targetid] > 0) return SendClientMessage(playerid, -2, "{ff0000}You cant arrest another police officer!"); 
 if(!SetPlayerAttachedObject(targetid, 0, 19418, 6, -0.011000, 0.028000, -0.022000, -15.600012, -33.699977,-81.700035, 0.891999, 1.000000, 1.168000)) return SendClientMessage(playerid,-1,"[ERROR] This player is not cuffed!"); 
 if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, 0xFFFFFFF,"ERROR: This player is not connected!"); 
 if(playerid == targetid) return SendClientMessage(playerid, 0xFFFFFFF, "{ff0000}ERROR: You can't arrest yourself"); 
 new name [MAX_PLAYER_NAME]; 
 GetPlayerName(playerid, name,sizeof(name)); 
 new target[MAX_PLAYER_NAME]; 
 GetPlayerName(targetid, target, sizeof(target)); 
 format(str, sizeof(str), "{ff0000}You have arrested %s",target); 
 SendClientMessage(playerid, 0xE01B1B, str); 
 GameTextForPlayer(playerid, "ARRESTED",5000,2); 
 SendClientMessageToAll(-1, "%s Has been sent to jail"); 
 SetPlayerInterior(playerid, 6); 
 ResetPlayerWeapons(playerid); 
 return 1; 
}
Reply
#3

same :\
Reply
#4

try this

pawn Код:
CMD:cuff(playerid,params[])
{
  new targetid;
  if(IsPlayerPolice[playerid] < 1)
  return SendClientMessage(playerid, -1, "{ff0000}This command only for cops");
  if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "USAGE: /cuff [Part of Name/Player ID]");
  if(IsPlayerPolice[targetid] >= 1) return  SendClientMessage(playerid, -2,  "{ff0000}You cant arrest another police officer!");
  if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFFFFFFF,"{ff0000}[ERROR]: This player is not connected!");
  if(playerid == targetid) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You can't cuff yourself");

  new Float:x, Float:y, Float:z;
  GetPlayerPos(playerid, x,y,z);
  if(IsPlayerInRangeOfPoint(targetid, 5.0, x, y, z))
  {
        new str[512];
        new name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name,sizeof(name));
        new target[MAX_PLAYER_NAME];
        GetPlayerName(targetid, target, sizeof(target));
        format(str, sizeof(str), "{ff0000}You cuffed %s!",target);
        SendClientMessage(playerid, 0xE01B1B, str);
        SetPlayerAttachedObject(targetid, 0, 19418, 6, -0.011000, 0.028000, -0.022000, -15.600012, -33.699977,-81.700035, 0.891999, 1.000000, 1.168000);
        SetPlayerSpecialAction(targetid,SPECIAL_ACTION_CUFFED);
        return 1;

  }
  return 1;
}
CMD:ar(playerid,params[]) return cmd_arrest(playerid, params);
CMD:arrest(playerid,params[])
{
 new targetid, str[512];
 if(IsPlayerPolice[playerid] < 1) return SendClientMessage(playerid,-1,"{ff0000}[ERROR]: You are not cop.");
 if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1,"USAGE: /arrest [Part of Name/Player ID]");
 if(IsPlayerPolice[targetid] >= 1) return SendClientMessage(playerid, -2, "{ff0000}You cant arrest another police officer!");
 if(!SetPlayerAttachedObject(targetid, 0, 19418, 6, -0.011000, 0.028000, -0.022000, -15.600012, -33.699977,-81.700035, 0.891999, 1.000000, 1.168000)) return SendClientMessage(playerid,-1,"[ERROR] This player is not cuffed!");
 if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFFFFFFF,"ERROR: This player is not connected!");
 if(playerid == targetid) return SendClientMessage(playerid, 0xFFFFFFF, "{ff0000}ERROR: You can't arrest yourself");
 new name [MAX_PLAYER_NAME];
 GetPlayerName(playerid, name,sizeof(name));
 new target[MAX_PLAYER_NAME];
 GetPlayerName(targetid, target, sizeof(target));
 format(str, sizeof(str), "{ff0000}You have arrested %s",target);
 SendClientMessage(playerid, 0xE01B1B, str);
 GameTextForPlayer(playerid, "ARRESTED",5000,2);
 SendClientMessageToAll(-1, "%s Has been sent to jail");
 SetPlayerInterior(playerid, 6);
 ResetPlayerWeapons(playerid);
 return 1;
}
Reply
#5

same.
Reply
#6

which sa-mp version you using?
Reply
#7

0.3z
Reply
#8

that's because it does it in order of the code
pawn Код:
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "USAGE: /cuff [Part of Name/Player ID]"); //gets targetid
  if(IsPlayerPolice[targetid] >= 1) return  SendClientMessage(playerid, -2,  "{ff0000}You cant arrest another police officer!"); //since you're a police this is triggered
  if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, 0xFFFFFFF,"{ff0000}[ERROR]: This player is not connected!");
  if(playerid == targetid) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You can't cuff yourself");
so either move the playerid == targetid up or add an exception in the first (&& playerid != targetid)
Reply
#9

U should replace all "<" or ">" with "=="

ex:
IsPlayerPolice[playerid] < 1 to IsPlayerPolice[playerid] ==1

IsPlayerPolice[playerid] >= 1 to IsPlayerPolice[playerid] != 1

hope u got it.
Reply
#10

Quote:
Originally Posted by cessil
Посмотреть сообщение
that's because it does it in order of the code
pawn Код:
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "USAGE: /cuff [Part of Name/Player ID]"); //gets targetid
  if(IsPlayerPolice[targetid] >= 1) return  SendClientMessage(playerid, -2,  "{ff0000}You cant arrest another police officer!"); //since you're a police this is triggered
  if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, 0xFFFFFFF,"{ff0000}[ERROR]: This player is not connected!");
  if(playerid == targetid) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You can't cuff yourself");
so either move the playerid == targetid up or add an exception in the first (&& playerid != targetid)
hmm.. then follow cessil codes in my codes. Just change the order.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)