[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
#2

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

This is kinda useful, but wiki ftw!
Reply
#4

awesome
Reply
#5

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.
Reply
#6

nice tutorial , gud job
Reply
#7

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);
            }
        }
    }
}
Reply
#8

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.
Reply
#9

Nice man!
Reply
#10

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
Reply
#11

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!
Reply
#12

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

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
Reply
#14

Epic
There are too much tutorials about this already
Reply
#15

Thx man
Reply
#16

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
Reply
#17

Nice TUT. !!
Reply
#18

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);
Reply
#19

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 )
Reply
#20

i did forward the public but still the gate doesnt react
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)