Raised This Month: $12 Target: $400
 3% 

[Resolved] Get players in other players radius?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 12-07-2006 , 10:39   [Resolved] Get players in other players radius?
Reply With Quote #1

Hi, I thought I had this fixed, but it seems if more than 2 players are in the game it won't work or something.

What I am trying to do is have it give each player a radius. If it detects another player in the radius, they will both be set to SOLID_NOT. If it doesn't detect a player in the radius, they will be set to SOLID_BBOX.

Here is the code i'm using now that doesn't work all the time (seems if more than 2 players are in it doesn't work).
Code:
    new players[32];     new num;     get_players(players, num, "a");     for(new i = 1; i <= num; i++) {         if( (is_user_alive(players[i]) && is_user_alive(id)) ) {             if(!(players[i] == id)) {                 new distance;                 new origin1[3], origin2[3];                 new radius = 95;                                 get_user_origin(players[i], origin1);                 get_user_origin(id, origin2);                 distance = get_distance(origin1, origin2);                 if(distance < radius) {                     entity_set_int(id, EV_INT_solid, SOLID_NOT);                     entity_set_int(players[i], EV_INT_solid, SOLID_NOT);                 } else {                     entity_set_int(id, EV_INT_solid, SOLID_BBOX);                     entity_set_int(players[i], EV_INT_solid, SOLID_BBOX);                 }             }         }     }

I then tried to use a suggestion with "find_sphere_class". This only gets the number of players I think though, and I need the players id. Here is the code I used for that...
Code:
    new players[32];     new num;         get_players(players, num);     for(new i = 1; i <= num; i++) {         new Float:origin[3];         new testplayer;         entity_get_vector(players[i], EV_VEC_origin, origin);         testplayer = find_sphere_class(0, "player", 100.0, players, 33, origin);         client_print(0, print_chat, "Players in radius... %d", testplayer);     }

Last edited by hlstriker; 12-08-2006 at 23:16. Reason: Resolved
hlstriker is offline
watch
Senior Member
Join Date: Sep 2005
Old 12-07-2006 , 10:47   Re: Get players in other players radius?
Reply With Quote #2

for(new i = 0; i < num; i++)

Also this might help
http://forums.alliedmods.net/showthread.php?t=42367
__________________
Code:
#include <amusing_small_signiture>

Last edited by watch; 12-07-2006 at 10:50.
watch is offline
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 12-07-2006 , 10:52   Re: Get players in other players radius?
Reply With Quote #3

Quote:
Originally Posted by watch View Post
for(new i = 0; i < num; i++)

Also this might help
http://forums.alliedmods.net/showthread.php?t=42367
Isn't that the same as...
for(new i = 1; i <= num; i++)

Also I'll check out that link, thanks.
hlstriker is offline
watch
Senior Member
Join Date: Sep 2005
Old 12-07-2006 , 11:02   Re: Get players in other players radius?
Reply With Quote #4

No, you are skipping a player by doing that and on a 32 man server "i" could reach 32 causing errors with the players[32] array
__________________
Code:
#include <amusing_small_signiture>

Last edited by watch; 12-07-2006 at 11:05.
watch is offline
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 12-07-2006 , 11:05   Re: Get players in other players radius?
Reply With Quote #5

Oh ok, thanks

Also, that link to the Kz plugin is way to advanced for me, hehe.

Last edited by hlstriker; 12-07-2006 at 11:08.
hlstriker is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 12-08-2006 , 00:54   Re: Get players in other players radius?
Reply With Quote #6

Code:
//WRONG
testplayer = find_sphere_class(0, "player", 100.0, players, 33, origin)
testplayer will be the number of "player" 's found. You want the values stored in the variable players.

I will come up with a solution tomorrow. I don't have time today.
stupok is offline
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 12-08-2006 , 14:23   Re: Get players in other players radius?
Reply With Quote #7

Alright thanks stupok69 . I will love you forever if you can help me get this working hehe .
hlstriker is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 12-08-2006 , 19:30   Re: Get players in other players radius?
Reply With Quote #8

Depending on what functionality you are looking for, you will have to modify this code. I set it up so that it checks every 2 seconds if a player is within the radius and makes them solid_not if they're within the radius.

If you want them to never collide, you can either lower the seconds for the set_task or use client_prethink/postthink. I would go with lowering the set_task seconds.

Code:
#include <amxmodx> #include <amxmisc> #include <engine> #define PLUGIN "New Plug-In" #define VERSION "1.0" #define AUTHOR "Kamil" new cvar_collisions new players[32], playersnum public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     cvar_collisions = register_cvar("no_collisions", "1")         start_preventing() } public start_preventing() {     if(!get_pcvar_num(cvar_collisions)) return PLUGIN_HANDLED         set_task(2.0, "all_players_function", 0, "", 0, "b") } public all_players_function() {     get_players(players, playersnum, "ah")         for(new i = 0; i < playersnum; i++)     {         prevent_collide(players[i])     } } public prevent_collide(id) {     new origin[3]     new player[1]     new Float:radius = 100.0         get_user_origin(id, origin, 0)         find_sphere_class(id, "player", radius, player, 1)         if(id != player[0])     {         entity_set_int(id, EV_INT_solid, SOLID_NOT)         entity_set_int(player[0], EV_INT_solid, SOLID_NOT)     }     else     {         entity_set_int(id, EV_INT_solid, SOLID_BBOX)     } }

This was fun to figure out . Also, I think this may be more efficient then teame06's method used in his KZ plugin. It all depends on how the find_sphere_class() function works.

Last edited by stupok; 12-08-2006 at 19:43.
stupok is offline
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 12-08-2006 , 23:16   Re: Get players in other players radius?
Reply With Quote #9

Thank you so so much, stupok69! You have no idea how much I appreciate this
hlstriker 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:50.


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