[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


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)