AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   distance between 2 players (https://forums.alliedmods.net/showthread.php?t=304646)

Saint Sinner 01-22-2018 10:12

distance between 2 players
 
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 )
  }
 
}


DjSoftero 01-22-2018 10:16

Re: distance between 2 players
 
https://www.amxmodx.org/api/vector/get_distance
https://www.amxmodx.org/api/vector/get_distance_f
https://www.amxmodx.org/api/engine_s...ntity_distance
https://www.amxmodx.org/api/engine/entity_range
https://www.amxmodx.org/api/vector/vector_distance

next time, just search

Saint Sinner 01-22-2018 16:34

Re: distance between 2 players
 
i know that ... but i want a kode to detect this...can someine help?

HamletEagle 01-22-2018 16:48

Re: distance between 2 players
 
Quote:

Originally Posted by Saint Sinner (Post 2573576)
i know that ... but i want a kode to detect this...can someine help?

The natives are the code.

DjSoftero 01-23-2018 02:33

Re: distance between 2 players
 
Quote:

Originally Posted by Saint Sinner (Post 2573576)
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.

eyal282 01-23-2018 03:09

Re: distance between 2 players
 
Quote:

Originally Posted by Saint Sinner (Post 2573492)
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

Saint Sinner 01-23-2018 05:54

Re: distance between 2 players
 
Thank you guys


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

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