Raised This Month: $ Target: $400
 0% 

Enemy distance in M


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 05-23-2016 , 20:52   Enemy distance in M
Reply With Quote #1

Man, i was searching for the distance between me and the enemy but i dont found a good format.
Appearing in hud the player closer and its distance in meters.

Like this:

Enemy: EFFx - 17 meters

I looked more wdo I thought were definitive codes for X distance, and I want to sample the distance from the closer, and I did not find it.

Can you guys help me?
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 05-23-2016 , 23:18   Re: Enemy distance in M
Reply With Quote #2

Quote:
Originally Posted by EFFx View Post
I looked more wdo I thought were definitive codes for X distance, and I want to sample the distance from the closer, and I did not find it.
I'm not sure what you're trying to say but here's one way to get the distance. Of course it's not the complete code because I'm not sure what you want.

PHP Code:
public whatever()
{
    
    new 
Float:kOrigin], Float:vOrigin];
     
    
pevyour_indexpev_originkOrigin )
    
pevenemy_indexpev_originvOrigin )
    
    new 
Float:iDist get_distance_fkOriginvOrigin )   
    new 
Float:iMeters iDist 0.0254  // This will convert it to meters.
    
    //Add your hud here

__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.

Last edited by wickedd; 05-23-2016 at 23:23.
wickedd is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 05-24-2016 , 18:31   Re: Enemy distance in M
Reply With Quote #3

What i made:

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

#define PLUGIN "Enemy distance"
#define VERSION "1.0"
#define AUTHOR "EFFx"

public plugin_init() 
{
 
register_plugin(PLUGINVERSIONAUTHOR)
}
public 
client_putinserver(id)
 
set_task(1.0,"ShowEnemyDHud",id,_,_,"b")
 
public 
ShowEnemyDHud(id)
{
 if(!
is_user_alive(id) && get_user_team(id) != 1)
 return 
PLUGIN_HANDLED
 
 
new Float:kOrigin], Float:vOrigin];
 
 new 
enemy
 
 pev
idpev_originkOrigin )
 
pevenemypev_originvOrigin )
 
 new 
Float:iDist get_distance_fkOriginvOrigin )   
 new 
Float:iMeters iDist 0.0254  // This will convert it to meters.
 
 
if(get_user_team(id) == get_user_team(enemy))
 return 
PLUGIN_HANDLED
 
 
new szHudEnemyD[50]
 
formatex(szHudEnemyD,charsmax(szHudEnemyD),"Enemy: %d meters",iMeters)
 
set_hudmessage(0,255,0,-1.0,0.70,0,1.0,1.0)
 
show_hudmessage(id,szHudEnemyD)
 return 
PLUGIN_CONTINUE

And like every format that i've searched, the result is:
Attached Thumbnails
Click image for larger version

Name:	Sem título.png
Views:	133
Size:	13.2 KB
ID:	154939  
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 05-24-2016 at 18:36.
EFFx is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 05-24-2016 , 19:35   Re: Enemy distance in M
Reply With Quote #4

%d -> %.0f
The number decides hos many decimals.
__________________
Black Rose is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 05-24-2016 , 19:44   Re: Enemy distance in M
Reply With Quote #5

Yes, your format made the plugin running successfly.
But this format is to all enemy, i want only one ( the closest )

Because when i'm by side the enemy, the distance is 56 meters/9 meters, wtf?

Here's the screenshot:
The first is when i'm alone, just me on the server.
The second photo is when i'm by side the enemy.
Attached Thumbnails
Click image for larger version

Name:	No_Players.png
Views:	67
Size:	12.6 KB
ID:	154940   Click image for larger version

Name:	asa.png
Views:	113
Size:	79.3 KB
ID:	154941  
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 05-24-2016 at 19:58.
EFFx is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 05-24-2016 , 21:05   Re: Enemy distance in M
Reply With Quote #6

Quote:
Originally Posted by EFFx View Post
What i made:

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

#define PLUGIN "Enemy distance"
#define VERSION "1.0"
#define AUTHOR "EFFx"

public plugin_init() 
{
 
register_plugin(PLUGINVERSIONAUTHOR)
}
public 
client_putinserver(id)
 
set_task(1.0,"ShowEnemyDHud",id,_,_,"b")
 
public 
ShowEnemyDHud(id)
{
 if(!
is_user_alive(id) && get_user_team(id) != 1)
 return 
PLUGIN_HANDLED
 
 
new Float:kOrigin], Float:vOrigin];
 
 new 
enemy
 
 pev
idpev_originkOrigin )
 
pevenemypev_originvOrigin )
 
 new 
Float:iDist get_distance_fkOriginvOrigin )   
 new 
Float:iMeters iDist 0.0254  // This will convert it to meters.
 
 
if(get_user_team(id) == get_user_team(enemy))
 return 
PLUGIN_HANDLED
 
 
new szHudEnemyD[50]
 
formatex(szHudEnemyD,charsmax(szHudEnemyD),"Enemy: %d meters",iMeters)
 
set_hudmessage(0,255,0,-1.0,0.70,0,1.0,1.0)
 
show_hudmessage(id,szHudEnemyD)
 return 
PLUGIN_CONTINUE

And like every format that i've searched, the result is:
Post the code you're using because this code would never work.

Edit: If you want to get the closet player near you, then you should use find_ent_in_sphere or find_ent_class. Then use the code I gave you.
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.

Last edited by wickedd; 05-24-2016 at 21:08.
wickedd is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 05-24-2016 , 21:37   Re: Enemy distance in M
Reply With Quote #7

And how will be? Can you make aa example?
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 05-24-2016 at 21:49.
EFFx is offline
Old 05-25-2016, 02:39
Chihuahuax
This message has been deleted by Chihuahuax.
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 05-25-2016 , 05:30   Re: Enemy distance in M
Reply With Quote #8

There's no way around it. Loop through all enemies and compare the distance. Save the one with the lowest value.
find_ent_in_sphere will not give you the result you are looking for.
__________________
Black Rose is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 05-25-2016 , 08:13   Re: Enemy distance in M
Reply With Quote #9

hhaa, you are creating variable enemy and after that you use pev origin. You basically are getting server origin because it has ID 0. You shall loop all players, I will come with a loop soon:

Try :

PHP Code:

#include <amxmodx>
#include <fakemeta>

#define PLUGIN "Enemy distance"
#define VERSION "1.0"
#define AUTHOR "EFFx"

public plugin_init() 
{
 
register_plugin(PLUGINVERSIONAUTHOR)
}
public 
client_putinserver(id)
 
set_task(1.0,"ShowEnemyDHud",id,_,_,"b")
 
public 
ShowEnemyDHud(id)
{
 if(!
is_user_alive(id) && get_user_team(id) != 1)
 return 
PLUGIN_HANDLED
 
 
new Float:myOrigin], Float:hisOrigin];
 new 
Float:iDistFloat:tmpdist;
 new 
players[32], pnum;
 
 
pevidpev_originmyOrigin )
 
 
get_playersplayerspnum"ae""CT" );
 
 if(!
pnum
 return 
PLUGIN_HANDLED
 
 
for(new ipnumi++)
 {
 
   
pevipev_originhisOrigin );
   
tmpdist get_distance_fmyOriginhisOrigin );
   if(
tmpdist iDist)
     
iDist tmpdist;
 
 }
 
    
 
iDist *= 0.0254;
 
 new 
szHudEnemyD[50]
 
formatex(szHudEnemyD,charsmax(szHudEnemyD),"Enemy: %d meters"iDist)
 
set_hudmessage(0,255,0,-1.0,0.70,0,1.0,1.0)
 
show_hudmessage(id,szHudEnemyD)
 return 
PLUGIN_CONTINUE

I removed amxmisc include from the top, not necessary..
And also i suggest you to set task on player spawn and remove it on death or disconnect, it will be more efficient because in your way task is running on dead player , disconnected player, on ct,spectate and or player.. It's not effiecient....

Like this one, it's more better (but uses hamsandwich module for player spawn hook):

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

#define PLUGIN "Enemy distance"
#define VERSION "1.0"
#define AUTHOR "EFFx"

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
RegisterHam(Ham_Spawn"player""set_the_task"1)
    
register_event("DeathMsg""eDeathMsg""a");
}
public 
set_the_task(id)
    if(
is_user_connected(id) && is_user_alive(id) && get_user_team(id) == 1)
    
set_task1.0"ShowEnemyDHud"id, .flags "b" )


public 
client_disconnect(id)
    if(
task_exists(id)) 
    
remove_task(id)

public 
eDeathMsg()
{
    new 
Victim read_data(2);
    if(
task_exists(Victim)) 
        
remove_task(Victim)
}    

public 
ShowEnemyDHud(id)
{
    
    new 
players[32], pnum;
    
    
get_playersplayerspnum"ae""CT" );
    
    if(!
pnum
        return 
PLUGIN_HANDLED
    
    
new Float:myOrigin], Float:hisOrigin];
    new 
Float:iDistFloat:tmpdist;
    
    
pevidpev_originmyOrigin )
    
    for(new 
ipnumi++)
    {
        
        
pevipev_originhisOrigin );
        
tmpdist get_distance_fmyOriginhisOrigin );
        if(
tmpdist iDist)
            
iDist tmpdist;
        
    }
    
    
set_hudmessage(0,255,0,-1.0,0.70,0,1.0,1.0)
    
show_hudmessage(id"Enemy: %d meters"iDist 0.0254)
    
    return 
PLUGIN_CONTINUE


Last edited by siriusmd99; 05-25-2016 at 08:40.
siriusmd99 is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 05-25-2016 , 16:01   Re: Enemy distance in M
Reply With Quote #10

The results from your codes:
Attached Thumbnails
Click image for larger version

Name:	Sem título.png
Views:	82
Size:	39.6 KB
ID:	154966  
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx 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 18:42.


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