[Tutorial] How to fix onplayerclickmap function
#1

This is how to fix the problem when the position is so far from player and the z coordinate is 0,without using any plugins.
Код:
new bool:ClickedOnMap[MAX_PLAYERS] = false;
public OnPlayerClickMap(playerid, Float:fX, Float:fY, Float:fZ)
{
    SetPlayerPos(playerid, fX, fY, 550);
    GameTextForPlayer(playerid,"Teleporting",1000,4);
    ClickedOnMap[playerid] = true;

    return 1;
}
public OnPlayerUpdate(playerid)
{
	if(ClickedOnMap[playerid] == true)
	{
		new Float:p[3];
		GetPlayerPos(playerid,p[0],p[1],p[2]);
		SetPlayerPosFindZ(playerid,p[0],p[1],p[2]);
		KillTimer(TelTimer[playerid]);
		TogglePlayerControllable(playerid, true);
		ClickedOnMap[playerid] = false;
	}
	return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
    ClickedOnMap[playerid] = false;
}
I hope its usefull
Reply
#2

SetPlayerPosFindZ isn't even a valid function.

You can make this in a way better way.
Reply
#3

Quote:
Originally Posted by Kevln
Посмотреть сообщение
SetPlayerPosFindZ isn't even a valid function.

You can make this in a way better way.
Its is valid sir. (from a_players.inc)
Quote:

native SetPlayerPos(playerid, Float:x, Float:y, Float:z);
native SetPlayerPosFindZ(playerid, Float:x, Float:y, Float:z);
native GetPlayerPos(playerid, &Float:x, &Float:y, &Float:z);

OT: Just use SetPlayerPosFindZ under the callback, instead of making it complex like your code.
Reply
#4

Or just use mapandreas.
Reply
#5

Quote:
Originally Posted by Gammix
Посмотреть сообщение
OT: Just use SetPlayerPosFindZ under the callback, instead of making it complex like your code.
https://sampwiki.blast.hk/wiki/SetPlayerPosFindZ

Quote:
Originally Posted by wiki
This function does not work if the new coordinates are far away from where the player currently is. The Z height will be 0, which will likely put them underground.
He uses SetPlayerPos a few milliseconds before SetPlayerPosFindZ to make this work properly.

Quote:
Originally Posted by Kar
Посмотреть сообщение
Or just use mapandreas.
SetPlayerPosFindZ has a pro over MapAndreas:

Quote:
Originally Posted by wiki
This sets the players position then adjusts the players z-coordinate to the nearest solid ground under the position.
While MapAndreas always gives the position of the ground.
Reply
#6

Quote:
Originally Posted by kvann
Посмотреть сообщение
Use SetPlayerPos first and SetPlayerPosFindZ after that. I think that would work.
Reply
#7

Quote:
Originally Posted by Gammix
Посмотреть сообщение
Use SetPlayerPos first and SetPlayerPosFindZ after that. I think that would work.
I tried that but it doesn't give the right z coordinates
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)