Moving gate with a command. -
Darnell - 22.08.2011
Moving gates - with commands.
I've seen certian people asking for that, so I thought making a little tutorial.
Functions used :
MoveObject
IsPlayerInRangeOfPoint
CreateObject
Step 1:
Let's get some coordinations for our gate, shall we ?
Let's go in-game
[ debug or any server ], go to the desired spot for the gate and simply /rs [comment].
Now, go to My Documents \ GTA SA User Files \ SAMP and open a text file named rawpositions.
In there, you'll see this :
All you need is the numbers. [ X,Y,Z ]
Step 2:
I'd rather defining my gate with a name, instead those messy object ID's.
I'd go to top of my script, under my includes, and write this :
We have defined a gate, but the script doesn't know it's a gate yet.
Under OnGameModeInIt, make the object with the coordinations you got in the start.
pawn Код:
public OnGameModeInit()
{
gate1 = CreateObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, Float:DrawDistance) //Creating the object
return 1;
}
Now we defined our gate and will be easier to use it on our command.
Step 3 :
Now let's go to
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
// Do something here
return 1;
}
return 0;
}
Now let's script out /open & /close command.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{//opening bracket
if (strcmp("/open", cmdtext, true, 5) == 0) // The /open command
{//opening bracket
if(IsPlayerInRangeOfPoint(playerid, radius, X, Y,Z))//Checking if the player in the range of the gate
{//opening bracket
MoveObject(name, X,Y, Z, speed);// Opening the gate
SendClientMessage(playerid, 0xEF994300, "The gate has opened."); //Sending a message that gate opened
}//closing bracket
return 1;
}//closing bracket
if (strcmp("/close", cmdtext, true, 6) == 0)// The /close command
{//opening bracket
if(IsPlayerInRangeOfPoint(playerid, radius, X, Y, Z))//Checking if the player in the range of the gate
{//opening bracket
MoveObject(name, X, Y, Z, speed);// Moving the gate
SendClientMessage(playerid, 0xEF994300, "The gate has closed.");//Sending a message to the one used the command
}//closing bracket
return 1;
}//closing bracket
return 0;
}//closing bracket
On our MoveObject line, we'll put the coordinations of the gate that is closed & opened, and insted of 'name' we write the name of the gate, which in this case is gate1 and speed is the speed of how fast the object would move.
Ex. :
Код:
MoveObject(gate1, X, Y, Z, speed);
Now you have a gate that will move with /open & /close, enjoy.
Re: Moving gate with a command. -
PhoenixB - 22.08.2011
Nice, about time you made a tutorial!
Re: Moving gate with a command. -
Darnell - 22.08.2011
Thanks
.
I'm not that good of a scripter anyway, lol.
Re: Moving gate with a command. -
PhoenixB - 22.08.2011
No, your good
10/10 for this tutorial, explains each function
Re: Moving gate with a command. -
Darnell - 22.08.2011
Thanks
.
Re: Moving gate with a command. -
Basicz - 22.08.2011
Thus, I prefer you to use ' /rs ' instead of ' /save ' to get positions.
save = whole AddPlayerClass
rs = rawposition ( X,Y,Z,A )
Saves at rawpositions.txt, same folder as /save
And :
pawn Код:
MoveObject(name, X, Y, Z, speed);// Moving the gate
at the close command, good explaining
at the open command,
pawn Код:
MoveObject(name, X,Y, Z, 1);// Opening the gate
What's 1 =P
Nice tutorial.
Re: Moving gate with a command. -
Darnell - 22.08.2011
Fixing, thanks.
Re: Moving gate with a command. -
alpha500delta - 22.08.2011
pawn Код:
if (strcmp("/open", cmdtext, true, 10) == 0)
/open is not 10 characters long >.<
Re: Moving gate with a command. -
Darnell - 22.08.2011
Well, 5 characters long
.
Re: Moving gate with a command. -
Naruto_Emilio - 23.08.2011
Very simple, but nice tutorial and teaching.
i suggest you to make
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/gate", cmdtext, true, 5) == 0) // The /open command
{
if(IsPlayerInRangeOfPoint(playerid, radius, X, Y,Z))//Checking if the player in the range of the gate
{
MoveObject(name, X,Y, Z, speed);// Opening the gate
SendClientMessage(playerid, 0xEF994300, "The gate has opened."); //Sending a message that gate opened
}
return 1;
}
else
{
MoveObject(name, X, Y, Z, speed);// Moving the gate
SendClientMessage(playerid, 0xEF994300, "The gate has closed.");//Sending a message to the one used the command
return 1;
}
return 0;
}
So 1 command can make 2 jobs in the same time
Re: Moving gate with a command. -
ninjahippie - 21.12.2011
Dude your amazing I will give that a try later
Now all you need to do it sort out your server 28% up time :P
Re: Moving gate with a command. -
Thresholdold - 21.12.2011
Lol starting on that now xD
Re: Moving gate with a command. -
Thresholdold - 22.12.2011
Fixed
Updated my topic to 0.3d aswell