22.08.2011, 12:47
(
Последний раз редактировалось Darnell; 22.08.2011 в 19:33.
)
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 :
pawn Код:
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 :
pawn Код:
new gate1;
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;
}
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;
}
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
Ex. :
Код:
MoveObject(gate1, X, Y, Z, speed);