01.07.2012, 14:53
(
Последний раз редактировалось LeOsk; 22.07.2012 в 20:05.
)
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:
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:
Step 3:
define a variable for your gate, so we can easily use it. Put it under:
And add it to your CreateObject like this:
Step 4:
Lets go to public OnPlayerCommandText(playerid,cmdtext[])
We will add a new cmd there with
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
x,y,z = are the coordinates of our gate
range = is the distance the command is working (i am using 25)
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
Step 5:
if the player isn't in range of the gate we want to send him a message with
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
Now we go back to our command where we add
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)
Step 7:
now we will make a new public somewhere in our script it should look like this
Now we have to add a new MoveObject
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
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
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); }
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);
Lets go to public OnPlayerCommandText(playerid,cmdtext[])
We will add a new cmd there with
Код:
if(strcmp(cmdtext,"/open",true)==0) { return 1; }
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);
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; }
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; }
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; }
Step 6:
Jump back to the location where we had add our variable (gate), there we add the timer with
Код:
forward timergateclose ();
Код:
SetTimer("Name of the timer",time,repeat);
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; }
now we will make a new public somewhere in our script it should look like this
Код:
public timergateclose () { }
Код:
public timergateclose () { MoveObject(gate,2184.9,-1764.4,14.5,2) }
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