SA-MP Forums Archive
[Include] [INC] a_angles - 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: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] [INC] a_angles (/showthread.php?tid=105568)

Pages: 1 2


Re: [INC] a_angles - acade - 25.02.2010

Thanks alot


Re: [INC] a_angles - M0R0JR - 10.10.2010

Hmm, for SetPlayerToFacePlayer:
pawn Код:
stock SetPlayerToFacePlayer(playerid, targetid)
{

    new Float:pX,Float:pY,Float:pZ,
        Float:X,Float:Y,Float:Z,
        Float:ang;
    if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetid)) return 0;
    GetPlayerPos(targetid, X, Y, Z);
    GetPlayerPos(playerid, pX, pY, pZ);
    if( Y > pY ) ang = (-acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
    else if( Y < pY && X < pX ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 450.0);
    else if( Y < pY ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
    if(X > pX) ang = (floatabs(floatabs(ang) + 180.0));
    else ang = (floatabs(ang) - 180.0);
    SetPlayerFacingAngle(playerid, ang);
}
Was that so hard to do:
pawn Код:
stock SetPlayerToFacePlayer(playerid,targetid)
{
    new Float:a[2];
    GetPlayerFacingAngle(playerid,a[0]);
    GetPlayerFacingAngle(playerid,a[1]);
   
    SetPlayerFacingAngle(targetid,a[0]+180.0);
}
?


Re: [INC] a_angles - JulietaZ - 10.10.2010

thanks too much this is what i was looking for !!!!!!!


Re: [INC] a_angles - Mauzen - 10.10.2010

@morojr: SetPlayerToFacePlayer makes one player look in the direction of another one. All that your code does, is to set the targetplayers angle to the opposite of the player's...


Re: [INC] a_angles - M0R0JR - 10.10.2010

Yes, that's right, because i used + 180.0, but if i don't use + 180.0, isn't the same thing ?


Re: [INC] a_angles - Dirkon - 26.12.2010

what is targetid? how to define it? because I get error like this:
C:\Users\user\Desktop\New folder (9)\gamemodes\lol.pwn(456) : error 017: undefined symbol "targetid"


Re: [INC] a_angles - cyber_punk - 26.12.2010

Quote:
Originally Posted by Dirkon
Посмотреть сообщение
what is targetid? how to define it? because I get error like this:
C:\Users\user\Desktop\New folder (9)\gamemodes\lol.pwn(456) : error 017: undefined symbol "targetid"
targetid is usually referring to the target of the playerid for example SetPlayerToFacePlayer(playerid, targetid); or SetPlayerToFacePlayer(0, 1); sets player 0 to face player 1. Get it?



In other news... I do have a recently updated version that will be MILES faster over the older one. I will have to get Tannz0rz to update the first post.....but this one uses atan2 and should be in workin order (I think....)


Crap seems you can't attach .inc files in forums posts well just copy this over the old code.....

pawn Код:
//a_angles.inc
//Geometric angle functions
//Created by:
//Tannz0rz

#if defined _a_angles_included
  #endinput
#endif
#define _a_angles_included

#include <a_samp>

stock IsPlayerBehindPlayer(playerid, targetid, Float:dOffset)
{

    new
        Float:pa,
        Float:ta;

    if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetid)) return 0;
   
    GetPlayerFacingAngle(playerid, pa);
    GetPlayerFacingAngle(targetid, ta);
   
    if(AngleInRangeOfAngle(pa, ta, dOffset) && IsPlayerFacingPlayer(playerid, targetid, dOffset)) return true;

    return false;

}

stock SetPlayerToFacePlayer(playerid, targetid)
{

    new
        Float:pX,
        Float:pY,
        Float:pZ,
        Float:X,
        Float:Y,
        Float:Z,
        Float:ang;

    if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetid)) return 0;

    GetPlayerPos(targetid, X, Y, Z);
    GetPlayerPos(playerid, pX, pY, pZ);

    ang = 180.0-atan2(pX-X,pY-Y);

    SetPlayerFacingAngle(playerid, ang);

    return 1;

}

stock IsPlayerFacingPlayer(playerid, targetid, Float:dOffset)
{

    new
        Float:pX,
        Float:pY,
        Float:pZ,
        Float:pA,
        Float:X,
        Float:Y,
        Float:Z,
        Float:ang;

    if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetid)) return 0;

    GetPlayerPos(targetid, pX, pY, pZ);
    GetPlayerPos(playerid, X, Y, Z);
    GetPlayerFacingAngle(playerid, pA);
   
    ang = atan2(pX-X,pY-Y);

    if(AngleInRangeOfAngle(-ang, pA, dOffset)) return true;

    return false;

}

stock AngleInRangeOfAngle(Float:a1, Float:a2, Float:range)
{

    a1 -= a2;
    if((a1 < range) && (a1 > -range)) return true;

    return false;

}



Re: [INC] a_angles - justsomeguy - 27.12.2010

okey i'm scripter noob but what is this exacly?


Re: [INC] a_angles - Dirkon - 27.12.2010

I don't really get it.. I'm trying to do, that when player looks at other player and presses middle mouse button and then at targets position create explosion. I'm doing it like this:

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if (PRESSED( KEY_LOOK_BEHIND ))
{
if(IsPlayerFacingPlayer(playerid, targetid, 15.0))
{
new Float: x, Float: y, Float: z;
GetPlayerPos(targetid, x, y, z);
CreateExplosion(x, y, z, 12, 10);
}
}
return 1;
}

What's wrong?
sorry for bad english.


Re: [INC] a_angles - cyber_punk - 27.12.2010

Quote:
Originally Posted by Dirkon
Посмотреть сообщение
I don't really get it.. I'm trying to do, that when player looks at other player and presses middle mouse button and then at targets position create explosion. I'm doing it like this:

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if (PRESSED( KEY_LOOK_BEHIND ))
{
if(IsPlayerFacingPlayer(playerid, targetid, 15.0))
{
new Float: x, Float: y, Float: z;
GetPlayerPos(targetid, x, y, z);
CreateExplosion(x, y, z, 12, 10);
}
}
return 1;
}

What's wrong?
sorry for bad english.
Yea thats not going to work, might I suggest finding the Function GetClosestPlayer and GetDistanceToPlayer your going to have to find the targetid.....you can use those functions to do so and then you can check if playerid is facing the targetid.


Re: [INC] a_angles - yanir3 - 28.05.2013

Awesome!