[Tutorial] Creating Simple Moving Objects
#1

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>
Map some Gates in MTA or SAMP Map editor.
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);
For further explaining i will tell you what does modelid and all does mean and do.
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;
}
So We just created a Gate -Object ! Congratulation

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;
}
Congratulation, You just created a Moving Gate !


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.
Reply
#2

Nice for your first tutorial.
You have explained everything very well..
Here ya go kid +1 rep

And haha first post FTW
Reply
#3

Pretty well explained bro.. Good Job! ++REP
Reply
#4

Thanks @ Jarnu and @RoleplayEditor
Reply
#5

Pretty Decent work buddy.
You have explained everything very well..
+1 rep.
Reply
#6

Thanks, this good tutorial
Reply
#7

Great Work +REP
Reply
#8

Thx +REP from me :P
Reply
#9

Thank you all
And lolwat..you guys just say rep+ but as i did checked my acc..No rep has been added :S..
Reply
#10

@Gaurav_Rawat maybe they forgot to rep you ..Not a problem ..keep posting and keep getting more rep !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)