XY infront of player
#1

Hello. Someone ages ago gave me this function:

pawn Код:
stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{

    new Float:a;
    GetPlayerFacingAngle(playerid, a);
    a -= 90;

    y += (distance * floatsin(a, degrees));
    x += (distance * floatcos(a, degrees));
}
but no matter where i am or which way i am facing it always points to the north area OFF the map :S. even with 5.00 distance.


Help it muchly apprectiated.
Reply
#2

For what do you need it and how do you use it?
Reply
#3

Okay i need it to get the XY infront of a player... Obvious?


but i need it for a exposive feature for a script.
Reply
#4

Код:
stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
	new Float:a;
	GetPlayerFacingAngle(playerid, a);
	x += (distance * floatsin(-a, degrees));
	y += (distance * floatcos(-a, degrees));
}
Reply
#5

I hope that will make it work. If it does, you have just helped Enemy Plus fix the biggest bug in our scripts and you will make me very happy.
Reply
#6

Didnt work. Bummer. Anyone else?
Reply
#7

Show us where you use it (code snippet).

Also before you do that, make sure you are passing a 'Float' type as the distance, if you mess up the types and push an integer then it will be a huge distance.
Reply
#8



pawn Код:
if (strcmp("/strike", cmdtext, true, 7) == 0)
    {

      if(AirStrike[playerid] == 1)
        {
          new Float:X, Float:Y;
          new Float:PX, Float:PY, Float:PZ;
          GetPlayerPos(playerid,PX,PY,PZ);
          GetXYInFrontOfPlayer(playerid,X,Y,20);
          SetPlayerVirtualWorld(playerid, 1);
          SetPlayerCameraPos(playerid,PX,PY,PZ + 10.00);
            SetPlayerCameraLookAt(playerid,X,Y,PZ);
            TogglePlayerControllable(playerid,0);
            SetPlayerCheckpoint(playerid, X, Y, PZ, 3.00);
        }
        else
        {
          SendClientMessage(playerid,MAROON,"Airstrikes not available");
        }
        return 1;
    }
Thanks
Reply
#9

pawn Код:
new Float:PX, Float:PY, Float:PZ;
GetPlayerPos(playerid,PX,PY,PZ); //get current pos
SetPlayerCameraPos(playerid,PX,PY,PZ + 10.00); //set camera to current pos plus 10 on the z axis
GetXYInFrontOfPlayer(playerid,PX,PY,20); //do math to work out 20 units infront of the players x,y axes
SetPlayerCheckpoint(playerid, PX, PY, PZ, 3.00); //set the checkpoint 20 units infront (above math)
SetPlayerCameraLookAt(playerid,PX,PY,PZ); //look at 20 units infront (above math)
SetPlayerVirtualWorld(playerid, 1); //blah
TogglePlayerControllable(playerid,0); //blah
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)