[Tutorial] How to make an automatic gate!
#1

Hello guys, I got bored so I said, "Why not make a simple tutorial?"
And what made me think about these gates, is that how much time it took me to know how to make them, because the tutorials I found weren't the best for this.
So let's get started!

At first, you add the Object name on the top:
pawn Код:
new Gate; // I will be calling it Gate
Now under OnGameModeInIt, we need to create the original object and the position of it,
so we will be implementing the following:
pawn Код:
Gate = CreateObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ)
// now for the modelid, I suggest 2933, 975, 971, etc, you can find many actually.
// Alright, don't forget to fill the CreateObject with what you need of course, you can do so with MTA or an editor to get the needed coordinates you are gonna use.
//The draw distance is not needed here, so u can put the X,Y,Z, rotationX, rotationY, rotationZ.

//we are gonna put a timer at what time the gate will open when ur near it.
SetTimer("TestGate", 1000, 1); //
Okay, so we're half done now.
What we need now is to see if the player is near this object, it will open it.
pawn Код:
forward TestGate();
public TestGate() // we made a public call for the timer, which we called "TestGate"
{
    new open;
    for(new i=GetMaxPlayers(); i > -1; i--) // we're making a loop here
    {
        if(IsPlayerConnected(i) && IsPlayerInRangeOfPoint(i, 10.0, Float:X, Float:Y, Float:Z))// we are checking if he's online and he's near the gate itself, at a range of 10 meters(You can change it of course)
// do not forget to change the X,Y,Z to what you want, mostly use the same coordinates as the gate's.
        {
            open = 1;
            MoveObject(Gate, NewX, NewY, NewZ, 2.0); // we checked that if he's near the gate, at 10 meters away as a max, it moves Object "Gate" to it's new position at a speed of 2.
// do not forget to change the coordinates to the new gate's coordinates, where it will move to.
            break;
        }
    }
    if(!open) // now we're checking that if it's not open and he's away from the gate, we're gonna close it back to it's old coordinates
        MoveObject(Gate, Float:X, Float:Y, Float:Z, 2.0); // do not forget to change the coordinates here too, to the original position of the gate.
       open = 0;
}
Hope I made it clear guys, if not, tell me what you didn't understand so I can help you with it!
Reply
#2

Thanks werry helpfull i hope it helps others too +REP
Reply
#3

Thanks for your feedback, hope it helped you!
PS: If you guys need a tutorial about something specific that I can help with, feel free to ask me!
Reply
#4

how can i make it only open for specific teams, example a cop?
Reply
#5

under the loop:
pawn Код:
if(IsCop(i)) { // or another function you use
Reply
#6

EDIT:

When are you setting the variable "open" back to 0?
Reply
#7

This system automatically checks that if you're not InRangeOfPoint, it will not be: open =1;
Anyway thank you for the attention, I added open = 0 at the end of the script.
Reply
#8

Quote:
Originally Posted by JimmyCh
Посмотреть сообщение
Hello guys, I got bored so I said, "Why not make a simple tutorial?"
And what made me think about these gates, is that how much time it took me to know how to make them, because the tutorials I found weren't the best for this.
So let's get started!

At first, you add the Object name on the top:
pawn Код:
new Gate; // I will be calling it Gate
Now under OnGameModeInIt, we need to create the original object and the position of it,
so we will be implementing the following:
pawn Код:
Gate = CreateObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ)
// now for the modelid, I suggest 2933, 975, 971, etc, you can find many actually.
// Alright, don't forget to fill the CreateObject with what you need of course, you can do so with MTA or an editor to get the needed coordinates you are gonna use.
//The draw distance is not needed here, so u can put the X,Y,Z, rotationX, rotationY, rotationZ.

//we are gonna put a timer at what time the gate will open when ur near it.
SetTimer("TestGate", 1000, 1); //
Okay, so we're half done now.
What we need now is to see if the player is near this object, it will open it.
pawn Код:
forward TestGate();
public TestGate() // we made a public call for the timer, which we called "TestGate"
{
    new open;
    for(new i=GetMaxPlayers(); i > -1; i--) // we're making a loop here
    {
        if(IsPlayerConnected(i) && IsPlayerInRangeOfPoint(i, 10.0, Float:X, Float:Y, Float:Z))// we are checking if he's online and he's near the gate itself, at a range of 10 meters(You can change it of course)
// do not forget to change the X,Y,Z to what you want, mostly use the same coordinates as the gate's.
        {
            open = 1;
            MoveObject(Gate, NewX, NewY, NewZ, 2.0); // we checked that if he's near the gate, at 10 meters away as a max, it moves Object "Gate" to it's new position at a speed of 2.
// do not forget to change the coordinates to the new gate's coordinates, where it will move to.
            break;
        }
    }
    if(!open) // now we're checking that if it's not open and he's away from the gate, we're gonna close it back to it's old coordinates
        MoveObject(Gate, Float:X, Float:Y, Float:Z, 2.0); // do not forget to change the coordinates here too, to the original position of the gate.
       open = 0;
}
Hope I made it clear guys, if not, tell me what you didn't understand so I can help you with it!
Can you help me? New to this gate is not understood all about it. The bottom is your download. You watch and help yourself.
Dowload: https://pastebin.com/B942CRiE
Reply
#9

Quote:
Originally Posted by BanhVo
Посмотреть сообщение
Can you help me? New to this gate is not understood all about it. The bottom is your download. You watch and help yourself.
Dowload: https://pastebin.com/B942CRiE
What the actual fuck.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)