AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [STOCK] Target is exist in client's angle and distance (03/07/2013 Ver 1.1) (https://forums.alliedmods.net/showthread.php?t=210080)

Guren 03-06-2013 04:06

[STOCK] Target is exist in client's angle and distance (03/07/2013 Ver 1.1)
 
2 Attachment(s)
i made this function cuz i want make skills like a league of legends.

Thanks to javalia. (helped to solve my question)


Update log
03 07 2013 - Changed function name, add to negativeangle


Code:

stock bool:IsTargetInSightRange(client, target, Float:angle=90.0, Float:distance=0.0, bool:heightcheck=true, bool:negativeangle=false)
{
        if(angle > 360.0 || angle < 0.0)
                ThrowError("Angle Max : 360 & Min : 0. %d isn't proper angle.", angle);
        if(!isClientConnectedIngameAlive(client))
                ThrowError("Client is not Alive.");
        if(!isClientConnectedIngameAlive(target))
                ThrowError("Target is not Alive.");
               
        decl Float:clientpos[3], Float:targetpos[3], Float:anglevector[3], Float:targetvector[3], Float:resultangle, Float:resultdistance;
       
        GetClientEyeAngles(client, anglevector);
        anglevector[0] = anglevector[2] = 0.0;
        GetAngleVectors(anglevector, anglevector, NULL_VECTOR, NULL_VECTOR);
        NormalizeVector(anglevector, anglevector);
        if(negativeangle)
                NegateVector(anglevector);

        GetClientAbsOrigin(client, clientpos);
        GetClientAbsOrigin(target, targetpos);
        if(heightcheck && distance > 0)
                resultdistance = GetVectorDistance(clientpos, targetpos);
        clientpos[2] = targetpos[2] = 0.0;
        MakeVectorFromPoints(clientpos, targetpos, targetvector);
        NormalizeVector(targetvector, targetvector);
       
        resultangle = RadToDeg(ArcCosine(GetVectorDotProduct(targetvector, anglevector)));
       
        if(resultangle <= angle/2)       
        {
                if(distance > 0)
                {
                        if(!heightcheck)
                                resultdistance = GetVectorDistance(clientpos, targetpos);
                        if(distance >= resultdistance)
                                return true;
                        else
                                return false;
                }
                else
                        return true;
        }
        else
                return false;
}


zipcore 03-06-2013 07:45

Re: [STOCK] Target is exist in client's angle and distance
 
cool, good job

Franc1sco 03-06-2013 08:17

Re: [STOCK] Target is exist in client's angle and distance
 
Nice, very useful

Bimbo1 04-06-2013 11:54

Re: [STOCK] Target is exist in client's angle and distance (03/07/2013 Ver 1.1)
 
it's pretty cool! but it doesn't check whether there is an obstacle between the two players or not, does it? well, since cassiopeia's ult doesn't do that too, i guess it's fine.
@edit: oh, since i think that you would be using this several times to detect all the players that are in range of someone, you would like to have it optimized. so, i recommend you using the third parameter of GetVectorDistance set as true, which will return a value without square rooting and, then, square the distance of your function. square rooting isn't as easy as a multiplication. also, checking the distance vector between the two players before doing anything else would be nice too, because it wouldn't do the angle calculation unnecessarily. if resultdistance(squared) is > distance(squared), nothing else matters, return it false right away.

friagram 04-06-2013 17:10

Re: [STOCK] Target is exist in client's angle and distance (03/07/2013 Ver 1.1)
 
Should make it draw tes too o:

Guren 04-29-2013 03:18

Re: [STOCK] Target is exist in client's angle and distance (03/07/2013 Ver 1.1)
 
Quote:

Originally Posted by Bimbo1 (Post 1927439)
it's pretty cool! but it doesn't check whether there is an obstacle between the two players or not, does it? well, since cassiopeia's ult doesn't do that too, i guess it's fine.
@edit: oh, since i think that you would be using this several times to detect all the players that are in range of someone, you would like to have it optimized. so, i recommend you using the third parameter of GetVectorDistance set as true, which will return a value without square rooting and, then, square the distance of your function. square rooting isn't as easy as a multiplication. also, checking the distance vector between the two players before doing anything else would be nice too, because it wouldn't do the angle calculation unnecessarily. if resultdistance(squared) is > distance(squared), nothing else matters, return it false right away.


i'll be fix. i'm a trial period now. :( so i don't have a many times.

ImACow 02-28-2019 14:03

Re: [STOCK] Target is exist in client's angle and distance (03/07/2013 Ver 1.1)
 
Thanks for this

Found this by google'ing client view cone

SZOKOZ 03-03-2019 05:07

Re: [STOCK] Target is exist in client's angle and distance (03/07/2013 Ver 1.1)
 
I've made a stock like this too. The only problem with this and mine is that it does not take into account the different yaw and pitch angles of a clients fov which will lead to false positives. (e.g. A players fov might be 70 degrees but due to their resolution their yaw angle will be different thus they do not truly see 70 degrees in both axis)
I've had a couple ideas to increase the accuracy but none were satisfactory for me. I guess it all depends on how accurate you want it to be. There's even obstruction by models to consider where as using its bounding box to check if there is true obstruction may not even work if the model in question has collision via vphysics. GGWP Summoner.

Edison1318 05-28-2019 20:53

Re: [STOCK] Target is exist in client's angle and distance (03/07/2013 Ver 1.1)
 
Not sure if this thread is still alive, I was thinking that if someone would able to code it that it look on sight correctly that is not behind the walls, and also while not looking up or downwards

`666 12-04-2019 08:10

Re: [STOCK] Target is exist in client's angle and distance (03/07/2013 Ver 1.1)
 
Thank you very much. Was very useful for me.


All times are GMT -4. The time now is 15:13.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.