[Tutorial] Admin-only zones
#1

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:
pawn Код:
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:
pawn Код:
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):
pawn Код:
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)

pawn Код:
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.
Reply
#2

GREEAAAT, I like it... Good luck.
Reply
#3

Wow, great use of PVars, nice tutorial.
Reply
#4

PVar's? The heck are you talking about
Reply
#5

great work , but i got warning
Untitled.pwn(247) : error 017: undefined symbol "playerid"

Код:
line 247 : Untitled.pwn(247) : error 017: undefined symbol "playerid"
Reply
#6

Oh, spotted the bug. Thanks ^^
Reply
#7

Great TuTorial Hiddos
Reply
#8

Thanks, I think I can use this for my gang zones.
Reply
#9

i luv this ass hole
Reply
#10

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!
pawn Код:
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.
Reply
#11

U Showed Up That U Are Really The Ass Hole Of Samp Forum....XD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)