XY infront of player -
pagie1111 - 19.10.2009
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.
Re: XY infront of player -
Think - 19.10.2009
For what do you need it and how do you use it?
Re: XY infront of player -
pagie1111 - 19.10.2009
Okay i need it to get the XY infront of a player... Obvious?
but i need it for a exposive feature for a script.
Re: XY infront of player -
Jefff - 19.10.2009
Код:
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));
}
Re: XY infront of player -
pagie1111 - 19.10.2009
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.
Re: XY infront of player -
pagie1111 - 20.10.2009
Didnt work. Bummer. Anyone else?
Re: XY infront of player -
Donny_k - 20.10.2009
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.
Re: XY infront of player -
pagie1111 - 20.10.2009
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
Re: XY infront of player -
Donny_k - 20.10.2009
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