In need of one stock function.
#1

I need this function or something similar:

pawn Код:
GetPlayerDirectionFromPoint(playerid, Float:x, Float:y, Float:z);
Could someone create it for me? Thanks.
Reply
#2

bump
Reply
#3

https://sampwiki.blast.hk/wiki/IsPlayerInRangeOfPoint
https://sampwiki.blast.hk/wiki/GetPlayerDistanceFromPoint

?
Reply
#4

I need direction, not distance.
Reply
#5

You mean relative angle on the XY axis in relation to a point ?
Reply
#6

Umm... Possibly yes.
Reply
#7

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).
Reply
#8

Very nice, thank you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)