Raised This Month: $ Target: $400
 0% 

Storing players in Array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mlk27
Veteran Member
Join Date: May 2008
Old 02-17-2009 , 08:25   Storing players in Array
Reply With Quote #1

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..

Last edited by Mlk27; 02-17-2009 at 09:06. Reason: Better description
Mlk27 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-17-2009 , 08:26   Re: Storing players in Array
Reply With Quote #2

#define MAX_CLIENTS 32
new MyArray[ MAX_CLIENTS + 1 ];
Arkshine is offline
Mlk27
Veteran Member
Join Date: May 2008
Old 02-17-2009 , 13:09   Re: Storing players in Array
Reply With Quote #3

Better description updated
Mlk27 is offline
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 02-17-2009 , 13:18   Re: Storing players in Array
Reply With Quote #4

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
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
anakin_cstrike
Veteran Member
Join Date: Nov 2007
Location: Romania
Old 02-17-2009 , 13:42   Re: Storing players in Array
Reply With Quote #5

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++;         }     } }
__________________

anakin_cstrike is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-17-2009 , 13:53   Re: Storing players in Array
Reply With Quote #6

PHP Code:
new g_bIsLifeLowerThan50[33]

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

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

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
anakin_cstrike
Veteran Member
Join Date: Nov 2007
Location: Romania
Old 02-17-2009 , 13:55   Re: Storing players in Array
Reply With Quote #7

Yes but the array can be: 1, 0, 0, 1, 1, 1, 0, etc..;
And you have to check if it's 1.
__________________

anakin_cstrike is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-17-2009 , 14:01   Re: Storing players in Array
Reply With Quote #8

In that case, you have to use dynamic arrays, so the array size will reflect low health players number.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-17-2009 , 17:29   Re: Storing players in Array
Reply With Quote #9

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; }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Mlk27
Veteran Member
Join Date: May 2008
Old 02-21-2009 , 19:09   Re: Storing players in Array
Reply With Quote #10

Exolent, thanks..

what is g_player_count there for?
Mlk27 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 16:52.


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