CreateObject(971,2184.9,-1764.4,14.5,0,0,0);
CreateObject(objectid,x,y,z,rotationx,rotationy,rotationz,DrawDistance
public OnGameModeInit ()
{
CreateObject(971,2184.9,-1764.4,14.5,0,0,0);
}
#include <a_samp>
new gate;
gate=CreateObject(971,2184.9,-1764.4,14.5,0,0,0);
if(strcmp(cmdtext,"/open",true)==0)
{
return 1;
}
IsPlayerInRangeOfPoint(playerid,x,y,z,range);
if(strcmp(cmdtext,"/open",true)==0)
{
if(IsPlayerInRangeOfPoint(playerid,2184.9,-1764.4,14.5,25);
{
}
return 1;
}
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(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;
}
forward timergateclose ();
SetTimer("Name of the timer",time,repeat);
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;
}
public timergateclose ()
{
}
public timergateclose ()
{
MoveObject(gate,2184.9,-1764.4,14.5,2)
}
|
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 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: Код:
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 ![]() |
|
au·to·mat·ic/ˌфtəˈmatik/
Adjective: (of a device or process) Working by itself with little or no direct human control |