Raised This Month: $68 Target: $400
 17% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Guren
Senior Member
Join Date: Feb 2011
Location: Equestria, Ponyville
Old 03-06-2013 , 04:06   [STOCK] Target is exist in client's angle and distance (03/07/2013 Ver 1.1)
Reply With Quote #1

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;
}
Attached Thumbnails
Click image for larger version

Name:	?????.jpg
Views:	819
Size:	55.1 KB
ID:	116688  
Attached Files
File Type: inc IsTargetInSightRange.inc (1.6 KB, 286 views)
__________________

Nick : Chamamyungsu // Korean Brony

Last edited by Guren; 03-06-2013 at 10:09. Reason: Updated
Guren is offline
zipcore
Veteran Member
Join Date: Mar 2010
Location: m_flZipcore
Old 03-06-2013 , 07:45   Re: [STOCK] Target is exist in client's angle and distance
Reply With Quote #2

cool, good job
zipcore is offline
Franc1sco
Veteran Member
Join Date: Oct 2010
Location: Spain (Madrid)
Old 03-06-2013 , 08:17   Re: [STOCK] Target is exist in client's angle and distance
Reply With Quote #3

Nice, very useful
__________________
Veteran SourceMod Coder -> Activity channel
I dont accept more paid request, here why. If you want my private help then you could get it for free, just ask me on steam

You like my work? Drop a +Rep in my steam profile comments

Franc1sco is offline
Send a message via MSN to Franc1sco Send a message via Skype™ to Franc1sco
Bimbo1
Senior Member
Join Date: Jan 2010
Location: brazil
Old 04-06-2013 , 11:54   Re: [STOCK] Target is exist in client's angle and distance (03/07/2013 Ver 1.1)
Reply With Quote #4

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.
__________________
sie sind das essen und wir sind die jäger!

Last edited by Bimbo1; 04-06-2013 at 17:09.
Bimbo1 is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 04-06-2013 , 17:10   Re: [STOCK] Target is exist in client's angle and distance (03/07/2013 Ver 1.1)
Reply With Quote #5

Should make it draw tes too o:
__________________
Profile - Steam Group - Plugins - Blog - Donate
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Guren
Senior Member
Join Date: Feb 2011
Location: Equestria, Ponyville
Old 04-29-2013 , 03:18   Re: [STOCK] Target is exist in client's angle and distance (03/07/2013 Ver 1.1)
Reply With Quote #6

Quote:
Originally Posted by Bimbo1 View Post
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.
__________________

Nick : Chamamyungsu // Korean Brony
Guren is offline
ImACow
AlliedModders Donor
Join Date: Feb 2015
Old 02-28-2019 , 14:03   Re: [STOCK] Target is exist in client's angle and distance (03/07/2013 Ver 1.1)
Reply With Quote #7

Thanks for this

Found this by google'ing client view cone
__________________

Last edited by ImACow; 02-28-2019 at 14:09.
ImACow is offline
SZOKOZ
Member
Join Date: Jan 2014
Old 03-03-2019 , 05:07   Re: [STOCK] Target is exist in client's angle and distance (03/07/2013 Ver 1.1)
Reply With Quote #8

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.
__________________
May still be available for SM scripting. Just look at my Steam profile regarding my availability.
My Steam

Last edited by SZOKOZ; 03-03-2019 at 05:09.
SZOKOZ is offline
Edison1318
Senior Member
Join Date: Nov 2015
Location: Peaceful place of the in
Old 05-28-2019 , 20:53   Re: [STOCK] Target is exist in client's angle and distance (03/07/2013 Ver 1.1)
Reply With Quote #9

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
__________________
EdisonGar
Edison1318 is offline
Send a message via Skype™ to Edison1318
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:20.


Powered by vBulletin®
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Theme made by Freecode