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

Add players to list


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Laurens
Junior Member
Join Date: Apr 2018
Old 01-12-2019 , 10:03   Add players to list
Reply With Quote #1

Hello, I want to make a list where you can add players to and check if a player is in it.
But this gives me a error:

PHP Code:
int[] playerList
Hope you can help!
Laurens is offline
eat1k
Senior Member
Join Date: Apr 2018
Old 01-12-2019 , 10:08   Re: Add players to list
Reply With Quote #2

Use ArrayCreate() and ArrayPushArray() then to check use ArrayGetArray().
__________________
eat1k is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 01-12-2019 , 11:05   Re: Add players to list
Reply With Quote #3

For the AMXX plugins int array must be written as:
Quote:
new ArrayName[32]
or
Quote:
new ArrayName[] = {1, 2, 3}
__________________
My English is A0
E1_531G is offline
Laurens
Junior Member
Join Date: Apr 2018
Old 01-12-2019 , 11:06   Re: Add players to list
Reply With Quote #4

Whoops! wrong forum! I accidentally clicked on amxx instead of sourcemod! Sorry!
Laurens is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-12-2019 , 11:11   Re: Add players to list
Reply With Quote #5

Use a bitfield. With this method, you can easily check if any players are in the list.
PHP Code:
new g_PlayerList;

#define AddPlayer(%1)        g_PlayerList |= ( 1 << ( %1 & 31 ) )
#define RemovePlayer(%1)    g_PlayerList &= ~( 1 << ( %1 & 31 ) )
#define IsInList(%1)        !!( g_PlayerList & ( 1 << ( %1 & 31 ) ) )

public TestFunc() 
{
    
server_print"Is player 5 in list? %d" IsInList) );
    
    
AddPlayer);
    
    
server_print"Is player 5 in list? %d" IsInList) );
    
    
RemovePlayer);
    
    
server_print"Is player in 5 list? %d" IsInList) );
}

public 
TestFunc2() 
{
    if ( 
g_PlayerList )
    {
        
server_print"One or more players in list" );
    }
    else
    {
        
server_print"No players are in list" );
    }

__________________
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-12-2019 , 11:11   Re: Add players to list
Reply With Quote #6

Moved to SM
__________________

Last edited by Bugsy; 01-12-2019 at 11:12.
Bugsy is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 01-12-2019 , 11:14   Re: Add players to list
Reply With Quote #7

PHP Code:

ArrayList g_Players
;

public 
void OnPluginStart()
{
    
g_Players = new ArrayList();
}


g_Players.Push(client);

int index g_Players.FindValue(client);
if (
index != -1) { // player in array} 
__________________
Ilusion9 is offline
Laurens
Junior Member
Join Date: Apr 2018
Old 01-12-2019 , 11:21   Add players to list
Reply With Quote #8

Hello, I want to make a list where you can add players to, and check if a player is in it.
But this gives me errors:

PHP Code:
int amountOfZombies 0;
int[] zombies = new int[amountOfZombies];
public 
Action Event_PlayerDeath(Event event, const char[] namebool dontBroadcast){

int client GetClientOfUserId(event.GetInt("userid"));
amountOfZombies += 1;
zombies[amountOfZombies] = client;


return 
Plugin_Handled;

The errors are:

error 162: cannot create dynamic arrays in global scope - did you mean to create a fixed-length array with brackets after the variable name?

error 020: invalid symbol name ""

both errors are from the line:
PHP Code:
int[] zombies = new int[amountOfZombies]; 
Hope you can help!
Laurens is offline
Laurens
Junior Member
Join Date: Apr 2018
Old 01-12-2019 , 11:52   Re: Add players to list
Reply With Quote #9

Quote:
Originally Posted by Ilusion9 View Post
PHP Code:

ArrayList g_Players
;

public 
void OnPluginStart()
{
    
g_Players = new ArrayList();
}


g_Players.Push(client);

int index g_Players.FindValue(client);
if (
index != -1) { // player in array} 
Thank you so much!
I didn't know it was so easy, honestly they should add this to the scripting section of the SourceMod wiki.
Laurens is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 01-12-2019 , 11:57   Re: Add players to list
Reply With Quote #10

Don't cross post / double post, use the Report Post button to request your threads moved instead, as mentioned in the AlliedModders Rules:

Code:
If you post (or see a post) in the wrong section, use the Report Post button to request it be moved rather than replying to the thread.
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL 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 21:23.


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