Raised This Month: $ Target: $400
 0% 

how to get if one player is too close to another ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
noob
Junior Member
Join Date: Jun 2004
Old 02-27-2005 , 15:15   how to get if one player is too close to another ?
Reply With Quote #1

this is what i got so far

Code:
public check_dist() {
	new players[32], inum
	get_players(players,inum,"a")
	new player[32], anum
	get_players(player,anum,"a")
	for(new i = 0 ;i < inum ;++i) {
		new origin[3]
		get_user_origin(players[i], origin, 0)
		for(new a = 0 ;a < anum ;++a) {
			new vorigin[3], distance
			get_user_origin(player[a], vorigin, 0)
			distance = get_distance(origin,vorigin)

			if(distance < 90) {
				do_something()
			}
		}
	}
	return PLUGIN_CONTINUE
}
and in the plugin_init, there is
Code:
 set_task(0.1, "check_dist", 0, "", 0, "b")
noob is offline
xeroblood
BANNED
Join Date: Mar 2004
Location: Toronto, Canada
Old 02-27-2005 , 20:26  
Reply With Quote #2

From engine_stocks.inc:

Code:
/* Get the distance between two entities */ stock get_entity_distance(ent1, ent2) {     new Float:orig1[3], Float:orig2[3], origin1[3], origin2[3]     entity_get_vector(ent1, EV_VEC_origin, orig1)     for(new a = 0; a < 3; a++)         origin1[a] = floatround(orig1[a])     entity_get_vector(ent2, EV_VEC_origin, orig2)     for(new b = 0; b < 3; b++)         origin2[b] = floatround(orig2[b])     return get_distance(origin1, origin2) }

So just include <engine_stocks> at the top of your code, and you can use that function..

And instead of looping every 0.1 seconds, you could call it in client_PreThink( id )..

Code:
public client_PreThink( id ) {     new players[32], inum     get_players( players, inum, "a" )     for( new i = 0; i < inum; ++i )     {         if( id == players[i] ) continue         if( get_entity_distance(id, players[i]) > 90 )         {              // id <-- is close to --> players[i]              // Do stuff  here..         }     }     return PLUGIN_CONTINUE }

I hope that helps..
xeroblood is offline
Send a message via MSN to xeroblood
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 02-28-2005 , 16:11  
Reply With Quote #3

You will also need to use i++ and a++ instead of ++i and ++a in this case.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
xeroblood
BANNED
Join Date: Mar 2004
Location: Toronto, Canada
Old 02-28-2005 , 16:29  
Reply With Quote #4

What are you talking about? the ++i in my for loop?? That is a single stand-alone statement, and as such results in the same value using either post-fix or pre-fix incrementation..
xeroblood is offline
Send a message via MSN to xeroblood
BlueRaja
Senior Member
Join Date: Nov 2004
Old 02-28-2005 , 19:30  
Reply With Quote #5

Xeroblood is correct; it doesn't matter whether you use ++i or i++:
http://forums.alliedmods.net/showthread.php?t=10505
__________________
STEPS IN TROUBLESHOOTING <insert anything here>:
1. Narrow down the problem to a specific condition or conditions.
2. Fix it.
BlueRaja is offline
Send a message via AIM to BlueRaja Send a message via MSN to BlueRaja
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 14:03.


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