PDA

View Full Version : Help with setting a limit


Mark_Niko
06/10/2011, 04:54 PM
I'm new to scripting and started to make some basic commands, 1 thing i have a problem with is how to set a limit? for example with this:


if (strcmp(cmd,"/roadblock",true) == 0)
{
new Float:X,Float:Y,Float:Z,Float:A;
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid,A);
roadblock = CreateObject(978, X, Y, Z, 0.0, 0.0, A);
return 1;
}
if (strcmp(cmd,"/deleteblock",true) == 0)
{
DestroyObject(roadblock);
return 1;
}


My problem here is that i can create unlimited roadblocks, but only delete 1 (like, i place 2 roadblocks, but i can only do /deleteblock once where it works) i thought that a limit could solve this, but i have no clue how to set a limit for placing objects, i searched around for long and didn't find anything, if anyone could help me i would be thankfull.

Another thing, if you know how to make it so i can use /deleteblock more than once that would be very great aswell, either where it just delete 1 roadblock at a time, or perhaps a /deleteallblocks which would delete all roadblocks.

Pharrel
06/10/2011, 05:06 PM
//global variables
new bool:Blocked[MAX_PLAYERS];
new roadblock[MAX_PLAYERS];

//commands
if (strcmp(cmd,"/roadblock",true) == 0)
{
if(!Blocked[playerid])
{
new Float:X,Float:Y,Float:Z,Float:A;
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid,A);
roadblock[playerid] = CreateObject(978, X, Y, Z, 0.0, 0.0, A);
Block[playerid] = true;
return 1;
}
else return SendClientMessage(playerid, -1, "You already create a road block...delete first!");
}
if (strcmp(cmd,"/deleteblock",true) == 0)
{
if(Blocked[playerid])
{
DestroyObject(roadblock[playerid);
Blocked[playerid] = false;
return 1;
}
else return SendClientMessage(playerid, -1, "You dont create any road block!");
}

Mark_Niko
06/10/2011, 05:13 PM
Thank you so much!