Raised This Month: $32 Target: $400
 8% 

distance between 2 players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Saint Sinner
Senior Member
Join Date: Feb 2016
Old 01-22-2018 , 10:12   distance between 2 players
Reply With Quote #1

How can detect distance between 2 players?

Code:
public distance(ent, id)
{
    if(is_user_alive(id) && is_user_alive(ent))
        return;

    new Float:kOrigin[ 3 ], Float:vOrigin[ 3 ]
    
    pev( id, pev_origin, kOrigin )
    pev( ent, pev_origin, vOrigin )

    new Float:iDist = get_distance_f( kOrigin, vOrigin ) 
    new Float:iMeters = iDist

    if( iDist <= 100.0)
   {
        client_print(id , print_center, "Distance : %.2f", iDist )
   }
 
}
Saint Sinner is offline
Saint Sinner
Senior Member
Join Date: Feb 2016
Old 01-22-2018 , 16:34   Re: distance between 2 players
Reply With Quote #3

i know that ... but i want a kode to detect this...can someine help?
Saint Sinner is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-22-2018 , 16:48   Re: distance between 2 players
Reply With Quote #4

Quote:
Originally Posted by Saint Sinner View Post
i know that ... but i want a kode to detect this...can someine help?
The natives are the code.
__________________
HamletEagle is offline
DjSoftero
Veteran Member
Join Date: Nov 2014
Location: Lithuania
Old 01-23-2018 , 02:33   Re: distance between 2 players
Reply With Quote #5

Quote:
Originally Posted by Saint Sinner View Post
i know that ... but i want a kode to detect this...can someine help?
you can do it in client_think, or create a separate entity, which does like 2 operations per second looping through all the players, to determine whether two players are near each other.
PHP Code:
new Players[32], countFloat:distance
get_players
(Playerscount)
for(new 
ii<count-1i++)
    for(new 
j=i+1j<countj++) {
        
distance entity_range(Players[i], Players[j])
        if(
distance <= 100) {
            
//two entities are nearby

        
}

at least that's what I understood.
__________________
retired chump

Last edited by DjSoftero; 01-23-2018 at 02:33. Reason: misindentation
DjSoftero is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 01-23-2018 , 03:09   Re: distance between 2 players
Reply With Quote #6

Quote:
Originally Posted by Saint Sinner View Post
How can detect distance between 2 players?

Code:
public distance(ent, id)
{
    if(is_user_alive(id) && is_user_alive(ent))
        return;

    new Float:kOrigin[ 3 ], Float:vOrigin[ 3 ]
    
    pev( id, pev_origin, kOrigin )
    pev( ent, pev_origin, vOrigin )

    new Float:iDist = get_distance_f( kOrigin, vOrigin ) 
    new Float:iMeters = iDist

    if( iDist <= 100.0)
   {
        client_print(id , print_center, "Distance : %.2f", iDist )
   }
 
}
The distance won't be checked if BOTH PLAYERS ARE ALIVE
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Saint Sinner
Senior Member
Join Date: Feb 2016
Old 01-23-2018 , 05:54   Re: distance between 2 players
Reply With Quote #7

Thank you guys
Saint Sinner is offline
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 01:53.


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