Raised This Month: $51 Target: $400
 12% 

Find players in range


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Neural
Junior Member
Join Date: Apr 2019
Old 05-01-2020 , 04:09   Find players in range
Reply With Quote #1

Hi there. I need a function to find people at a given distance. But this should not find people, ignoring props and walls. So i can’t just use GetVectorDistance. If there is something between the players, then it needs to be eliminated

I used this function from sentry_owner plugin to find first player in range:
Code:
stock FindFirstTargetInRange(client, Float:vAngle[3], Float:vEntPosition[3], Float:entHeight = 60.0)
{
	new Float:vClientPosition[3];
	
	GetEntPropVector(client, Prop_Send, "m_vecOrigin", vEntPosition);
	vEntPosition[2] += entHeight;
	
	new Float:fDistance[MAXPLAYERS + 1];
	new iTager[MAXPLAYERS + 1];
	new numb = 0;
	for (new i = 1; i <= MaxClients; i++)
	{
		if (IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(client) != GetClientTeam(i))
		{
			GetClientEyePosition(i, vClientPosition);
			fDistance[numb] = GetVectorDistance(vClientPosition, vEntPosition, false);
			if(fDistance[numb] <= 9000000 && fDistance[numb] > 50)
			{
				iTager[numb] = i;
				numb++;				
			}
		}
	}
	
	new zombie = GetZombieMinDistance(iTager, fDistance, numb+1);
	if(zombie < 1 || !IsClientInGame(zombie) || !IsPlayerAlive(zombie))
	{
		return (-1);
	}
	
	GetClientEyePosition(zombie, vClientPosition);
	vClientPosition[2] -= 10.0;
	MakeVectorFromPoints(vEntPosition, vClientPosition, vAngle);
	vClientPosition[2] += 10.0;
	//NormalizeVector(vAngle, vAngle);
	GetVectorAngles(vAngle, vAngle);
	
	new Handle:trace = TR_TraceRayFilterEx(vEntPosition, vClientPosition, MASK_SHOT, RayType_EndPoint, TraceASDF, client);
	if(!TR_DidHit(trace))
	{
		CloseHandle(trace);
		return (zombie);
	}
	CloseHandle(trace);
	return (-1);
}

GetZombieMinDistance(clients[], Float:distance[], max_clients)
{
	if(max_clients < 1) 
	{
		return -1;
	}
	new Float:min_distance = 999999999.0;
	new zombie = -1;
	for(new i = 0; i < max_clients; i++)
	{
		// 999999999   >  10000000
		if(min_distance > distance[i]) 
		{
			if(distance[i] <= 9000000009 && distance[i] > 50)
			{
				min_distance = distance[i];
				zombie = clients[i];				
			}
		}
	}
	return zombie;
}

public bool:TraceASDF(entity, mask, any:data)
{
	return (data != entity);
}
But it doesn’t work well, because it is designed for a turret that does such a check in a repeating timer. In most cases, this function does not notice the player, even if he stands at point blank range and there is nothing between the players. Can someone tell me how to make such a function? Thanks in advance
Neural is offline
Reply



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 16:37.


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