17.04.2015, 12:39
(
Последний раз редактировалось Denis1; 18.04.2015 в 14:06.
)
Introduction
I've specifically designed the content of this tutorial to make your life easier. The purpose of this tutorial is not necessarily to help you create a teleport command, but also teach you how to properly design a command. The tutorial aims to catch any beginner's attention as it's mainly been done for them.
Also, I used the search function before I had made this thread, and I couldn't find a similar tutorial. Forgive me if one exists.
Prerequisite tools to create the command:
-latest version of sscanf
-y_commands (part of YSI library)
PAWN CODE AND EXPLANATION
In our case, if the input is not the one the command expects, it will not send a client message to the player who typed the command. You may add this if you want to inform the player about the correct structure.
Reason
I made this tutorial, because I have been recently asked what is the best way to make a teleport command. If you searched on ******, you would see that there are only old tutorials using outdated ways of making a simple command. I hope this one will clarify.
I've specifically designed the content of this tutorial to make your life easier. The purpose of this tutorial is not necessarily to help you create a teleport command, but also teach you how to properly design a command. The tutorial aims to catch any beginner's attention as it's mainly been done for them.
Also, I used the search function before I had made this thread, and I couldn't find a similar tutorial. Forgive me if one exists.
Prerequisite tools to create the command:
-latest version of sscanf
-y_commands (part of YSI library)
PAWN CODE AND EXPLANATION
Код:
CMD:teleport(playerid, params[]) { new Float:x, Float:y, Float:z, interiorid; // the coordinates will be stored in the x, y, z float variables, and the interior id will be stored inside the 'interiorid' variable; sscanf(params, "fffi", x, y, z, interiorid); // we use sscanf to unformat our params; /* // params(a.k.a. input) is the string we extract data from; "fffi" tells sscanf about the structure of the input data - i.e. what things we expect it to contain and in what order; the order of the data in the input string is determined by these letters; In conclusion, sscanf extracts data from the given string and stores that data in the specified variables; each data is delimited by literally a space button; In our case, the first specifier "f" holds x's value; */ SetPlayerPos(playerid, x, y, z); // it sets the player's position SetPlayerInterior(playerid, interiorid); // it sets the player's interior return 1; }
Код:
if(sscanf(params, "fffi", x, y, z, interiorid)) return SendClientMessage(playerid, -1, "USAGE: /teleport [x] [y] [z], [interiorid]"); // besides what was written in the first code sample, it also checks if the params are correctly used; if they are not, a client message will be sent to the player.
I made this tutorial, because I have been recently asked what is the best way to make a teleport command. If you searched on ******, you would see that there are only old tutorials using outdated ways of making a simple command. I hope this one will clarify.