[Tutorial] Teleport command (sscanf + y_commands)
#1

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

Код:
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;
}
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.

Код:
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.
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.
Reply


Messages In This Thread
Teleport command (sscanf + y_commands) - by Denis1 - 17.04.2015, 12:39
Re: Teleport command (sscanf + y_commands) - by Karan007 - 17.04.2015, 17:28
Re: Teleport command (sscanf + y_commands) - by Jimmy0wns - 17.04.2015, 17:30
Re: Teleport command (sscanf + y_commands) - by Misiur - 17.04.2015, 17:31
Re: Teleport command (sscanf + y_commands) - by Denis1 - 18.04.2015, 14:10
Re: Teleport command (sscanf + y_commands) - by iSkyline - 18.04.2015, 17:51
Re: Teleport command (sscanf + y_commands) - by 036 - 21.06.2015, 14:13

Forum Jump:


Users browsing this thread: 1 Guest(s)