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

Solved Detect distance between Players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Saint Sinner
Senior Member
Join Date: Feb 2016
Old 06-08-2019 , 15:55   Detect distance between Players
Reply With Quote #1

I want to detect distance between Id and another players...But something is wrong here

Code:
public client_PreThink(id)
{
    new Float:myOrigin[ 3 ], Float:hisOrigin[ 3 ];
    
    new Float:fDistance  

    pev( id, pev_origin, myOrigin )

    for(new i = 1 ; i <= maxplayers; i++)
    {
        pev(i, pev_origin, hisOrigin)
        fDistance = get_distance_f( myOrigin, hisOrigin)

        if( fDistance <= 62.0)
        {
            client_print(id , print_center, "Distance to entity: %.2f", fDistance )
        }

    }
}

Last edited by Saint Sinner; 06-11-2019 at 11:35.
Saint Sinner is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 06-08-2019 , 15:58   Re: Detect distance between Players
Reply With Quote #2

You do not check if player (variable with name i ) is connected.
__________________
My English is A0
E1_531G is offline
Old 06-08-2019, 16:00
<VeCo>
This message has been deleted by <VeCo>.
Old 06-08-2019, 16:11
Saint Sinner
This message has been deleted by Saint Sinner.
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 06-08-2019 , 16:21   Re: Detect distance between Players
Reply With Quote #3

Code:
if (i == id) continue;
__________________








CrazY. is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 06-08-2019 , 16:45   Re: Detect distance between Players
Reply With Quote #4

PHP Code:
public client_PreThink(id)
{
    if(!
is_user_alive(id)) return;
    static 
Float:myOrigin], Float:hisOrigin], players[32], szName[32], playeripnumFloat:fDistance;
    
pevidpev_originmyOrigin )

    
get_players(playerspnum"ah");
    for(
pnumi++)
    {
        
player players[i];

        if(
player == id) continue;
        
pev(playerpev_originhisOrigin)
        
fDistance get_distance_fmyOriginhisOrigin)

        if( 
fDistance <= 62.0)
        {
            
get_user_name(playerszName31);
            
client_print(id print_center"Distance to player entity(%s): %.2f"szNamefDistance)
        }

    }

using static instead of new much better in a forward called each fps.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 06-11-2019 at 10:31.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Saint Sinner
Senior Member
Join Date: Feb 2016
Old 06-11-2019 , 08:43   Re: Detect distance between Players
Reply With Quote #5

Now i have this error...I want to disable distance if player in my team

L 06/11/2019 - 14:29:47: [AMXX] Displaying debug trace (plugin "head.amxx", version "1.0")
L 06/11/2019 - 14:29:47: [AMXX] Run time error 10: native error (native "cs_get_user_team")
L 06/11/2019 - 14:29:47: [AMXX] [0] head.sma::client_PreThink (line 51)

this line : if (cs_get_user_team(id) == cs_get_user_team(i))

Code:
public client_PreThink(id)
{
    if(!is_user_alive(id)) return 1;

    static Float:myOrigin[ 3 ], Float:hisOrigin[ 3 ], Float:fDistance, szName[32]

    if( get_pcvar_num(active) )
    {
        pev( id, pev_origin, myOrigin )

        for(new i = 1 ; i <= maxplayers; i++)
        {
            if (i == id) continue;

            if (cs_get_user_team(id) == cs_get_user_team(i))
            {
                return PLUGIN_CONTINUE
            }

            if (is_user_connected(i))
            {
                pev(i, pev_origin, hisOrigin)
                fDistance = get_distance_f( myOrigin, hisOrigin)

                get_user_name(id, szName, charsmax(szName)) 

                if(equal(szName, "Headshoot"))
                {
                    if( fDistance <= get_pcvar_num(Attack_Distance))
                    {
	                if( get_pcvar_num(stab))
		        {
		            HeadShoot[ id ] = true;
	                }
		        else if( get_pcvar_num(slash))
		        {
                            HeadShoot[ id ] = true;
	                }
                    }
                }
            }
        }
    }
    return PLUGIN_HANDLED
}

Last edited by Saint Sinner; 06-11-2019 at 10:14.
Saint Sinner is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 06-11-2019 , 09:13   Re: Detect distance between Players
Reply With Quote #6

put is_user_connected( i ) before checking his team? even better put is_user_alive there

also if you are using returns PLUGIN_HANDLED and PLUGIN_CONTINUE, then no 'need' for return 1/0
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 06-11-2019 , 09:39   Re: Detect distance between Players
Reply With Quote #7

No don't put anything use get_players instead and what are you trying to achieve? There might be another (better)way without the need of use prethink
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 06-11-2019 at 09:41.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Saint Sinner
Senior Member
Join Date: Feb 2016
Old 06-11-2019 , 10:13   Re: Detect distance between Players
Reply With Quote #8

I want to detect distance for example

If i am TERO detect CT distance
If i am CT detect TERO distance

How can do that?

Code:
#include <amxmodx>
#include <fakemeta>
#include <engine>


public client_PreThink(id)
{
    if(!is_user_alive(id)) return;
    static Float:myOrigin[ 3 ], Float:hisOrigin[ 3 ], players[32], szName[32], player, i, pnum, fDistance;
    pev( id, pev_origin, myOrigin )

    get_players(players, pnum, "ah");
    for(i = 0 ; i < pnum; i++)
    {
        player = players[i];

        if(player == id) continue;
        pev(player, pev_origin, hisOrigin)
        fDistance = get_distance_f( myOrigin, hisOrigin)

        if( fDistance <= 62.0)
        {
            get_user_name(player, szName, 31);
            client_print(id , print_center, "Distance to player entity(%s): %.2f", szName, fDistance)
        }

    }
}
Saint Sinner is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 06-11-2019 , 10:30   Re: Detect distance between Players
Reply With Quote #9

PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <engine>


public client_PreThink(id)
{
    if(!
is_user_alive(id)) return;
    static 
Float:myOrigin], Float:hisOrigin], players[32], szName[32], playeripnumFloat:fDistance;
    
pevidpev_originmyOrigin );
    
get_players(playerspnum"ahe"get_user_team(id) == "CT":"TERRORIST");
    for(
pnumi++)
    {
        
player players[i];

        
pev(playerpev_originhisOrigin)
        
fDistance get_distance_fmyOriginhisOrigin)

        if( 
fDistance <= 62.0)
        {
            
get_user_name(playerszName31);
            
client_print(id print_center"Distance to player entity(%s): %.2f"szNamefDistance)
        }

    }

Here you go..

I forgot to add the Float tag to fDistance in previous code.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 06-11-2019 at 13:05.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Saint Sinner
Senior Member
Join Date: Feb 2016
Old 06-11-2019 , 11:36   Re: Detect distance between Players
Reply With Quote #10

thanks
Saint Sinner 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 10:26.


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