[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


Messages In This Thread
Admin-only zones - by Hiddos - 13.07.2010, 10:17
Re: Admin-only zones - by MartinDaniel - 13.07.2010, 10:23
Re: Admin-only zones - by iZN - 13.07.2010, 10:28
Re: Admin-only zones - by Hiddos - 13.07.2010, 10:32
Re: Admin-only zones - by KJ1 - 13.07.2010, 15:31
Re: Admin-only zones - by Hiddos - 13.07.2010, 17:51
Re: Admin-only zones - by Aleluja - 13.07.2010, 21:27
Re: Admin-only zones - by bartje01 - 19.07.2010, 20:29
Re: Admin-only zones - by Kar - 19.07.2010, 21:31
Re: Admin-only zones - by pocok1 - 20.07.2010, 13:32
Re: Admin-only zones - by [Lsrcr]Sandra - 23.07.2010, 06:28

Forum Jump:


Users browsing this thread: 3 Guest(s)