09.04.2012, 20:28
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>
Step #2 - The Setup
Code:
new GateOpen; new Gate; new stock GateTimer;
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; }
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; }
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; }
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; }