SA-MP Forums Archive
[Tutorial] Creating Simple Moving Objects - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Creating Simple Moving Objects (/showthread.php?tid=355459)



Creating Simple Moving Objects - Gaurav_Rawat - 30.06.2012

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.


Re: Creating Simple Moving Objects - RoleplayEditor - 30.06.2012

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

And haha first post FTW


Re: Creating Simple Moving Objects - Jarnu - 30.06.2012

Pretty well explained bro.. Good Job! ++REP


Re: Creating Simple Moving Objects - Gaurav_Rawat - 30.06.2012

Thanks @ Jarnu and @RoleplayEditor


Re: Creating Simple Moving Objects - MA_proking - 30.06.2012

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


Re: Creating Simple Moving Objects - Lordzy - 30.06.2012

Thanks, this good tutorial


Re: Creating Simple Moving Objects - Nirzor - 30.06.2012

Great Work +REP


Re: Creating Simple Moving Objects - dino_d_carter - 30.06.2012

Thx +REP from me :P


Re: Creating Simple Moving Objects - Gaurav_Rawat - 01.07.2012

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


Re: Creating Simple Moving Objects - RoleplayEditor - 01.07.2012

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