[Tutorial] ZCMD:how to make a teleport command (x,y,z)
#1

What do you need?

sscanf2 by y_less:https://sampforum.blast.hk/showthread.php?tid=120356
zcmd by zeex :https://sampforum.blast.hk/showthread.php?tid=91354

Ok Let's start by opening the pawno:
first of all we need to add the float x,y,z,the name of the command and the interior,let's name it teleport:
pawn Code:
CMD:teleport(playerid,params[])//the command
{//first bracket
new Float:x;//pos x
new Float:y;//pos y
new Float:z;//pos z
new interior;//the interior
now we want to make an error , or a message to the player if he didn't type the command correctly! so let's add:
pawn Code:
CMD:teleport(playerid,params[])//the command
{//first bracket
new Float:x;//pos x
new Float:y;//pos y
new Float:z;//pos z
new interior;//the interior
if(sscanf(params,"fffi", Float:x, Float:y, Float:z,interior)) return SendClientMessage(playerid, -1,"{FF0000}Error:{FFFFFF}/teleport [x] [y] [z] [interior]");//the message
Now we gonna make a message to that player to tell him that he got teleported to a coordinates x,y,z
pawn Code:
CMD:teleport(playerid,params[])//the command
{//first bracket
new Float:x;//pos x
new Float:y;//oos y
new Float:z;//pos z
new interior;
new string[128];//the message string
if(sscanf(params,"fffi", Float:x, Float:y, Float:z,interior)) return SendClientMessage(playerid, -1,"{FF0000}Error:{FFFFFF}/teleport [x] [y] [z] [interior]");//the message
format(string,sizeof(string),"You have been teleported to coordinates: %.0f.%.0f.%.0f",x,y,z);//this is the format for our message
SendClientMessage(playerid,-1,string);//now let's send him this message with the coordinates!
now we want to finish this command so we are going to type return 1; (so we will not get unkown command)
and close our command bracket
pawn Code:
CMD:teleport(playerid,params[])//the command
{//first bracket
new Float:x;//pos x
new Float:y;//oos y
new Float:z;//pos z
new interior;

new string[128];//the message string
if(sscanf(params,"fffi", Float:x, Float:y, Float:z,interior)) return SendClientMessage(playerid, -1,"{FF0000}Error:{FFFFFF}/teleport [x] [y] [z] [interior]");//the message
format(string,sizeof(string),"You have been teleported to coordinates: %.0f.%.0f.%.0f interior: %d",x,y,z,interior);//this is the format for our message
SendClientMessage(playerid,-1,string);//now let's send him this message with the coordinates!
SetPlayerInterior(playerid,interior);//now we will set the player interior
SetPlayerPos(playerid,Float:x,Float:y,Float:z);//now let's teleport him to this pos!
return 1;
}
So let me test it in game
let's say that i want to go to :
1681.9612,-2281.1660,13.5126
but i didn't type the coordinates very well:
like i typed 1681.9612 -2281.1660 but didn't write the z:13.5126 or I did type the cordinates but didnt type the interior:
this error will be shown:
Reply
#2

Could you please re-size the pictures because they are so large? And add a little bit more explanation so that the newbies understand it better.
Reply
#3

yes sure i am going to resize it and will explain more..
Reply
#4

Reply
#5

am.. what's wrong?
Reply
#6

Nothing, Good Job
Reply
#7

- The tag is "Float:" not "float" - that would give warning about tag mismatch.
- The max length for a client message is 144 so using 256 goes waste.
- Coordinates are floating point numbers, so use the placeholder "%f" instead of "%d" which is for integers. If you don't want to display the demical places, then use "%.0f" instead.
Reply
#8

Can you add with interior to?
Reply
#9

Making a tutorial of how to teleport to a certain player or location would be more logical, cause you won't be remembering all xyz coordinates for the certain locations. And you need to explain more about sscanf and what hte logic behind your code is. But you probably made a x y z tutorial cause you probably thought htere are too many tutorials about teleporting to players or locs...
Reply
#10

Quote:
Originally Posted by Konstantinos
View Post
- The tag is "Float:" not "float" - that would give warning about tag mismatch.
- The max length for a client message is 144 so using 256 goes waste.
- Coordinates are floating point numbers, so use the placeholder "%f" instead of "%d" which is for integers. If you don't want to display the demical places, then use "%.0f" instead.
edited and fixed ty.
Quote:
Originally Posted by JuanStone
View Post
PHP Code:
warning 213tag mismatch
warning 213
tag mismatch
warning 213
tag mismatch 
pawn Code:
new Float:x, Float:y, Float:z;

new string[ 128 ]; // Maximum characters per line
Fixed it already, ty for telling.
Quote:
Originally Posted by NaClchemistryK
View Post
Making a tutorial of how to teleport to a certain player or location would be more logical, cause you won't be remembering all xyz coordinates for the certain locations. And you need to explain more about sscanf and what hte logic behind your code is. But you probably made a x y z tutorial cause you probably thought htere are too many tutorials about teleporting to players or locs...
Well I just wanted a new thing.
Quote:
Originally Posted by Roddan
View Post
Can you add with interior to?
I added it Roddan.
Quote:
Originally Posted by satafinix
View Post
Nothing, Good Job
Ty dude
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)