[Include] [INC] a_angles
#21

Thanks alot
Reply
#22

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);
}
?
Reply
#23

thanks too much this is what i was looking for !!!!!!!
Reply
#24

@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...
Reply
#25

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

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"
Reply
#27

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;

}
Reply
#28

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

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.
Reply
#30

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.
Reply
#31

Awesome!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)