Raised This Month: $ Target: $400
 0% 

Getting distance between player and entity gives wrong result.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 07-10-2013 , 02:46   Getting distance between player and entity gives wrong result.
Reply With Quote #1

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?
__________________

Last edited by Kia; 07-10-2013 at 02:51.
Kia is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-10-2013 , 04:13   Re: Getting distance between player and entity gives wrong result.
Reply With Quote #2

Buttons are brush entities, you have to compute origin doing (absmax + absmin)/2
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 07-10-2013 , 04:16   Re: Getting distance between player and entity gives wrong result.
Reply With Quote #3

Thanks.
__________________
Kia is offline
devilicioux
Veteran Member
Join Date: Jun 2013
Location: Delhi,India
Old 07-10-2013 , 07:21   Re: Getting distance between player and entity gives wrong result.
Reply With Quote #4

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

Classic .. Thanks Connor
devilicioux 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 06:32.


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