[Tutorial] Creating an Automatic Gate
#1

I havent seen many of these around so i decided to make one.

Ok, first we need to include a_samp so all the functions will work. So we will want to put this at the top of the script.
pawn Код:
#include <a_samp>
Then we need to forward the timer that we will use later on. So we put this under #include <a_samp>
pawn Код:
forward GateCheck();
Then we will want to create something to store the gate object. So we will want to put this under the include and forward.
pawn Код:
new AutomaticGate;
Ok, if you have a filterscript you will use "OnFilterScriptInit" instead of "OnGameModeInit", im using "OnGameModeInit" here, Change it to "OnFilterScriptInit" if your puting this into a filterscript instead.
pawn Код:
public OnGameModeInit()
Now we want to add the timer that we forwarded before to check if a player is near the gate.
pawn Код:
SetTimer("GateCheck", 500, true);
You can change 500 to a lower amount if you want, but the lower amount you take the more it might lag your server.

And now we want to create the gate object and attach the something that stores the object.
I have selected to create my object at the co-ords 2641.8201, 2810.6196 and 36.3222.
pawn Код:
AutomaticGate = CreateObject(971, 2641.8201, 2810.6196, 36.3222, 0, 0, 0);
Read https://sampwiki.blast.hk/wiki/CreateObject for more information about this function.

When we are done it should look something like this
pawn Код:
public OnGameModeInit()
{
    SetTimer("GateCheck", 500, true);
    AutomaticGate = CreateObject(971, 2641.8201, 2810.6196, 36.3222, 0, 0, 0);
    return 1;
}
And at last, we want to create the timer function that we forwarded at first.
pawn Код:
public GateCheck()
Then we will want to make a loop for all players.
pawn Код:
for(new i=0; i<MAX_PLAYERS; i++)
And after that we will want to check if the players are connected. (To be safe)
pawn Код:
if(IsPlayerConnected(i))
Now we want to check if a player is near the gate. Using the IsPlayerInRangeOfPoint function.
pawn Код:
if(IsPlayerInRangeOfPoint(i, 10.0, 2641.8201, 2810.6196, 36.3222))
See https://sampwiki.blast.hk/wiki/IsPlayerInRangeOfPoint for more info about this function.

And if a player is near the gate, we will want to move it.
pawn Код:
MoveObject(AutomaticGate, 2641.8201, 2810.6196, 26.3222, 5.0);
I have choosed to move it 10 points down.

If the player is not near the gate, we should reset it.
pawn Код:
MoveObject(AutomaticGate, 2641.8201, 2810.6196, 36.3222, 5.0);
Now it should look something like this.
pawn Код:
public CheckGate()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInRangeOfPoint(i, 10.0, 2641.8201, 2810.6196, 36.3222))
            {
                MoveObject(AutomaticGate, 2641.8201, 2810.6196, 26.3222, 5.0);
            }
            else
            {
                MoveObject(AutomaticGate, 2641.8201, 2810.6196, 36.3222, 5.0);
            }
        }
    }
}

Thats all for me, hope it helped.
Reply


Messages In This Thread
Creating an Automatic Gate - by [NWA]Hannes - 24.12.2010, 19:42
Re: Creating an Automatic Gate - by Noss* - 24.12.2010, 19:48
Re: Creating an Automatic Gate - by Mean - 25.12.2010, 16:12
Re: Creating an Automatic Gate - by Darien - 22.01.2011, 15:16
Re: Creating an Automatic Gate - by Legit_V20 - 23.01.2011, 07:12
Re: Creating an Automatic Gate - by [_Bo$$_] - 23.01.2011, 07:24
Re: Creating an Automatic Gate - by hadzx - 24.01.2011, 17:55
Re: Creating an Automatic Gate - by ExeC - 24.01.2011, 17:58
Re: Creating an Automatic Gate - by ricardo178 - 24.01.2011, 22:18
Re: Creating an Automatic Gate - by Haydz - 24.01.2011, 23:32
Re: Creating an Automatic Gate - by Darien - 31.01.2011, 17:50
Re: Creating an Automatic Gate - by ricardo178 - 31.01.2011, 19:54
Re: Creating an Automatic Gate - by buster_ - 07.02.2011, 17:11
Re: Creating an Automatic Gate - by SkizzoTrick - 07.02.2011, 17:13
Re: Creating an Automatic Gate - by MoDee - 12.02.2011, 12:12
AW: Creating an Automatic Gate - by MuLtiVaN - 12.02.2011, 21:54
Re: Creating an Automatic Gate - by Stunt_Guy - 13.02.2011, 16:28
Re: Creating an Automatic Gate - by justsomeguy - 25.02.2011, 17:37
Re: Creating an Automatic Gate - by Miralem - 25.02.2011, 17:50
Re: Creating an Automatic Gate - by justsomeguy - 25.02.2011, 18:19
Re: Creating an Automatic Gate - by Justinlampy - 03.03.2011, 23:40
Re: Creating an Automatic Gate - by Rolyy - 04.03.2011, 11:27
Re: Creating an Automatic Gate - by Ironboy - 04.03.2011, 11:32
Re: Creating an Automatic Gate - by ParaMedicalzZ - 04.03.2011, 11:34
Re: Creating an Automatic Gate - by justsomeguy - 05.03.2011, 20:45
Re: Creating an Automatic Gate - by tanush - 07.03.2011, 19:28
Re: Creating an Automatic Gate - by AH.1990 - 19.03.2011, 20:31
Re: Creating an Automatic Gate - by Davz*|*Criss - 19.03.2011, 20:51
Re: Creating an Automatic Gate - by rtyd - 10.04.2011, 11:55
Re: Creating an Automatic Gate - by juraska - 23.05.2011, 18:54
Re: Creating an Automatic Gate - by BaubaS - 23.05.2011, 22:18
Re: Creating an Automatic Gate - by Snipa - 23.05.2011, 23:44
Re: Creating an Automatic Gate - by Dennis_Sanchez - 31.05.2011, 15:59
Re: Creating an Automatic Gate - by Jack_Rocker - 03.06.2011, 10:00
Re: Creating an Automatic Gate - by Darnell - 10.08.2011, 06:10
Re: Creating an Automatic Gate - by Amel_PAtomAXx - 26.08.2011, 16:28
Re: Creating an Automatic Gate - by cs_waller - 30.12.2011, 20:31
Re : Creating an Automatic Gate - by Heni - 01.01.2013, 10:09
Re: Re : Creating an Automatic Gate - by [NWA]Hannes - 02.01.2013, 20:49
Re : Creating an Automatic Gate - by Heni - 03.01.2013, 09:54
Re: Creating an Automatic Gate - by ata001 - 29.09.2018, 16:26

Forum Jump:


Users browsing this thread: 1 Guest(s)