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;
}
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.
|
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!");
}
new string[128], Float:Position[3];
26064) : warning 204: symbol is assigned a value that is never used: "Position"
new string[128];
#define MAX_BARRICADES 10 new Barricade[MAX_BARRICADES];
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;
}
|
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 Код:
|
if(Barricade[i] != 0)
if(IsValidDynamicObject(Barricade[i]))
if(IsValidDynamicObject(Barricade[i]) && Barricade[i] != 0)
|
Did you checked my previous post?
Also i've saw your Barricade[] code, so you can check by using: pawn Код:
But i would recommend my previous code above, with IsValidDynamicObject... You can either use: pawn Код:
pawn Код:
|
foreach(Player, x)
(26093) : warning 219: local variable "x" shadows a variable at a preceding level