How to set this into /destroyallcades?
#1

So basically i have this /destroycades

but i want to make /destroyallcades

Код:
CMD:destroycade(playerid, params[])
{
	if(CheckGMX(playerid)) return 1;
	if(IsACop(playerid))
	{
		if(IsPlayerInAnyVehicle(playerid))
		{
			SendClientMessage(playerid, COLOR_GREY, "You must be on foot to use this command.");
			return 1;
		}
		if(PlayerInfo[playerid][pRank] < 3 && PlayerInfo[playerid][pFaction] != 2)
		{
			SendClientMessage(playerid, COLOR_GREY, "You need to be at least rank 3 to use this command.");
			return 1;
		}
		new string[128], Float:Position[3];
		for(new i; i<MAX_BARRICADES; i++)
		{
			GetDynamicObjectPos(Barricade[i], Position[0], Position[1], Position[2]);

			if(IsPlayerInRangeOfPoint(playerid, 5.0, Position[0], Position[1], Position[2]))
			{
				DestroyDynamicObject(Barricade[i]);
				Barricade[i] = 0;
				new zone[MAX_ZONE_NAME];
				GetPlayer3DZone(playerid, zone, sizeof(zone));
				format(string, sizeof(string), "HQ: A barricade has been destroyed by %s at %s.", GetPlayerNameEx(playerid), zone);
				foreach(Player, x)
				{
					if(IsACop(x))
					{
						SendClientMessage(x, TEAM_BLUE_COLOR, string);
					}
				}
				return 1;
			}
		}
		SendClientMessage(playerid, COLOR_GREY, "You're not near any barricades.");
	}
	else
	{
		SendClientMessage(playerid, COLOR_GREY, "You're not a law enforcement officer.");
	}
	return 1;
}
Thank you very much
Reply
#2

Try to remove the "nearest object" code, so it will remove all, like this:
pawn Код:
CMD:destroyallcades(playerid, params[])
{
    if(CheckGMX(playerid)) return 1;
    if(IsACop(playerid))
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            SendClientMessage(playerid, COLOR_GREY, "You must be on foot to use this command.");
            return 1;
        }
        if(PlayerInfo[playerid][pRank] < 3 && PlayerInfo[playerid][pFaction] != 2)
        {
            SendClientMessage(playerid, COLOR_GREY, "You need to be at least rank 3 to use this command.");
            return 1;
        }
        new string[128], Float:Position[3];
        for(new i; i<MAX_BARRICADES; i++)
        {
            DestroyDynamicObject(Barricade[i]);
        }
        format(string, sizeof(string), "HQ: All barricades has been destroyed by %s", GetPlayerNameEx(playerid));
        foreach(Player, x)
        {
            if(IsACop(x))
            {
                SendClientMessage(x, TEAM_BLUE_COLOR, string);
            }
        }
        return 1;
    }
    else
    {
        SendClientMessage(playerid, COLOR_GREY, "You're not a law enforcement officer.");
    }
    return 1;
}
Note with code above: if there are no barricades created, the message "HQ: All barricades has been destroyed" will still showing, to prevent this, add an if statement and check if there is any barricades.
Reply
#3

Quote:
Originally Posted by Robo_N1X
Посмотреть сообщение
Note with code above: if there are no barricades created, the message "HQ: All barricades has been destroyed" will still showing, to prevent this, add an if statement and check if there is any barricades.
Can you make me a statement if there is any barricade?
Reply
#4

Quote:
Originally Posted by ChristianIvann09
Посмотреть сообщение
Can you make me a statement if there is any barricade?
Hmm no, because i can't see how Barricade[] is defined, perhaps you can count how many objects were deleted, by checking if the object is valid, like this:
pawn Код:
new x = 0;
for(new i; i<MAX_BARRICADES; i++)
{
    if(IsValidDynamicObject(Barricade[i]))
    {
        DestroyDynamicObject(Barricade[i]);
        x++;
    }
}
if(x > 0)
{
        foreach(Player, x)
        {
            if(IsACop(x))
            {
                SendClientMessage(x, TEAM_BLUE_COLOR, string);
            }
        }

}
else
{
    SendClientMessage(playerid, COLOR_GREY, "There is no barricade to destroy!");
}
Not tested yet, hope it works.
Reply
#5

Код:
  new string[128], Float:Position[3];
Код:
26064) : warning 204: symbol is assigned a value that is never used: "Position"
Reply
#6

Oh yeah, Sorry i forgot about it, you can delete Float:Position[3];
so it's left like this:
pawn Код:
new string[128];
Also check my previous post, i edited the code.
Reply
#7

Quote:
Originally Posted by Robo_N1X
Посмотреть сообщение
Hmm no, because i can't see how Barricade[] is defined,
Here:
Код:
#define	MAX_BARRICADES	10
new Barricade[MAX_BARRICADES];
Others:
Код:
CMD:deploycade(playerid, params[])
{
	if(IsACop(playerid) || PlayerInfo[playerid][pFaction] == 4 || PlayerInfo[playerid][pFaction] == 4 && PlayerInfo[playerid][pRank] >= 3)
	{
		if(PlayerInfo[playerid][pRank] <= 2)
			return SendClientMessage(playerid, COLOR_GRAD1, "You must be R3+ to use this command");
		if(IsPlayerInAnyVehicle(playerid))
		{
			SendClientMessageEx(playerid, COLOR_GREY, "You must be on foot to use this command.");
			return 1;
		}
		new number, string[128], Float:Position[4];
        if(sscanf(params,"d",number))
	    {
			SendClientMessage(playerid,COLOR_WHITE,"USAGE: /deploycade <1/2/3/4/5/6/7>");
			SendClientMessage(playerid,COLOR_GRAD1,"| 1: Small Roadblock | 2: Medium Roadblock");
			SendClientMessage(playerid,COLOR_GRAD1,"| 3: Big Roadblock | 4: Traffic cone");
			//SendClientMessage(playerid,COLOR_FBI,"| 5: Detour sign | 6: Will be sign");
			SendClientMessage(playerid,COLOR_GRAD1,"| 5: Line closed sign");
			SendClientMessage(playerid,COLOR_WHITE,"----------------------");
			return 1;
		}
		for(new i; i<MAX_BARRICADES; i++)
		{
			if(Barricade[i] == 0)
			{
			GetPlayerPos(playerid, Position[0], Position[1], Position[2]);
			GetPlayerFacingAngle(playerid, Position[3]);
			switch(number)
			{
				case 1:
				{
					Barricade[i] = CreateDynamicObject(1459, Position[0], Position[1]+1, Position[2]-0.5, 0.0, 0.0, Position[3],-1, -1, -1, 200.0);
				}
				case 2:
				{
					Barricade[i] = CreateDynamicObject(978, Position[0], Position[1]+1, Position[2], 0.0, 0.0, Position[3],-1, -1, -1, 200.0);
				}
				case 3:
				{
				    Barricade[i] = CreateDynamicObject(981, Position[0], Position[1]+1, Position[2], 0.0, 0.0, Position[3]+180.0, -1, -1, -1, 200.0);
                    SetPlayerPos(playerid, Position[0], Position[1], Position[2]+5);
				}
				case 4:
				{
		            Barricade[i] = CreateDynamicObject(1238, Position[0], Position[1]+1, Position[2]-0.5, 0.0, 0.0, Position[3],-1, -1, -1, 200.0);
				}
				/*case 5:
				{
		            Barricade[i] = CreateDynamicObject(1425, Position[0], Position[1]+1, Position[2]-0.5, 0.0, 0.0, Position[3],-1, -1, -1, 200.0);
				}
				case 6:
				{
					Barricade[i] = CreateDynamicObject(3265, Position[0], Position[1]+1, Position[2]-0.9, 0.0, 0.0, Position[3],-1, -1, -1, 200.0);
				}*/
				case 5:
				{
					Barricade[i] = CreateDynamicObject(3091, Position[0], Position[1]+1, Position[2]-0.25, 0.0, 0.0, Position[3],-1, -1, -1, 200.0);
				}
			}
			GetPlayerPos(playerid, Position[0], Position[1], Position[2]);
			GetPlayerFacingAngle(playerid, Position[3]);
			new zone[MAX_ZONE_NAME];
			GetPlayer3DZone(playerid, zone, sizeof(zone));
			format(string, sizeof(string), "HQ: A barricade has been deployed by %s at %s.", GetPlayerNameEx(playerid), zone);
			foreach(Player, x)
		{
					if(IsACop(x) || PlayerInfo[x][pFaction] == 4)
					{
						SendClientMessageEx(x, TEAM_BLUE_COLOR, string);
						if (PlayerInfo[x][pRank] >= 3)
						{
							SendClientMessageEx(x, COLOR_YELLOW, "You can remove a barricade by typing /destroycade.");
						}
					}
				}
			return 1;
			}
		}
		SendClientMessageEx(playerid, COLOR_GREY, "All available barriers have been deployed.");
	}
	else
	{
		SendClientMessageEx(playerid, COLOR_GREY, "You are not an LEO.");
	}
	return 1;
}
Reply
#8

are you still there? @Robo_N1X ?
Reply
#9

Quote:
Originally Posted by Robo_N1X
Посмотреть сообщение
Also check my previous post, i edited the code.
Did you checked my previous post?

Quote:
Originally Posted by Robo_N1X
Посмотреть сообщение
Hmm no, because i can't see how Barricade[] is defined, perhaps you can count how many objects were deleted, by checking if the object is valid, like this:
pawn Код:
new x = 0;
for(new i; i<MAX_BARRICADES; i++)
{
    if(IsValidDynamicObject(Barricade[i]))
    {
        DestroyDynamicObject(Barricade[i]);
        x++;
    }
}
if(x > 0)
{
        foreach(Player, x)
        {
            if(IsACop(x))
            {
                SendClientMessage(x, TEAM_BLUE_COLOR, string);
            }
        }

}
else
{
    SendClientMessage(playerid, COLOR_GREY, "There is no barricade to destroy!");
}
Not tested yet, hope it works.
Also i've saw your Barricade[] code, so you can check by using:
pawn Код:
if(Barricade[i] != 0)
on code above, replace the IsValidDynamicObject(Barricade[i]).
But i would recommend my previous code above, with IsValidDynamicObject...
You can either use:
pawn Код:
if(IsValidDynamicObject(Barricade[i]))
or
pawn Код:
if(IsValidDynamicObject(Barricade[i]) && Barricade[i] != 0)
Reply
#10

Quote:
Originally Posted by Robo_N1X
Посмотреть сообщение
Did you checked my previous post?



Also i've saw your Barricade[] code, so you can check by using:
pawn Код:
if(Barricade[i] != 0)
on code above, replace the IsValidDynamicObject(Barricade[i]).
But i would recommend my previous code above, with IsValidDynamicObject...
You can either use:
pawn Код:
if(IsValidDynamicObject(Barricade[i]))
or
pawn Код:
if(IsValidDynamicObject(Barricade[i]) && Barricade[i] != 0)
Код:
  foreach(Player, x)
Код:
(26093) : warning 219: local variable "x" shadows a variable at a preceding level
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)