Need some help
#1

Hello. I need some help with command again. Looks like ok (no errors or warnings). When I typed /goto 0, it was ok. /goto libra (my name) worked too. But when I type /goto wbueqngiuwrhbg, it teleports me to ID 0. Could anyone solve this? (Don't tell to use sscanf )

Код:
dcmd_goto(playerid,params[])
{
	new playerid2;
	new tmp[128], Index, string[128];
	tmp = strtok(params,Index), playerid2 = strval(tmp);
	if(!strlen(params)) return SendClientMessage(playerid,red,"USAGE: /goto [ID]");
	if(!IsPlayerConnected(playerid2))return SendClientMessage(playerid,red,"ERROR: Player is not connected!");
	new Float:x,Float:y,Float:z;
	GetPlayerPos(playerid2, x, y, z);
	SetPlayerPos(playerid, x+2, y, z);
	format(string,sizeof(string),"You have teleported to %s's location!",GetName(playerid2));
	SendClientMessage(playerid,blue,string);
	format(string,sizeof(string),"Player %s has teleported to you!",GetName(playerid));
	SendClientMessage(playerid,blue,string);
	return 1;
}
Reply
#2

You can use sscanf and you won't have problems like this.

Edit: I made it quickly and in text document(I'm in school) so I'm not sure if this is gonna work.
WITH SSCANF!
pawn Код:
dcmd_goto(playerid,params[])
{
    new playerid2, string[128];
    if(!sscanf(params, "u", playerid2))
    {
        if(IsPlayerConnected(playerid2))
        {
            new Float:x,Float:y,Float:z;
            GetPlayerPos(playerid2, x, y, z);
            SetPlayerPos(playerid, x+2, y, z);
            format(string,sizeof(string),"You have teleported to %s's location!",GetName(playerid2));
            SendClientMessage(playerid,blue,string);
            format(string,sizeof(string),"Player %s has teleported to you!",GetName(playerid));
            SendClientMessage(playerid,blue,string);
        }
        else return SendClientMessage(playerid,red,"ERROR: Player is not connected!");
    }
    else return SendClientMessage(playerid,red,"USAGE: /goto [ID]");
    return 1;
}
Reply
#3

Hm, ok thanks, I will use sscanf next time...

But could you add possibility to make the command to use with /goto [player name]? I never used sscanf yet, so I don't know how to use it
Reply
#4

You see this code:
pawn Код:
if(!sscanf(params, "u", playerid2))
?

This "u" is a specifier and it gives you an advantage to use command like /goto Libra.
I meant to say that you can use both (Player ID / Player Name) with sscanf and "u" as a specifier.
Reply
#5

I tried, it said player is not connected
Reply
#6

Weird, I just tested it and it worked normally. :S
Reply
#7

Lol, it works now, I didn't do anything o.O

Anyway, thx! Beer for you
Reply
#8

Quote:
Originally Posted by Libra_PL
Посмотреть сообщение
Lol, it works now, I didn't do anything o.O

Anyway, thx! Beer for you
Haha Glad I could help ya'
Reply
#9

Yo dude, if you don't mind i tried to use your code but i stumbled in a problem.
Код:
undefined symbol "GetName"
undefined symbol "GetName"
Someone has an stock for it ?
Reply
#10

That's easy to make, you just need to get the players name and return it.

pawn Код:
stock GetName(playerid)
{
    new pName[MAX_PLAYER_NAME];
    if( IsPlayerConnected(playerid))
    {
        GetPlayerName(playerid, pName, sizeof(pName));
    }
    return pName;
}
And don't just copy/paste the code... :S
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)