In need of one stock function. - 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: In need of one stock function. (
/showthread.php?tid=439403)
In need of one stock function. -
kristo - 25.05.2013
I need this function or something similar:
pawn Код:
GetPlayerDirectionFromPoint(playerid, Float:x, Float:y, Float:z);
Could someone create it for me? Thanks.
Re: In need of one stock function. -
kristo - 26.05.2013
bump
AW: In need of one stock function. -
Blackazur - 26.05.2013
https://sampwiki.blast.hk/wiki/IsPlayerInRangeOfPoint
https://sampwiki.blast.hk/wiki/GetPlayerDistanceFromPoint
?
Re: In need of one stock function. -
kristo - 26.05.2013
I need direction, not distance.
Re: In need of one stock function. -
Pottus - 26.05.2013
You mean relative angle on the XY axis in relation to a point ?
Re: In need of one stock function. -
kristo - 27.05.2013
Umm... Possibly yes.
Re: In need of one stock function. -
MP2 - 27.05.2013
pawn Код:
stock SetPlayerLookAt(playerid, Float:x, Float:y)
{
new Float:Px, Float:Py, Float: Pa;
if(IsPlayerInAnyVehicle(playerid)) GetVehiclePos(GetPlayerVehicleID(playerid), Px, Py, Pa);
else GetPlayerPos(playerid, Px, Py, Pa);
Pa = floatabs(atan((y-Py)/(x-Px)));
if(x <= Px && y >= Py) Pa = floatsub(180, Pa);
else if(x < Px && y < Py) Pa = floatadd(Pa, 180);
else if(x >= Px && y <= Py) Pa = floatsub(360.0, Pa);
Pa = floatsub(Pa, 90.0);
if(Pa >= 360.0) Pa = floatsub(Pa, 360.0);
if(!IsPlayerInAnyVehicle(playerid)) SetPlayerFacingAngle(playerid, Pa);
else SetVehicleZAngle(GetPlayerVehicleID(playerid), Pa);
}
I did not write this function. It looks very messy and there's probably a much better way to write it - but it works.
If you don't want the function to actually set the players' angle, you could just make it return 'Pa' instead (and remember to add a Float: tag to the function).
Re: In need of one stock function. -
kristo - 27.05.2013
Very nice, thank you