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

Solved How to Find Nearest Object & Entity (Help please)


Post New Thread Reply   
 
Thread Tools Display Modes
Antrax15
New Member
Join Date: Feb 2018
Location: Romania
Old 09-09-2019 , 13:43   Re: How to Find Nearest Object & Entity (Help please)
Reply With Quote #11

Quote:
Originally Posted by Dr.Doctor View Post
Try this function
PHP Code:
int GetNearestEntity(int clientchar[] classname)
{
    
//Get the first entity
    
int nearestEntity FindEntityByClassname(entityclassname);
    if (!
IsValidEntity(nearestEntity))
    {
        return -
1;
    }
    
    
float clientVecOrigin[3], entityVecOrigin[3];
    
GetEntPropVector(clientProp_Data"m_vecOrigin"clientVecOrigin);
    
GetEntPropVector(nearestEntityProp_Data"m_vecOrigin"entityVecOrigin);
    
    
//Get the distance between the first entity and client
    
float distancenearestDistance GetVectorDistance(clientVecOriginentityVecOrigin);
    
    
//Find all the entity and compare the distances
    
int entity = -1;
    while (
entity FindEntityByClassname(entityclassname) != -1)
    {
        
GetEntPropVector(entityProp_Data"m_vecOrigin"entityVecOrigin);
        
distance GetVectorDistance(clientVecOriginentityVecOrigin);
        
        if (
distance nearestDistance)
        {
            
nearestEntity entity;
            
nearestDistance distance;
        }
    }
    
    return 
nearestEntity;

You can find the nearest "item_ammopack_medium" like this
PHP Code:
int ammopack GetNearestEntity(client"item_ammopack_medium");

if (
IsValidEntity(ammopack))
{
    
//YOUR CODE

lol,thx ya so much ! )
__________________
Shaiya Noxius EP 5.4 JOIN US NOW!

www.shaiyanoxius.com

-[DEV]Antrax





Antrax15 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 11:06.


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