[Tutorial] semi-automatic gates [TUT for newbies]
Hello and welcome to my first tutorial.
I decided to make this tutorial even if there are several other moving objects tutorials, after my short research there nearly no tutorials with automatically closing gates witch are in my opinion the most important.

I marked the new lines in our script with red
Lets begin:

Step 1:
At first you open your map editor to create the gate (in closed position) we will move. If you are using MTA you have to convert it into PAWN other ways it won't work. If you are using an other map editor you have to look it up in the internet how you convert it. After you had converted it it should look like this:
Код:
`CreateObject(971,2184.9,-1764.4,14.5,0,0,0);`
Код:
`CreateObject(objectid,x,y,z,rotationx,rotationy,rotationz,DrawDistance`
objectid = its the id of the object you want to add
x,y,z = are the coordinates of your object
rotation x,y,z = is the rotation of your object
DrawDistance = is the distance the object will show to a player (you can leave it blanc)

Step 2:
Now we will put the gate in our script:
Therefor we put the code we have in Step 1 under public OnGameModeInit() or if it is a Filterscript public OnFilterScriptInit()
It should look now like this:
Код:
```public OnGameModeInit ()
{
CreateObject(971,2184.9,-1764.4,14.5,0,0,0);
}```
Step 3:
define a variable for your gate, so we can easily use it. Put it under:
Код:
`#include <a_samp>`
Код:
`new gate;`
Код:
`gate=CreateObject(971,2184.9,-1764.4,14.5,0,0,0);`
Step 4:
Lets go to public OnPlayerCommandText(playerid,cmdtext[])
We will add a new cmd there with
Код:
```if(strcmp(cmdtext,"/open",true)==0)
{
return 1;
}```
It checks if the text a player entered (cmdtext) is the same we defined for our command ("/open")

Now we add what should happen if a player enter our cmd:
We want that the gate will open only if the player is in range of the gate so we add
Код:
`IsPlayerInRangeOfPoint(playerid,x,y,z,range);`
x,y,z = are the coordinates of our gate
range = is the distance the command is working (i am using 25)
Код:
```if(strcmp(cmdtext,"/open",true)==0)
{
if(IsPlayerInRangeOfPoint(playerid,2184.9,-1764.4,14.5,25);
{

}
return 1;
}```
if this is true we want the gate to move so we add for that we need the coordinates our gate will have if it fully open this will be the to x,to y, to z and the objected is the variable we had add
As speed i recommend 2 for a gate
Код:
`MoveObject(objectid,to x,to y,to z,speed);`
Код:
```if(strcmp(cmdtext,"/open",true)==0)
{
if(IsPlayerInRangeOfPoint(playerid,2184.9,-1764.4,14.5,25);
{
MoveObject(gate,2184.98,-1764.40,7.6,2);
}
return 1;
}```
Step 5:
if the player isn't in range of the gate we want to send him a message with
Код:
```if(strcmp(cmdtext,"/open",true)==0)
{
if(IsPlayerInRangeOfPoint(playerid,2184.9,-1764.4,14.5,25);
{
MoveObject(gate,2184.98,-1764.40,7.6,2);
}
else
{
SendClientMessage(playerid,BLUE,"You are not in range of the gate");
}
return 1;
}```
If we run it now and use the command in range of the gate the gate will open but not close after we passed so lets get to Step 6

Step 6:
Jump back to the location where we had add our variable (gate), there we add the timer with
Код:
`forward timergateclose ();`
Now we go back to our command where we add
Код:
`SetTimer("Name of the timer",time,repeat);`
Name of the timer = what we had add just a second ago (timergateclose)
time = the time we want i will use 10000
repeat = should the timer repeat or not (1 = it will repeat 0 = it won't)

Код:
```if(strcmp(cmdtext,"/open",true)==0)
{
if(IsPlayerInRangeOfPoint(playerid,2184.9,-1764.4,14.5,25);
{
MoveObject(gate,2184.98,-1764.40,7.6,2);
SetTimer("timergateclose",10000,0);
}
else
{
SendClientMessage(playerid,BLUE,"You are not in range of the gate");
}
return 1;
}```
Step 7:
now we will make a new public somewhere in our script it should look like this
Код:
```public timergateclose ()
{

}```
Now we have to add a new MoveObject
Код:
```public timergateclose ()
{
MoveObject(gate,2184.9,-1764.4,14.5,2)
}```
This timer we use the coordinates of the closed gate

Thats it your gate will now open if you enter the cmd and close after the timer finished
please excuse my english it isn't the best but i think you can read and understand all
if you like my tutorial and if i helped you please give me a rep Well explained, good for newbies.
9.5/10
thanks
I've seen this type of tutorial many times,but none explained well except this.
So,excellent+rep.
Im sure that this will help newbies because my cousin learned how to make movable gates.
He looked many tutorials but he learned from this only.
wow thanks man Quote:
 Originally Posted by LeOsk Hello and welcome to my first tutorial. I decided to make this tutorial even if there are several other moving objects tutorials, after my short research there nearly no tutorials with automatically closing gates witch are in my opinion the most important. I marked the new lines in our script with red Lets begin: Step 1: At first you open your map editor to create the gate (in closed position) we will move. If you are using MTA you have to convert it into PAWN other ways it won't work. If you are using an other map editor you have to look it up in the internet how you convert it. After you had converted it it should look like this: Код: `CreateObject(971,2184.9,-1764.4,14.5,0,0,0);` Код: `CreateObject(objectid,x,y,z,rotationx,rotationy,rotationz,DrawDistance` objectid = its the id of the object you want to add x,y,z = are the coordinates of your object rotation x,y,z = is the rotation of your object DrawDistance = is the distance the object will show to a player (you can leave it blanc) Step 2: Now we will put the gate in our script: Therefor we put the code we have in Step 1 under public OnGameModeInit() or if it is a Filterscript public OnFilterScriptInit() It should look now like this: Код: ```public OnGameModeInit () { CreateObject(971,2184.9,-1764.4,14.5,0,0,0); }``` Step 3: define a variable for your gate, so we can easily use it: Код: `new gate;` And add it to your CreateObject like this: Код: `gate=CreateObject(971,2184.9,-1764.4,14.5,0,0,0);` Step 4: Lets go to public OnPlayerCommandText(playerid,cmdtext[]) We will add a new cmd there with Код: ```if(strcmp(cmdtext,"/open",true)==0) { return 1; }``` It checks if the text a player entered (cmdtext) is the same we defined for our command ("/open") Now we add what should happen if a player enter our cmd: We want that the gate will open only if the player is in range of the gate so we add Код: `IsPlayerInRangeOfPoint(playerid,x,y,z,range);` x,y,z = are the coordinates of our gate range = is the distance the command is working (i am using 25) Код: ```if(strcmp(cmdtext,"/open",true)==0) { if(IsPlayerInRangeOfPoint(playerid,2184.9,-1764.4,14.5,25); { } return 1; }``` if this is true we want the gate to move so we add for that we need the coordinates our gate will have if it fully open this will be the to x,to y, to z and the objected is the variable we had add As speed i recommend 2 for a gate Код: `MoveObject(objectid,to x,to y,to z,speed);` Код: ```if(strcmp(cmdtext,"/open",true)==0) { if(IsPlayerInRangeOfPoint(playerid,2184.9,-1764.4,14.5,25); { MoveObject(gate,2184.98,-1764.40,7.6,2); } return 1; }``` Step 5: if the player isn't in range of the gate we want to send him a message with Код: ```if(strcmp(cmdtext,"/open",true)==0) { if(IsPlayerInRangeOfPoint(playerid,2184.9,-1764.4,14.5,25); { MoveObject(gate,2184.98,-1764.40,7.6,2); } else { SendClientMessage(playerid,BLUE,"You are not in range of the gate"); } return 1; }``` If we run it now and use the command in range of the gate the gate will open but not close after we passed so lets get to Step 6 Step 6: Jump back to the location where we had add our variable (gate), there we add the timer with Код: `forward timergateclose ();` Now we go back to our command where we add Код: `SetTimer("Name of the timer",time,repeat);` Name of the timer = what we had add just a second ago (timergateclose) time = the time we want i will use 10000 repeat = should the timer repeat or not (1 = it will repeat 0 = it won't) Код: ```if(strcmp(cmdtext,"/open",true)==0) { if(IsPlayerInRangeOfPoint(playerid,2184.9,-1764.4,14.5,25); { MoveObject(gate,2184.98,-1764.40,7.6,2); SetTimer("timergateclose",10000,0); } else { SendClientMessage(playerid,BLUE,"You are not in range of the gate"); } return 1; }``` Step 7: now we will make a new public somewhere in our script it should look like this Код: ```public timergateclose () { }``` Now we have to add a new MoveObject Код: ```public timergateclose () { MoveObject(gate,2184.9,-1764.4,14.5,2) }``` This timer we use the coordinates of the closed gate Thats it your gate will now open if you enter the cmd and close after the timer finished please excuse my english it isn't the best but i think you can read and understand all if you like my tutorial and if i helped you please give me a rep Great tut...but i cant understand how to make only the gang members to open if you could show me add me on fb you should create a file where the team of the player can be saved (you can do this with includes like dini or what ever) then you can write it like this:
if(strcmp(cmdtext,"/open",true)==0)#
{
if(GetPVarInt(playerid,"team")==TEAM_COP) // This is how you check if the player is a cop
{
//Here you add what i told you in the tutorial
}
return 1;
}
For those includes like dini you can find a lot of tutorials
@Starky Yakavetta
Here you go.
How to create gang gates
au·to·mat·ic/ˌфtəˈmatik/
 Originally Posted by MP2 au·to·mat·ic/ˌфtəˈmatik/ Adjective: (of a device or process) Working by itself with little or no direct human control