SA-MP Forums Archive
Teleporting using coordinates - 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: Teleporting using coordinates (/showthread.php?tid=403579)



Teleporting using coordinates - Xlithan - 30.12.2012

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.


Re: Teleporting using coordinates - Chriham3 - 30.12.2012

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]");



Re: Teleporting using coordinates - Xlithan - 31.12.2012

Brilliant, thank you