[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
#2

Sscanf has been removed and can no longer be used.
Reply
#3

Quote:
Originally Posted by karan007
Посмотреть сообщение
Sscanf has been removed and can no longer be used.
It has probably been redistributed on a GitHub page somewhere, a simple search will do the job.
Reply
#4

Life, uh, finds a way.
Reply
#5

The tutorial was rather done in a hurry, so I ask anyone, who finds any mistakes, to drop a reply.
Reply
#6

I don't know why, but I always regret reading tutorials like this. I mean like, what's that point used manning a whole new thread just to show how to create a simple command? It's not like I'm being offensive to your powder, but this really pisses me off.
But anyways, I'm no-one to judge someone's thinking. Nice job, nonetheless.
Reply
#7

There are much better tutorials then this.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)