If player not in range, disable command - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: If player not in range, disable command (
/showthread.php?tid=630406)
If player not in range, disable command -
NBass - 13.03.2017
Hello,
i'm trying to disable command to players, but it seems not working. I want to make, that if ONLY, the player is near the coordinates, can use the commands. The code seems good, but it's not working

Any ideas, to get that to work?
Code:
if(playerDB[playerid][vip] == true)
{
GetPlayerPos( playerid, Xaa, Yaa, Zaa );
if(Xaa <= -2069 && Xaa >= -2064 && Yaa <= -262 && Yaa >= -268)
{
SendClientMessage(playerid, 0xFF9900FF, " You are to far away!");
return 1;
} else {
if (!strcmp("/gates", cmdtext, true)) return MoveDynamicObject(zon1, -2067.7896, -265.9207, 36.4651, 5);
}
}
Thanks.
Re: If player not in range, disable command -
LEOTorres - 13.03.2017
Have you tried this?
Code:
IsPlayerInRangeOfPoint (playerid, Float:range, Float:x, Float:y, Float:z);
Re: If player not in range, disable command -
NBass - 13.03.2017
Yes, but I do not want to make a "circle" just for certain height. I do not want to use a Z coordinates. I want that for, only in area of X and Y coordinates, will be allowed the command.
Re: If player not in range, disable command -
Flamehaze7 - 13.03.2017
Somewhere inside the Gamemode:
Code:
IsPlayerInArea(playerid, Float:MinX, Float:MinY, Float:MaxX, Float:MaxY)
{
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
if(X >= MinX && X <= MaxX && Y >= MinY && Y <= MaxY) {
return 1;
}
return 0;
}
Your Command:
Code:
if(strcmp("/code",cmdtext, true))
{
if(IsPlayerInArea(playerid,LowCornerX,LowCornerY, HighCornerX,HighCornerY))
{
//If the player is in the area let him do the code stuff
} else {
//You're too far away
}
return 1;
}
I highly recommend the using of ZCMD since it's way more efficient than strcmp:
https://sampforum.blast.hk/showthread.php?tid=91354
You can obviously add before IsPlayerInArea the check if the player is a VIP or not and the other stuff.