[Tutorial] Tutorial #1 - Creating Moving Objects (With commands)
#1

Creating Moving Objects


Hello, i am RBCRP and i'm going to be creating a tutorial on how to create moving objects such as gates and doors. Also, i am going to teach you how to make these objects move when activating a command. The object that i will be creating and moving with a command today will be a gate. This is useful for things such as police garages, paytoll centers, and even personal gates for houses on your server. The reason i am going to be tutoring about this is because having moving objects on your server can bring forth a very professional look, because, rather than just deleting and re-creating an object, moving it is much more realistic. Okay, let's get started.
Thing's you will need before performing these actions (My Way):
In order to create the command that i will be creating, you will be using the command processing include known as ZCMD.
You will need the scripting program known as Pawno in order to perform this. This comes in the SAMP script package located at sa-mp.com on the downloads page.
And last but most importantly, you will need Incognito's Streamer, this streamer will allow you to create dynamic objects, as well as move them. Without this it makes it difficult to perform actions the way i do.

Okay, so lets get started with the scripting...

Step #1 - Includes and Defines:
Code:
#include <zcmd>
#include <streamer>
you will need to include this code at the top of your script. These includes allow you to script using ZCMD, as well as create dynamic objects. These are very important when scripting dynamic objects. You will also need to define MAX_PLAYERS in order to do this.


Step #2 - The Setup
Code:
new GateOpen;
new Gate;

new stock GateTimer;
This code will allow you to check and see if the gate is already opened or not, and send a message if it is. Also, the stock will allow you to create a timer with the id of 'GateTimer'. This will be displayed later on in the tutorial. Also, the code 'new Gate;' will allow the player to create an object with the ID of 'Gate'. This will also be displayed later in the tutorial.

Step #3 - OnGameModeInit
Code:
public OnGameModeInit()
{
     Gate = CreateDynamicObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, Float:DrawDistance);
     return 1;
}
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 = all of the ROTATION coordinates for the object. What direction you want to face it, ect.
Draw Distance = how far away a player can see the object from. The max for this is 300.

Step #4 = Creating the Command to Move the Object
Code:
command(gate, playerid, params[])
{
     if(GateOpen == 0)
     {
          MoveObject(Gate, newx, newy, newz, rate);
          GateOpen = 1;
     }
     else
     {
          MoveObject(Gate, originalx, originaly, originalz, rate);
          GateOpen = 0;
     }
     return 1;
}
This code will check and see if the gate is closed, and if it is. It will move it to the coordinates 'newx, newy, newz'. But, if it is already opened, it will move the gate back to it's original position, which was stated above 'OnGameModeInit()'. But, if you only wan't a certain person to use this code, you can change the code to something such as...
Code:
command(gate, playerid, params[])
{
     if(Player[playerid][Group] == (insertnumberhere)) //Vortex Roleplay 1 Example.
     {
          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 unavailable.");
     }
     return 1;
}
Also, if you want to only make a player be able to use a command at a certain position. You can change the code again and add it to look like this.
Code:
command(gate, playerid, params[])
{
     if(IsPlayerInRangeOfPoint(playerid, 5.0(range), x, y, z))
     {
          if(Player[playerid][Group] == (insertnumberhere)) //Vortex Roleplay 1 Example.
          {
               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 unavailable.");
          }
     }
     else
     {
          SendClientMessage(playerid, color, "You are not in range of the gate.");
     }
     return 1;
}
Thank you for reading my tutorial. Again i am RBCRP and i am new to this tutorial thing. So if you have any suggestings or changes i can make to make this more useful please tell me. But i'm sure that if you follow through this tutorial you can create great things. Also, the MoveObject is how you move the object to the next position instead of just deleting and re-creating the object. Thanks again. If you have any questions please feel free to ask them. Also, if you need another tutorial for anything please ask, and ill do my best to explain.
Reply
#2

Usefull and helpful this is the most helpful tutorial i found about this. Thank you.
Reply
#3

Good tutorial I think this will be useful.
Reply
#4

It's really good for new scripters. Can you make a tutorial for teaching people how to make entrance/exits of interiors?
Reply
#5

I didnt understand anything where can i just find a [FS] for this
Reply
#6

... delete
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)