SA-MP Forums Archive
[Tutorial] Creating an Automatic Gate - 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)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Creating an Automatic Gate (/showthread.php?tid=202668)

Pages: 1 2 3


Creating an Automatic Gate - [NWA]Hannes - 24.12.2010

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.


Re: Creating an Automatic Gate - Noss* - 24.12.2010

Good job.. Seen alot of these around but having more = even better.


Re: Creating an Automatic Gate - Mean - 25.12.2010

This is kinda useful, but wiki ftw!


Re: Creating an Automatic Gate - Darien - 22.01.2011

awesome


Re: Creating an Automatic Gate - Legit_V20 - 23.01.2011

ok so i have
Код:
public gatecheck()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInRangeOfPoint(i, 10.0, 2127.55102500,3275.75195300,2.47892000))

            {
                MoveObject(automaticgate, 2127.55102500,8275.75195300,2.47892000);
            }
            else
            {
                MoveObject(automaticgate, 2127.55102500,3275.75195300,2.47892000);
            }
            if(IsPlayerInRangeOfPoint(i, 10.0, 976,2127.33276400,3275.76489300,2.45796200))
            {
            	MoveObject(automaticgate2, 2127.33276400,8275.76489300+5,2.45796200);
            }
            else
            {
            	MoveObject(automaticgate2, 2127.33276400,3275.76489300,2.45796200);
			}
        }
    }
    return 1;
}
and then i get

Код:
C:\Users\Legit_V20\Desktop\GTASanAndreas\gamemodes\HNH.pwn(721) : warning 202: number of arguments does not match definition
C:\Users\Legit_V20\Desktop\GTASanAndreas\gamemodes\HNH.pwn(725) : warning 202: number of arguments does not match definition
C:\Users\Legit_V20\Desktop\GTASanAndreas\gamemodes\HNH.pwn(727) : warning 202: number of arguments does not match definition
C:\Users\Legit_V20\Desktop\GTASanAndreas\gamemodes\HNH.pwn(729) : warning 202: number of arguments does not match definition
C:\Users\Legit_V20\Desktop\GTASanAndreas\gamemodes\HNH.pwn(733) : warning 202: number of arguments does not match definition
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


5 Warnings.



Re: Creating an Automatic Gate - [_Bo$$_] - 23.01.2011

nice tutorial , gud job


Re: Creating an Automatic Gate - hadzx - 24.01.2011

i get this error

Код:
C:\Users\Stephen-Laptop\Desktop\server samp - Copy\gamemodes\lvpg.pwn(719) : warning 235: public function lacks forward declaration (symbol "CheckGate")
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
Код:
public CheckGate()// <<<<<<<< LINE 719
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInRangeOfPoint(i, 10.0, 1717.04809570,1298.18298340,11.49500275))
            {
                MoveObject(AutomaticGate, 1716.09643555,1293.90063477,11.49500275, 5.0);
            }
            else
            {
                MoveObject(AutomaticGate, 1717.04809570,1298.18298340,11.49500275, 5.0);
            }
        }
    }
}



Re: Creating an Automatic Gate - ExeC - 24.01.2011

Quote:
Originally Posted by hadzx
View Post
i get this error

Code:
C:\Users\Stephen-Laptop\Desktop\server samp - Copy\gamemodes\lvpg.pwn(719) : warning 235: public function lacks forward declaration (symbol "CheckGate")
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
pawn Code:
forward CheckGate();
public CheckGate()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInRangeOfPoint(i, 10.0, 1717.04809570,1298.18298340,11.49500275))
            {
                MoveObject(AutomaticGate, 1716.09643555,1293.90063477,11.49500275, 5.0);
            }
            else
            {
                MoveObject(AutomaticGate, 1717.04809570,1298.18298340,11.49500275, 5.0);
            }
        }
    }
}
Btw, nice tut.


Re: Creating an Automatic Gate - ricardo178 - 24.01.2011

Nice man!


Re: Creating an Automatic Gate - Haydz - 24.01.2011

Quote:
Originally Posted by Legit_V20
Посмотреть сообщение
ok so i have
Код:
public gatecheck()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInRangeOfPoint(i, 10.0, 2127.55102500,3275.75195300,2.47892000))

            {
                MoveObject(automaticgate, 2127.55102500,8275.75195300,2.47892000);
            }
            else
            {
                MoveObject(automaticgate, 2127.55102500,3275.75195300,2.47892000);
            }
            if(IsPlayerInRangeOfPoint(i, 10.0, 976,2127.33276400,3275.76489300,2.45796200))
            {
            	MoveObject(automaticgate2, 2127.33276400,8275.76489300+5,2.45796200);
            }
            else
            {
            	MoveObject(automaticgate2, 2127.33276400,3275.76489300,2.45796200);
			}
        }
    }
    return 1;
}
and then i get

Код:
C:\Users\Legit_V20\Desktop\GTASanAndreas\gamemodes\HNH.pwn(721) : warning 202: number of arguments does not match definition
C:\Users\Legit_V20\Desktop\GTASanAndreas\gamemodes\HNH.pwn(725) : warning 202: number of arguments does not match definition
C:\Users\Legit_V20\Desktop\GTASanAndreas\gamemodes\HNH.pwn(727) : warning 202: number of arguments does not match definition
C:\Users\Legit_V20\Desktop\GTASanAndreas\gamemodes\HNH.pwn(729) : warning 202: number of arguments does not match definition
C:\Users\Legit_V20\Desktop\GTASanAndreas\gamemodes\HNH.pwn(733) : warning 202: number of arguments does not match definition
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


5 Warnings.
You're missing out Float: speed at the end of your MoveObject functions.
https://sampwiki.blast.hk/wiki/MoveObject


Re: Creating an Automatic Gate - Darien - 31.01.2011

but i have error, then other ppl wants open doors they cant!!!! event they r rcon admins! just me can open these doors so WATAFAK!


Re: Creating an Automatic Gate - ricardo178 - 31.01.2011

It is good man but there is alried MUTCH toturials about this!


Re: Creating an Automatic Gate - buster_ - 07.02.2011

Quote:
Originally Posted by hadzx
View Post
i get this error

Code:
C:\Users\Stephen-Laptop\Desktop\server samp - Copy\gamemodes\lvpg.pwn(719) : warning 235: public function lacks forward declaration (symbol "CheckGate")
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
Code:
public CheckGate()// <<<<<<<< LINE 719
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInRangeOfPoint(i, 10.0, 1717.04809570,1298.18298340,11.49500275))
            {
                MoveObject(AutomaticGate, 1716.09643555,1293.90063477,11.49500275, 5.0);
            }
            else
            {
                MoveObject(AutomaticGate, 1717.04809570,1298.18298340,11.49500275, 5.0);
            }
        }
    }
}
line 791 = GateCheck_|_ NOT CheckGate


Re: Creating an Automatic Gate - SkizzoTrick - 07.02.2011

Epic
There are too much tutorials about this already


Re: Creating an Automatic Gate - MoDee - 12.02.2011

Thx man


AW: Creating an Automatic Gate - MuLtiVaN - 12.02.2011

Quote:
pawn Code:
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);
            }
        }
    }
}
aargh, it needs a return 1; or its endless


Re: Creating an Automatic Gate - Stunt_Guy - 13.02.2011

Nice TUT. !!


Re: Creating an Automatic Gate - justsomeguy - 25.02.2011

ey i get close to the gate but it doesnt open how to fix this? here is the code:
pawn Code:
public CheckGate()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInRangeOfPoint(i, 10.0, -1572.1834716797, 658.83563232422, 6.96250295639042))
            {
                MoveObject(AutomaticGate, -1572.1834716797, 658.83563232422, 6.9625029563904, 0, 90);
            }
            else
            {
                MoveObject(AutomaticGate, -1575.4208984375, 660.19921875, 6.1875, 0, 90);
            }
        }
    }
}
and here the warnings:
Code:
C:\Program Files\Rockstar Games\GTA San Andreas\gamemodes\sf90s.pwn(1393) : warning 202: number of arguments does not match definition
C:\Program Files\Rockstar Games\GTA San Andreas\gamemodes\sf90s.pwn(1397) : warning 202: number of arguments does not match definition
i used these createobjects:
pawn Code:
CreateObject(968, -1572.1834716797, 658.83563232422, 6.9625029563904, 0, 90.250213623047, 90);
CreateObject(968, -1575.4208984375, 660.19921875, 6.1875, 0, 90.247192382813, 90);



Re: Creating an Automatic Gate - Miralem - 25.02.2011

did u forward CheckGate at the top of the script ( or it might be " new CheckGate " I aint such a good scripter :P :P :P )


Re: Creating an Automatic Gate - justsomeguy - 25.02.2011

i did forward the public but still the gate doesnt react