PDA

View Full Version : [Tutorial] Admin-only zones


Hiddos
13/07/2010, 10:17 AM
Another totally useless tutorial brought you to by the asshole of the SA-MP forums, Hiddos.

We're doing an admin-only zone here.

To start off, we're going to add a forward declaration for a function that checks if the player is in a forbidden area (Or easily said: Check if the player isn't an admin and still is in the admin area)

Add this on top of the script, but under your #includes:
forward CheckAdminArea();

That tells the script that there is a public function/whatever, so it won't error.

Here's a stock function that we'll use to check if the player is in the specific area:

stock IsPlayerInArea(playerid, Float:min_x, Float:max_x, Float:min_y, Float:max_y)
{
new Float:pos[3]; //Save his position this this triple-var.
GetPlayerPos(playerid,pos[0],pos[1],pos[2]); //Save his X in pos[0], his Y in pos[1] and his Z in pos[2].
if(min_x <= pos[0] && max_x >= pos[0] && min_y <= pos[1] && max_y >= pos[1]) return 1; //Checks if the player is in the area, and if so returns 1.
return 0; //Else it returns 0.
}

We'll be using that later, when we're checking if the player is in the admin area. Which is right now.
For the "admin zone", we'll be using the co-ords of the pyramid in Las Venturas, feel free to use your own co-ords.

Create the public function this way (Place it anywhere in the script, not in another function):
public CheckAdminArea()
{
for(new i; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i)) continue;
if(IsPlayerInArea(i,2082.2393,2417.5349,1203.1693, 1363.7429) && !IsPlayerAdmin(i))
{
//Do your stuff
SetPlayerHealth(i,0); // Kills him, for example.
}
}
return 1;
}

I guess that's the most you'll need to know, we just need to set a timer. We'll do that at OnFilterScriptInit (Or if you're doing it in a GM, OnGameModeInit)


public OnFilterScriptInit()
{
SetTimer("CheckAdminArea",3000,1); // That "3000" means that it checks every 3000 milliseconds, or 3 seconds. Feel free to change it to what you want. But remember, 1000 = 1 second.
return 1;
}

That should get you going. Feel free to ask questions in this topic.

For a filterscript version, go to this link:
http://pastebin.com/MCFpFj6r

Small edit: A friend of mine asked me about doing this for stunt zones. It's easy to edit the the person type it checks, for example you could do IsPlayerNPC instead of IsPlayerAdmin, or GetPVarInt(playerid,"Premium") to check if he's got what it takes.

MartinDaniel
13/07/2010, 10:23 AM
GREEAAAT, I like it... Good luck.

iZN
13/07/2010, 10:28 AM
Wow, great use of PVars, nice tutorial.

Hiddos
13/07/2010, 10:32 AM
PVar's? The heck are you talking about :D

KJ1
13/07/2010, 03:31 PM
great work , but i got warning
Untitled.pwn(247) : error 017: undefined symbol "playerid"

line 247 : Untitled.pwn(247) : error 017: undefined symbol "playerid"

Hiddos
13/07/2010, 05:51 PM
Oh, spotted the bug. Thanks ^^

Aleluja
13/07/2010, 09:27 PM
Great TuTorial Hiddos :) :D

bartje01
19/07/2010, 08:29 PM
Thanks, I think I can use this for my gang zones.

Kar
19/07/2010, 09:31 PM
i luv this ass hole:D

pocok1
20/07/2010, 01:32 PM
Yes, good! And I bet, if we poke that if structure, and use up the "trash" Z coords thats sitting in the pos[2], we can convert the memory-eating Z coords into a 3D ADMINAREA!

stock IsPlayerInArea(playerid, Float:min_x, Float:max_x, Float:min_y, Float:max_y, Float:min_z, Float:max_z){
new Float:pos[3]; //Save his position this this triple-var.
GetPlayerPos(playerid,pos[0],pos[1],pos[2]); //Save his X in pos[0], his Y in pos[1] and his Z in pos[2].
if(min_x <= pos[0] && max_x >= pos[0] && min_y <= pos[1] && max_y >= pos[1] && min_z <= pos[2] && max_z >= pos[2] ) return 1; //Checks if the player is in the area, and if so returns 1.
return 0; //Else it returns 0.}

I mean this. See the function's last two params! They are now asking Z values. And the last two if statement is Z too. Now you can create admin zones under a bridge without the risk of the innocent players die when stunt/rp/whatever ON the bridge. They die if they UNDER the bridge.

[Lsrcr]Sandra
23/07/2010, 06:28 AM
U Showed Up That U Are Really The Ass Hole Of Samp Forum....XD