AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Distanse (https://forums.alliedmods.net/showthread.php?t=210310)

Podarok 03-09-2013 05:27

Distanse
 
How can i get distanse between players? E.g. i want all players in range 250 of me to write in chat Hello. i'm close to you. How can i getall players in a certain distanse from me?

SpeeDeeR 03-09-2013 05:51

Re: Distanse
 
find_ent_in_sphere

Podarok 03-09-2013 06:00

Re: Distanse
 
Thanks a lot. Any example of using it to find players? And do smth with them after we find them? Please

Infernuz 03-09-2013 06:28

Re: Distanse
 
Find first players origins, and second one. Create a straight line betwen them and calculate the length of that line. There you go, distance.

Podarok 03-09-2013 06:44

Re: Distanse
 
Why do i have to create a straight line? I just want to find all players in lets say 250.0 radius and make some function on them e.g. wadress a message to them

Infernuz 03-09-2013 07:01

Re: Distanse
 
To find the distance betwen one player. You'll have later on loop throw other ones and make a check if they are in range.

This is just my idea of how it can be done, there'r of course other ways.

Backstabnoob 03-09-2013 07:01

Re: Distanse
 
Code:
new iPlayer // origin of the entity to look around, player in your case new Float: vecEntityOrigin[ 3 ] entity_get_vector( iEntity, EV_VEC_origin, vecEntityOrigin ) while( ( iPlayer = find_ent_in_sphere( iPlayer, vecEntityOrigin, 250.0 ) ) ) {     if( is_user_alive( iPlayer ) )     {         client_print( iPlayer, print_chat, "Hello" )     } }

Podarok 03-09-2013 07:44

Re: Distanse
 
Can i use instead of iEntity players id, because i have to calculate distance between players.?

Backstabnoob 03-09-2013 08:00

Re: Distanse
 
Yes, that's what you have to do (reason for my comment above it)

Podarok 03-10-2013 05:53

Re: Distanse
 
Thanks but it does not work. It writes me this : "Hello muthahacka lol!" but not people around me.
Here is my code
Code:
public myfunction( id ) {     new iEnemy         // origin of the entity to look around, player in your case     new Float: vecOrigin[ 3 ]     entity_get_vector( id, EV_VEC_origin, vecOrigin )         while( ( iEnemy = find_ent_in_sphere( id, vecOrigin, 250.0 ) ) && iEnemy != id )     {         if( is_user_alive( iEnemy ) )         {                        client_print( iEnemy, print_chat, "Hello muthahacka lol!" );         }     } }


All times are GMT -4. The time now is 21:41.

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