Cuff Command
#1

Im not sure if Im tripping or not. I've made a cuff command but somehow its reverted. Civilians can use it and police/army can't use it. Its quiet confusing since I used the same method for spawns and there it is working.


These are my basic defines:

Код:
new allTeams[MAX_PLAYERS];

#define TEAM_CIV 1
#define TEAM_POLICE 2
#define TEAM_SWAT 3
#define TEAM_ARMY 4
#define TEAM_MEDIC 5
#define TEAM_FF 6
#define TEAM_MAFIA 7
#define TEAM_YAKUZA 8
Код:
CMD:cuff(playerid, params[])
{	
	if(allTeams[playerid] == TEAM_POLICE) return SendClientMessage(playerid,COLOR_RED, "ERROR: You need to be a police officer or a army member!");
	if(allTeams[playerid] == TEAM_ARMY)	return SendClientMessage(playerid,COLOR_RED, "ERROR: You need to be a police officer or a army member!");
	{	
    new targetid;
    if(sscanf(params, "u", targetid)) return SendClientMessage(playerid,COLOR_RED, "ERROR: /cuff [Part of Name/Player ID]!");
    else if(targetid==playerid) return SendClientMessage(playerid,COLOR_RED, "ERROR: You can not use that on yourself!");
    else if(targetid==TEAM_ARMY) return SendClientMessage(playerid,COLOR_RED, "ERROR: You can not cuff members of the army!");
    else if(targetid==TEAM_POLICE) return SendClientMessage(playerid,COLOR_RED, "ERROR: You can not cuff police officers!");
    else if(targetid==INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOR_RED, "ERROR: Invalid ID/Name or Player is not connected!");
    else if(IsPlayerInAnyVehicle(targetid)) return SendClientMessage(playerid,COLOR_RED,"ERROR: You can not cuff someone who is in a vehicle!");
    if(IsPlayerConnected(targetid)) return SendClientMessage(playerid,COLOR_RED, "ERROR: Player is not connected!");
    {
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        if(IsPlayerInRangeOfPoint(targetid, 5.0, x, y, z))  return SendClientMessage(playerid,COLOR_RED,"ERROR: Player is not in range to cuff!");
        {
         new str[88];

         new target[MAX_PLAYER_NAME];
         GetPlayerName(targetid, target, sizeof(target));
         format(str, sizeof(str), "Information:{FFFFFF} You have cuffed %s!",target);
         SendClientMessage(playerid,COLOR_ORANGE, 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);
         TogglePlayerControllable(targetid,0);
         
         return 1;
        }

    }
    
}
	
}
As spawn code to set a player to a team I've used mSelection:

Код:
if(listid == skinscivilian)
	{
	    if(response)
	    {
		    allTeams[playerid] = TEAM_CIV;

		    SendClientMessage(playerid,COLOR_WHITE,"Faction & Skin Selected.");
	    	new civspawns = random(sizeof(CIV_RANDOM_SPAWNS));
	    	SetSpawnInfo(playerid,TEAM_CIV_SKINS,modelid,CIV_RANDOM_SPAWNS[civspawns][0],CIV_RANDOM_SPAWNS[civspawns][1],CIV_RANDOM_SPAWNS[civspawns][2],CIV_RANDOM_SPAWNS[civspawns][3],0,0,0,0,0,0);
	    	TogglePlayerSpectating(playerid,false);
	    	SendClientMessage(playerid,COLOR_WHITE,"You have selected to play as a innocent citizen.");
	    	SendClientMessage(playerid,COLOR_WHITE,"Make sure you have read our rules. You can find them under /help.");
	    	SendClientMessage(playerid,COLOR_WHITE,"Further help can be found under /help.");
	    	SetPlayerToTeamColour(playerid);

	 	    	    		   
	    }
	    else SendClientMessage(playerid,COLOR_GREY, "Selection aborted.");
	    
    	return 1;
	}
Could really use some help .-.
Reply
#2

change this
PHP код:
    if(allTeams[playerid] == TEAM_POLICE) return SendClientMessage(playerid,COLOR_RED"ERROR: You need to be a police officer or a army member!");
    if(
allTeams[playerid] == TEAM_ARMY)    return SendClientMessage(playerid,COLOR_RED"ERROR: You need to be a police officer or a army member!");
    { 
into this
PHP код:
    if(allTeams[playerid] != TEAM_POLICE && allTeams[playerid] != TEAM_ARMY) return SendClientMessage(playerid,COLOR_RED"ERROR: You need to be a police officer or a army member!"); 
Reply
#3

Quote:
Originally Posted by Mugala
Посмотреть сообщение
change this
PHP код:
    if(allTeams[playerid] == TEAM_POLICE) return SendClientMessage(playerid,COLOR_RED"ERROR: You need to be a police officer or a army member!");
    if(
allTeams[playerid] == TEAM_ARMY)    return SendClientMessage(playerid,COLOR_RED"ERROR: You need to be a police officer or a army member!");
    { 
into this
PHP код:
    if(allTeams[playerid] != TEAM_POLICE && allTeams[playerid] != TEAM_ARMY) return SendClientMessage(playerid,COLOR_RED"ERROR: You need to be a police officer or a army member!"); 
Thanks, it worked. Can't give +rep because Im missing the minimum forum posts I guess.
Reply
#4

The thing is, != sign (Exclamation mark followed by an equals), means Not Equal to. while double equal means equal too. You used double equal to in your code that is why it got reverted. As Mughla did, he combined both lines using && sign (double ampersand ) which means AND relation. Mughla had not provided explanation so I thought I'd give it for people who are new to programming.
Reply
#5

Quote:
Originally Posted by GTLS
Посмотреть сообщение
The thing is, != sign (Exclamation mark followed by an equals), means Not Equal to. while double equal means equal too. You used double equal to in your code that is why it got reverted. As Mughla did, he combined both lines using && sign (double ampersand ) which means AND relation. Mughla had not provided explanation so I thought I'd give it for people who are new to programming.
Yeah. Thanks for the info.
I guess this triggered the double equal and reverted the teams right?
Код:
if(allTeams[playerid] == TEAM_POLICE) return SendClientMessage(playerid,COLOR_RED, "ERROR: You need to be a police officer or a army member!");
if(allTeams[playerid] == TEAM_ARMY)	return SendClientMessage(playerid,COLOR_RED, "ERROR: You need to be a police officer or a army member!");
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)