Teleporting using coordinates
#1

This command I currently have working. However, a lot of coordinates use a decimal place, if not all of them.

The command only works without the decimal place, which isn't much of a problem since it still spawns in pretty much the exact location. However, I don't like things that don't work 100% so if anybody can help me with this, that would be great.

Код:
CMD:tp(playerid, params[])
{
	if(PlayerInfo[playerid][pAdmin] < 99998) {
	    SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to use this command.");
	    return 1;
	}

    new string[128], giveplayerid, X, Y, Z;
	if(sscanf(params, "uiii", giveplayerid, X, Y, Z)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /tp [playerid] [X] [Y] [Z]");
	
	if(IsPlayerConnected(giveplayerid))
	{
	    format(string, sizeof(string), "Administrator %s has teleported you.", GetPlayerNameEx(playerid));
	    SendClientMessageEx(giveplayerid, COLOR_WHITE, string);
	    format(string, sizeof(string), "You have teleported %s.", GetPlayerNameEx(giveplayerid));
	    SendClientMessageEx(playerid, COLOR_WHITE, string);
	    SendClientMessageEx(giveplayerid, COLOR_GRAD1, "   You have been teleported!");
	    SetPlayerPos(giveplayerid, X, Y, Z);
	}
	return 1;
}
Anybody is welcome to use this code, it's VERY useful.
Reply
#2

The problem is that you are using integers, while coordinates are floats.

It should be like this:

pawn Код:
CMD:tp(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] < 99998) {
        SendClientMessageEx(playerid, COLOR_GRAD2, "You are not authorized to use this command.");
        return 1;
    }

    new string[128], giveplayerid, Float:X, Float:Y, Float:Z;
    if(sscanf(params, "ufff", giveplayerid, X, Y, Z)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /tp [playerid] [X] [Y] [Z]");
   
    if(IsPlayerConnected(giveplayerid))
    {
        format(string, sizeof(string), "Administrator %s has teleported you.", GetPlayerNameEx(playerid));
        SendClientMessageEx(giveplayerid, COLOR_WHITE, string);
        format(string, sizeof(string), "You have teleported %s.", GetPlayerNameEx(giveplayerid));
        SendClientMessageEx(playerid, COLOR_WHITE, string);
        SendClientMessageEx(giveplayerid, COLOR_GRAD1, "   You have been teleported!");
        SetPlayerPos(giveplayerid, X, Y, Z);
    }
    return 1;
}
pawn Код:
new string[128], giveplayerid, Float:X, Float:Y, Float:Z;
if(sscanf(params, "ufff", giveplayerid, X, Y, Z)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /tp [playerid] [X] [Y] [Z]");
Reply
#3

Brilliant, thank you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)