AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Resolved] Get players in other players radius? (https://forums.alliedmods.net/showthread.php?t=48211)

hlstriker 12-07-2006 10:39

[Resolved] Get players in other players radius?
 
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);     }

watch 12-07-2006 10:47

Re: Get players in other players radius?
 
for(new i = 0; i < num; i++)

Also this might help
http://forums.alliedmods.net/showthread.php?t=42367

hlstriker 12-07-2006 10:52

Re: Get players in other players radius?
 
Quote:

Originally Posted by watch (Post 411890)
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.

watch 12-07-2006 11:02

Re: Get players in other players radius?
 
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

hlstriker 12-07-2006 11:05

Re: Get players in other players radius?
 
Oh ok, thanks :)

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

stupok 12-08-2006 00:54

Re: Get players in other players radius?
 
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.

hlstriker 12-08-2006 14:23

Re: Get players in other players radius?
 
Alright thanks stupok69 :). I will love you forever if you can help me get this working hehe :P.

stupok 12-08-2006 19:30

Re: Get players in other players radius?
 
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 :mrgreen:. 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.

hlstriker 12-08-2006 23:16

Re: Get players in other players radius?
 
Thank you so so much, stupok69! You have no idea how much I appreciate this :)


All times are GMT -4. The time now is 07:00.

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