30.06.2012, 03:47
Simple Moving Objects Tutorial
I know,You must be thinking aww..Another Moving object Tutorial..Damn make something new.
But i did tried to explain this as simpler as i could. [so please don't say the ^ line]
So i will start now
Code:
Note : I will be using ZCMD so i hope you have the include and you must define it
pawn Code:
#include <zcmd>
After you got your gate object id and position.
Copy them[We will need them soon ]
So here we start
Store a variable for gate object.
Lets say
First Step
pawn Code:
new GateOpen;//To check if the gate is opened or not
new Gate;//To save the gate variable. We will use it soon so remember it :D
new stock GateTimer; //This is used so we don't need to make two commands i.e open and close. Timer for closing
Lets get on second step !
Second Step
If you are going to create gate in your Gamemode use
public OnGameModeInit()
If you are going to create gate in a Filterscript use
public OnFilterScriptInit()
Well,I will be using *public OnFilterScriptInit()*
pawn Code:
Gate = CreateObject(modelid,Float:X,Float:Y,Float:Z,Float:rX,Float:rY,Float:rZ,Float:DrawDistance = 0.0);
modelid = the id of the object you want to create.
X, Y and Z = all of the coodinates for WHERE you want to place the object.
rX, rY and rZ = These are the rotation coordinate. What direction you want to face it and want it to move and all.
Draw Distance = how far away a player can see the object from. The max for this is 300.
It should look like this
pawn Code:
/* A example for you :)*/
public OnFilterScriptInit()
{
gate=CreateObject(987,1496.59997559,-699.75000000,93.80000305,0.00000000,0.00000000,0.00000000);
return 1;
}
Third Step
Ok Time to make the moving object work !
pawn Code:
CMD:(gate, playerid, params[])
{
if(GateOpen == 0)
{
MoveObject(Gate, newx, newy, newz, rate);/*This will move the object to a new coordinate wherever you want*/
GateOpen = 1;//It means that the gate is opened now
}
else
{
MoveObject(Gate, originalx, originaly, originalz, rate);// It is the object coordinate which you defined in Gamemodeinit/Or Filterscriptinit.
GateOpen = 0;//It won't open gate as its already opened.
}
}
else
{
SendClientMessage(playerid, color, "You are Far Away.");/*SendClientMessage is use to send a message to the client/user. Playerid=His ID , Color= What color you want the text to be displayed it.*/
}
return 1;
A example if you want to make a moving gate for your Gang or Factions etc.
pawn Code:
command(gate, playerid, params[])
{
if(IsPlayerInRangeOfPoint(playerid, 5.0(range), x, y, z))//The Range you want that player can use the command
{
if(Player[playerid][Group] == (Insert Your Gang or Faction Id)) /*Write the id or with whatever you defined them so that only they can open the gate*/
{
if(GateOpen == 0)
{
MoveObject(Gate, newx, newy, newz, rate);
GateOpen = 1;
}
else
{
MoveObject(Gate, originalx, originaly, originalz, rate);
GateOpen = 0;
}
}
else
{
SendClientMessage(playerid, color, "Command Not available.");
}
}
else
{
SendClientMessage(playerid, color, "You are not in range of the gate.");
}
return 1;
}
If you like my first tutorial ever a little even Please rep me..So it encourage me to do more and more scripting and publishing it here.