AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Storing players in Array (https://forums.alliedmods.net/showthread.php?t=85872)

Mlk27 02-17-2009 08:25

Storing players in Array
 
Sorry for another newbie question. I'm trying store info in array which will contain id's of all players that *for example* has health below 50. The array size must reflects the numbers of current ids added in it.

Can you show how to do this? Adding/remove info into/from the array and count the array size etc..eg when 2 players have health below 50, add their ids to the array and when their health no long below 50, remove their id from the array..

Arkshine 02-17-2009 08:26

Re: Storing players in Array
 
#define MAX_CLIENTS 32
new MyArray[ MAX_CLIENTS + 1 ];

Mlk27 02-17-2009 13:09

Re: Storing players in Array
 
Better description updated

AntiBots 02-17-2009 13:18

Re: Storing players in Array
 
new Float:array[33] // Yes 33. Ids are from 1 to 32. Yes float because hp are float.

Then to get it. pev(id, pev_health, array[id]) // yes heres id... They are 33 spec in the array. So to get it in another funccion just.

new Float:someonehp = array[id]

sorry mi english is very bad :P

anakin_cstrike 02-17-2009 13:42

Re: Storing players in Array
 
Something like this
Code:
#include <amxmodx> #define MAX_PLAYERS 32 new g_maxplayers; new g_Array[ MAX_PLAYERS+1 ]; public plugin_init() {     set_task( 5.0, "check", _, _, _, "b" );     g_maxplayers = get_maxplayers(); } public check( ) {     new j;     for( new i = 1; i <= g_maxplayers; i++ )     {         if( !is_user_alive( i ) )             continue;                     if( get_user_health( i ) < 50 )         {             g_Array[ j ] = i;             j++;         }     } }

ConnorMcLeod 02-17-2009 13:53

Re: Storing players in Array
 
PHP Code:

new g_bIsLifeLowerThan50[33]

public 
plugin_init()
{
    
register_event("Health""Event_Health""b")
}

public 
Event_Healthid )
{
    
g_bIsLifeLowerThan50id ] = (read_data(1) < 50)



anakin_cstrike 02-17-2009 13:55

Re: Storing players in Array
 
Yes but the array can be: 1, 0, 0, 1, 1, 1, 0, etc..;
And you have to check if it's 1.

ConnorMcLeod 02-17-2009 14:01

Re: Storing players in Array
 
In that case, you have to use dynamic arrays, so the array size will reflect low health players number.

Exolent[jNr] 02-17-2009 17:29

Re: Storing players in Array
 
Quickly made, might be errors.

Code:
#include <amxmodx> #include <amxmisc> new Array:g_low_health_players; new g_player_count; public plugin_init() {     register_event("DeathMsg", "EventDeathMsg", "a");     register_event("Health", "EventHealth", "be");         g_low_health_players = ArrayCreate(1); } public client_disconnect(client) {     new pos = GetArrayPos(client);     if( pos >= 0 )     {         ArrayDeleteItem(g_low_health_players, pos);         g_player_count--;     } } public EventDeathMsg() {     new client = read_data(2);         client_disconnect(client); } public EventHealth(client) {     new pos = GetArrayPos(client);         if( pos == -1 )     {         if( read_data(1) < 50 )         {             ArrayPushCell(g_low_health_players, client);             g_player_count++;         }     }     else if( read_data(1) >= 50 )     {         ArrayDeleteItem(g_low_health_players, pos);         g_player_count--;     } } GetArrayPos(client) {     for( new i = 0; i < g_player_count; i++ )     {         if( ArrayGetCell(g_low_health_players, i) == client )         {             return i;         }     }         return -1; }

Mlk27 02-21-2009 19:09

Re: Storing players in Array
 
Exolent, thanks..

what is g_player_count there for?


All times are GMT -4. The time now is 16:52.

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