[Help] Need help with /telep xyz
#1

OKey basically i want to make a command with zcmd like: /telep XYZ.
Example: /telep 0.0,0.0,0.0 and then it will teleport there.
I know how to make the command, but i dont know how to make cmd input to float

Heres my current code:

Код:
CMD:telep(M, params[])
{
  
	new idx;
        new xyz[256];
	

    
   
    xyz = strtok(params, idx);
    
    if(isnull(params))
	{
		Kiri(M, RED, "Hint: /telep [x,y,z]");
		return 1;
	}
	

    
	
	if(User[M][Admin] < 1338) { Kiri(M,RED,"You dont have enough permissions!"); return 1; }
	
	Kiri(M,WHITE,"* Teleported");
	SetPlayerPos(M, xyz);


	return 1;
}
Reply
#2

There is a command exactly like this in the Vortex Roleplay 2 script, I suggest downloading it and CTRL+F 'CMD:gotopoint', use it for reference.
Reply
#3

One problem, I dont want to use sscanf, so how can i make transform into normal?
Reply
#4

Quote:
Originally Posted by Andrus99
Посмотреть сообщение
One problem, I dont want to use sscanf, so how can i make transform into normal?
Well i suggest sscanf because its SO easy to make a command with that
Reply
#5

I'm an old school scripter, so i like that everything is writen out and Don't i want everything to be so easy.
Reply
#6

So can anyone help me?
Reply
#7

You have
pawn Код:
new xyz;
Use
pawn Код:
new Float:x, Float:y, Float:z;
SetPlayerPos(playerid, x, y, z);
pawn Код:
CMD:telep(M, params[])
{
    new idx;
    new Float:x, Float:y, Float:z;
       
    if(isnull(params))
    {
        Kiri(M, RED, "Hint: /telep [x,y,z]");
        return 1;
    }
    if(User[M][Admin] < 1338)
    {
        Kiri(M,RED,"You dont have enough permissions!");
        return 1;
    }
    SetPlayerPos(M, X, Y, Z);
    Kiri(M,WHITE,"* Teleported");
    return 1;
}
I don't know if it works lol
Reply
#8

Quote:
Originally Posted by Andrus99
Посмотреть сообщение
I'm an old school scripter, so i like that everything is writen out and Don't i want everything to be so easy.
Since when is using the finest tools at your disposal taboo?
You're not an old-school scripter, you're just refusing to make life easier for yourself at no expense whatsoever.
Nevertheless, here you go.(Requires some modification to detect null parameters, etc.)
Код:
CMD:telep(playerid,params[])
	{
	new idx,tmp[128];
	if(isnull(params))
		{
		return SendClientMessage(playerid,0xFFFFFFFF,"Hint: /telep x y z");
		}
	if(User[M][Admin] < 1338) {return SendClientMessage(playerid,0xFFFFFFFF,"You dont have enough permissions!");}
	new Float:X,Float:Y,Float:Z;
	strtok(tmp,idx);
	X = floatstr(tmp);
	strtok(tmp,idx);
	Y = floatstr(tmp);
	strtok(tmp,idx);
	Z = floatstr(tmp);
	SetPlayerPos(playerid,X,Y,Z);
        return 1;
	}
And just to show you how easy sscanf makes things, here's the sscanf version of it(No modification needed)
Код:
CMD:telep(playerid,params[])
	{
	new Float:X,Float:Y,Float:Z;
	if(sscanf(params,"fff",X,Y,Z)
		{
		SendClientMessage(playerid,0xFFFFFFFF,"Hint: /telep x y z");
		}
	else
		{
                 if(User[M][Admin] < 1338) {return SendClientMessage(playerid,0xFFFFFFFF,"You dont have enough permissions!");}
		SetPlayerPos(playerid,X,Y,Z);
		}
	return 1;
	}
Reply
#9

There is nothing wrong with using more practical methods like sscanf to get what you want. It wastes time, and mistakes are easy to be made. I posted this mainly because the code above me is incorrect.
pawn Код:
if(!strcmp("/gotopoint",cmdtext,true))
{
    new
        Float:x,
        Float:y,
        Float:z;
    if(sscanf(params,"fff",x,y,z))
    {
        return SendClientMessage(playerid,-1,"USAGE: /gotopoint <x> <y> <z>");
    }
    else
    {
        new string[128];
        format(string,sizeof(string),"You have teleported to coordinates: X:%f Y:%f Z:%f",x,y,z);
        SendClientMessage(playerid,-1,string);
        SetPlayerPos(playerid,x,y,z);
        return 1;
    }
}
It can me maid easily within 20 lines.(I counted)
Reply
#10

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
There is nothing wrong with using more practical methods like sscanf to get what you want. It wastes time, and mistakes are easy to be made. I posted this mainly because the code above me is incorrect.
pawn Код:
if(!strcmp("/gotopoint",cmdtext,true))
{
    new
        Float:x,
        Float:y,
        Float:z;
    if(sscanf(params,"fff",x,y,z))
    {
        return SendClientMessage(playerid,-1,"USAGE: /gotopoint <x> <y> <z>");
    }
    else
    {
        new string[128];
        format(string,sizeof(string),"You have teleported to coordinates: X:%f Y:%f Z:%f",x,y,z);
        SendClientMessage(playerid,-1,string);
        SetPlayerPos(playerid,x,y,z);
        return 1;
    }
}
It can me maid easily within 20 lines.(I counted)
I think this would make it less lines
pawn Код:
if(!strcmp("/gotopoint",cmdtext,true))
{
    new Float:x,Float:y,Float:z,string[128];
    if(sscanf(params,"fff",x,y,z)) return SendClientMessage(playerid,-1,"USAGE: /gotopoint <x> <y> <z>");
         format(string,sizeof(string),"You have teleported to coordinates: X:%f Y:%f Z:%f",x,y,z);
        SendClientMessage(playerid,-1,string);
        SetPlayerPos(playerid,x,y,z);
        return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)