Can someone help me with this? -
iOxide - 03.07.2014
I made a roadblock system for police, everything is working fine but when player use /delrb, its not deleting the created roadblock object. It says "No Roadblocks found near you" even if the player is near the object.
pawn Код:
#define MAX_ROADBLOCK 2
enum RoadblockData
{
RBObject,
Float:RBX,
Float:RBY,
Float:RBZ
}
new
RoadBlock[MAX_ROADBLOCK][RoadblockData];
CMD:rb(playerid, params[])
{
SendAdminText(playerid, "/RB", params);
if (pInfo[playerid][Class] != POLICE)
return 0;
if(RankInfo[playerid][PoliceRank] < 2)
return SendClientMessage(playerid, RED, "You need to be Police Rank 2+ to use this command!");
if (GetPlayerVehicleSeat(playerid) == -1)
RoadBlock_Create(playerid);
else
SendClientMessage(playerid, RED, "You must be on foot to create a RoadBlock.");
return 1;
}
CMD:delrb(playerid, params[])
{
SendAdminText(playerid, "/DELRB", params);
if(pInfo[playerid][Class] != POLICE)
return 0;
if(RankInfo[playerid][PoliceRank] < 2)
return SendClientMessage(playerid, RED, "You need to be Police Rank 2+ to use this command!");
if (GetPlayerVehicleSeat(playerid) == 0)
return SendClientMessage(playerid, RED, "You cannot use this command while you are inside a vehicle!");
for(new i = 1; i<MAX_ROADBLOCK; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 5.5, RoadBlock[i][RBX], RoadBlock[i][RBY], RoadBlock[i][RBZ]))
{
DestroyObject(RoadBlock[i][RBObject]);
SendClientMessage(playerid, BLUE, "Roadblock has been deleted.");
}
else
SendClientMessage(playerid, RED, "No Roadblocks found around you!");
}
return 1;
}
stock RoadBlock_Create(playerid)
{
new
RBIndex = -1,
Float:x,
Float:y,
Float:z,
Float:rot;
for (new i; i < MAX_ROADBLOCK; i++)
{
RBIndex = i;
break;
}
if (RBIndex != -1)
{
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, rot);
RoadBlock[RBIndex][RBObject] = CreateObject(981, x, y, z, 0.0, 0.0, rot);
RoadBlock[RBIndex][RBX] = x;
RoadBlock[RBIndex][RBY] = y;
RoadBlock[RBIndex][RBZ] = z;
SetPlayerPos(playerid, x,y,z+3.0);
SetPlayerFacingAngle(playerid, rot);
SendClientMessage(playerid, BLUE, "Roadblock has been created!");
SendClientMessage(playerid, GRAY, "Use /delrb to remove the Roadblock.");
}
else
SendClientMessage(playerid, RED, "The maximum number of Roadblocks has been reached!");
}
Re: Can someone help me with this? -
Dziugsas - 03.07.2014
Can you delete the first roadblock that you placed?
Re: Can someone help me with this? -
iOxide - 03.07.2014
Nope, its not detecting any objects near the police player if they use /delrb cmd, it sends the error message saying roadblock not found, but the roadblocks are created.
Re: Can someone help me with this? -
BroZeus - 03.07.2014
for(new i = 1; i<MAX_ROADBLOCK; i++)
change this to this
for(new i = 0; i<MAX_ROADBLOCK; i++)
Re: Can someone help me with this? -
iOxide - 03.07.2014
Hm, its working now but i got another issue. Cops are able to create more than the MAX_ROADBLOCK amount. It was suppose to block a player from spawning more than 2 roadblocks but its not working 0_o any help?
PS: Can you tell me what does i = 0 and i = 1 do?
AW: Can someone help me with this? -
Macronix - 03.07.2014
Well, if you set it to 0 it starts looping from id 0 and otherwise if you set it to 1 it starts from id 1

Simple.
Re: Can someone help me with this? -
BroZeus - 03.07.2014
pawn Код:
enum RoadblockData
{
RBObject,
Float:RBX,
Float:RBY,
Float:RBZ,
bool:IsUsed
}
stock RoadBlock_Create(playerid)
{
new
RBIndex = -1,
Float:x,
Float:y,
Float:z,
Float:rot;
for (new i=0; i < MAX_ROADBLOCK; i++)
{
if(RoadBlock[i][IsUsed] == true)continue;
RBIndex = i;
break;
}
if (RBIndex != -1)
{
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, rot);
RoadBlock[RBIndex][RBObject] = CreateObject(981, x, y, z, 0.0, 0.0, rot);
RoadBlock[RBIndex][RBX] = x;
RoadBlock[RBIndex][RBY] = y;
RoadBlock[RBIndex][RBZ] = z;
RoadBlock[RBIndex][IsUsed] = true;
SetPlayerPos(playerid, x,y,z+3.0);
SetPlayerFacingAngle(playerid, rot);
SendClientMessage(playerid, BLUE, "Roadblock has been created!");
SendClientMessage(playerid, GRAY, "Use /delrb to remove the Roadblock.");
}
else
SendClientMessage(playerid, RED, "The maximum number of Roadblocks has been reached!");
}
CMD:delrb(playerid, params[])
{
SendAdminText(playerid, "/DELRB", params);
if(pInfo[playerid][Class] != POLICE)
return 0;
if(RankInfo[playerid][PoliceRank] < 2)
return SendClientMessage(playerid, RED, "You need to be Police Rank 2+ to use this command!");
if (GetPlayerVehicleSeat(playerid) == 0)
return SendClientMessage(playerid, RED, "You cannot use this command while you are inside a vehicle!");
new found=0;
for(new i = 0; i<MAX_ROADBLOCK; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 5.5, RoadBlock[i][RBX], RoadBlock[i][RBY], RoadBlock[i][RBZ]))
{
DestroyObject(RoadBlock[i][RBObject]);
RoadBlock[i][IsUsed]=false;
found=1;
SendClientMessage(playerid, BLUE, "Roadblock has been deleted.");
}
}
if(found==0)SendClientMessage(playerid, RED, "No Roadblocks found around you!");
return 1;
}
use this all
no need to edit rb command leave it as it is
but note the edits in above code