AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Getting distance between player and entity gives wrong result. (https://forums.alliedmods.net/showthread.php?t=220368)

Kia 07-10-2013 02:46

Getting distance between player and entity gives wrong result.
 
Hello everybody,

I try to store the position of a End Button using this Code

Code:

new Float:g_flDist[33][3]
.
.
.
new ent = -1
while((ent = find_ent_by_class(ent, "counter_off")))
        pev(ent, pev_origin, g_flDist[id])
while((ent = find_ent_by_class(ent, "clockstopbutton")))
        pev(ent, pev_origin, g_flDist[id])
while((ent = find_ent_by_class(ent, "clockstop")))
        pev(ent, pev_origin, g_flDist[id])
while((ent = find_ent_by_class(ent, "but_stop")))
        pev(ent, pev_origin, g_flDist[id])
while((ent = find_ent_by_class(ent, "counter_stop_button")))
        pev(ent, pev_origin, g_flDist[id])
while((ent = find_ent_by_class(ent, "multi_stop")))
        pev(ent, pev_origin, g_flDist[id])
while((ent = find_ent_by_class(ent, "stop_counter")))
        pev(ent, pev_origin, g_flDist[id])
while((ent = find_ent_by_class(ent, "m_counter_end_emi")))
        pev(ent, pev_origin, g_flDist[id])

Then getting the origin of the player
Code:

static Float:origin[3]
pev(id, pev_origin, origin)

and showing the distance in a HUD
Code:

get_distance_f(origin, g_flDist[id])
But I always get wrong results, when I stand next to the button it shows me 3000 Units distance. Can anyone tell me whats wrong?

ConnorMcLeod 07-10-2013 04:13

Re: Getting distance between player and entity gives wrong result.
 
Buttons are brush entities, you have to compute origin doing (absmax + absmin)/2

Kia 07-10-2013 04:16

Re: Getting distance between player and entity gives wrong result.
 
Thanks. :)

devilicioux 07-10-2013 07:21

Re: Getting distance between player and entity gives wrong result.
 
Quote:

Originally Posted by ConnorMcLeod (Post 1987466)
Buttons are brush entities, you have to compute origin doing (absmax + absmin)/2


Classic .. Thanks Connor :D


All times are GMT -4. The time now is 06:32.

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