25.07.2012, 19:26
► Semi Automated Gates ◄
Introduction: Today,I'll be showing you how to make your own simple Semi-Automated Gates System.This tutorial is very simple and made for newbies with fully explaining to everything we'll be using.
Step 1: First of all, we have to get the closed gate and the opened gate's cords.
To get the cords of each gate we'll be using Map editor application, you can download the program by visiting the official topic of it, here.
Once you have downloaded it follow the instructions to install and use it and when you're done you'll be getting an object with ID 975 (The gate's ID we are going to use in this tutorial).
Once you have added it, would look like this (In this tutorial I'll be Scripting a gate at Idlewood):
Click at the top left of the page and the code will look something like:
Код:
CreateObject(975, 2053.16, -1762.77, 14.25, 0.00, 0.00, 0.00);
CreateObject: A function in the SAMP's API, used to add an Object to the actual Map of the Game/Server.
Код:
CreateObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ, Float:DrawDistance); modelid The model you want to use. Float:X The X coordinate to create the object at. Float:Y The Y coordinate to create the object at. Float:Z The Z coordinate to create the object at. Float:rX The X rotation of the object. Float:rY The Y rotation of the object. Float:rZ The Z rotation of the object. Float:DrawDistance (optional) The distance that San Andreas renders objects. 0.0 will cause objects to render at their default distances. 300.0 is the usable maximum. Usable since 0.3b. Returns The ID of the object that was created.
Once you have Mapped it, would look like:
And the code would be something like:
Код:
CreateObject(975, 2047.22, -1762.77, 14.25, 0.00, 0.00, 0.00)
First, you'll need to find OnGameModeIni();, Once you have found it add the closed gate codes under it and then it would look like:
Код:
public OnGameModeInit(){ CreateObject(975, 2053.16, -1762.77, 14.25, 0.00, 0.00, 0.00); }
Step 3: Now we'll define the variable of the gate that we'll be using.
Find #include <a_samp> in your script and under it add a new variable.
Код:
New gate;
Quote:
#include <core> #include <float> #include <string> #include <file> #include <time> #include <datagram> #include <a_players> #include <a_vehicles> #include <a_objects> #include <a_sampdb> |
Now go to the line we have added before under OnGameModeInit() and make the variable "gate" equals it.
Код:
gate=CreateObject(975, 2053.16, -1762.77, 14.25, 0.00, 0.00, 0.00);
First you'll need to find OnPlayerCommandText(playerid,cmdtext[])
Under it add this code:
Код:
if(strcmp(cmdtext,"/opengate",true)==0 || strcmp(cmdtext,"/og",true)==0){ return 1; }
Код:
strcmp(const string1[], const string2[], bool:ignorecase, length) string1 The first string to compare. string2 The second string to compare. ignorecase (optional) When set to true, the case doesn't matter - HeLLo is the same as Hello. When false, they're not the same. length (optional) When this length is set, the first x chars will be compared - doing "Hello" and "Hell No" with a length of 4 will say it's the same string. Returns -1 if string1 comes before string2 1 if string1 comes after string2 0 if the strings are the same (for the matched length).
Once we have added the base, we'll use IsPlayerInRangeOfPoint function to see if the player is in range of the gate so he won't be able to open it from a long distances.
IsPlayerInRangeOfPoint: Checks if a player is in range of a point.
Код:
IsPlayerInRangeOfPoint(playerid, Float:range, Float:x, Float:y, Float:z) playerid The ID of the player you want to check the point range of. Float:range The furthest distance the player can be to be in range. Float:x The X coordinate of the point to check the range to. Float:y The Y coordinate of the point to check the range to. Float:z The Z coordinate of the point to check the range to. Returns 1 if the player is in range of the point, otherwise 0.
Код:
if(strcmp(cmdtext,"/opengate",true)==0 || strcmp(cmdtext,"/og",true)==0){ if (IsPlayerInRangeOfPoint(playerid,30, 2053.16, -1762.77, 14.25)){ //The player is near the gate. }else{ //The player is not near the gate. } return 1; }
MoveObject: Moves an object to a new position with a set speed. Players/vehicles will 'surf' the object as it moves.
Код:
MoveObject(objectid, Float:X, Float:Y, Float:Z, Float:Speed, Float:RotX = -1000.0, Float:RotY = -1000.0, Float:RotZ = -1000.0) objectid The ID of the object to move. Float:X The X coordinate to move the object to. Float:Y The Y coordinate to move the object to. Float:Z The Z coordinate to move the object to. Float:Speed The speed at which to move the object (units per second). Float:RotX The FINAL X rotation (optional). Float:RotY The FINAL Y rotation (optional). Float:RotZ The FINAL Z rotation (optional). Returns The time it will take for the object to move in milliseconds.
Код:
if(strcmp(cmdtext,"/opengate",true)==0 || strcmp(cmdtext,"/og",true)==0){ if (IsPlayerInRangeOfPoint(playerid,30, 2053.16, -1762.77, 14.25)){ //The player is near the gate. MoveObject(gate,2053.16, -1762.77, 14.25,15); // Moves object "gate" to other point }else{ //The player is not near the gate. } return 1; }
We'll send the play error message.
Код:
if(strcmp(cmdtext,"/opengate",true)==0 || strcmp(cmdtext,"/og",true)==0){ if (IsPlayerInRangeOfPoint(playerid,30, 2053.16, -1762.77, 14.25)){ //The player is near the gate. MoveObject(gate,2053.16, -1762.77, 14.25,15); // Moves object "gate" to other point }else{ //The player is not near the gate. SendClientMessage(playerid,RED,"You are not close enough to open the gate."); } return 1; }
Код:
SendClientMessage (playerid, color, const message[]) playerid The playerid you would like to display the message for. color The color it should be in. const message[] The text you would like to display. max len displayable: 144 Returns This function doesn't return a specific value
Same steps as the open command with few changes:
Код:
if(strcmp(cmdtext,"/closegate",true)==0 || strcmp(cmdtext,"/cg",true)==0){ }
Код:
if(strcmp(cmdtext,"/closegate",true)==0 || strcmp(cmdtext,"/cg",true)==0){ if (IsPlayerInRangeOfPoint(playerid,30,2053.16, -1762.77, 14.25)){ //The player is near the gate. }else{ //The player is not near the gate. } }
Код:
if(strcmp(cmdtext,"/closegate",true)==0 || strcmp(cmdtext,"/cg",true)==0){ if (IsPlayerInRangeOfPoint(playerid,30,2053.16, -1762.77, 14.25)){ //The player is near the gate. MoveObject(gate,2053.16, -1762.77, 14.25,15); }else{ //The player is not near the gate. SendClientMessage(playerid,RED,"You are not close enough to open the gate."); } }
- TD (Me).
- SA:MP API.
Thanks for reading my tutorial,
Royal