SA-MP Forums Archive
[Help] Need help with /telep xyz - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [Help] Need help with /telep xyz (/showthread.php?tid=330399)



[Help] Need help with /telep xyz - Andrus99 - 01.04.2012

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;
}



Re: [Help] Need help with /telep xyz - Boooth - 01.04.2012

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.


Re: [Help] Need help with /telep xyz - Andrus99 - 01.04.2012

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


Re: [Help] Need help with /telep xyz - Tanush123 - 01.04.2012

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


Re: [Help] Need help with /telep xyz - Andrus99 - 02.04.2012

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


Re: [Help] Need help with /telep xyz - Andrus99 - 03.04.2012

So can anyone help me?


Re: [Help] Need help with /telep xyz - sjvt - 03.04.2012

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


Re: [Help] Need help with /telep xyz - blank. - 03.04.2012

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;
	}



Re: [Help] Need help with /telep xyz - ReneG - 03.04.2012

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)


Re: [Help] Need help with /telep xyz - Tanush123 - 03.04.2012

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;
}