AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Using dynamic arrays for all players (https://forums.alliedmods.net/showthread.php?t=108661)

shadow.hk 11-07-2009 22:28

Using dynamic arrays for all players
 
I need some help with this final bit of code for this mod. I tested it and it obviously doesn't work so I was wondering if there's a similar method that you're supposed to do so it will work. I'm trying to create a dynamic array for all players because the size is reliant on the size of another dynamic array.

Here is the original static array...

PHP Code:

new g_iPlayerBind[MAX_BINDS][33][16]; 

Here was my attempt at converting it to a dynamic array...

PHP Code:

new Array:g_iPlayerBind[33];

public 
plugin_cfg()
{
      for(new 
033i++)
      {
            
g_iPlayerBind[i] = ArrayCreate(16);
      }
}

// To get the string...
ArrayGetStringHandle(g_iPlayerBind[id], num); 

So, any help would be greatly appreciated. If you need to see more code just ask - just be a bit specific about what part of the code.

fysiks 11-07-2009 22:43

Re: Using dynamic arrays for all players
 
PHP Code:

new Array:g_szPlayerBinds


public plugin_cfg()
{
    
g_szPlayerBinds ArrayCreate(16); // 15 character strings
    
    
for(new 033i++)
    {
        
ArrayPushString(g_szPlayerBinds"somthing here"// Initialize I guess
    
}

}


public function(
id)
{
    
// Get the string for id
    
new my_string[16]
    
ArrayGetString(g_szPlayerBindsidmy_stringcharsmax(my_string))
    
    
// use my_string
    
    // Set the string for id
    
ArraySetString(g_szPlayerBindsid"something new")
    
    
// Also, use the string for id in a format command
    
    
new another_string[56]
    
formatex(another_string55"Player entity: %d <> Bind: %a"idArrayGetStringHandle(g_szPlayerBinds[id], id));
    
    
// Use another_string



shadow.hk 11-07-2009 22:52

Re: Using dynamic arrays for all players
 
But I need players to have multiple binds (i.e. Multiple strings) in the id-specific array. Here's my loading function...

PHP Code:

public load_binds(id)
{
    
id -= TASK_ID_BINDS;
    
    new 
szData[256], szKey[64];
    
    
formatex(szKey63"%sSETTINGS"g_szAuthID[id]);
    
    
// Load bind settings
    
if( nvault_get(g_BindVaultszKeyszData255) )
    {
        new 
szSettings[2][2];
        
parse(szDataszSettings[0], 1szSettings[1], 1);
        
        
g_iSettings[0][id] = str_to_num(szSettings[0]);
        
g_iSettings[1][id] = str_to_num(szSettings[1]);
    }
    
    
get_pcvar_num(p_BindMulti) ?
    
formatex(szKey63"%s%s"g_szAuthID[id], g_szBindMode) : formatex(szKey63"%sBINDS"g_szAuthID[id]);
    
    
// Load specific bind configuration
    
if( nvault_get(g_BindVaultszKeyszData255) )
    {
        new 
szLeft[16], temp;
        
temp ArraySize(g_iPlayerBind[id]);
        
        while( 
contain(szData"#") != -&& temp g_MaxBinds )
        {
            
strtok(szDataszLeft15szData255'#'1);
            
            
ArrayPushString(g_iPlayerBind[id], szLeft);
            
temp++;
        }
        
        
// Make sure that the array is fully initialised
        
for(new temptemp g_MaxBindsi++)
        {
            
ArrayPushString(g_iPlayerBind[id], "");
        }
    }
    
    
// Check if autobind is on
    
if( g_iSettings[0][id] )
        
set_binds(id);


So if I'm reading yours correctly, each player can only have one string?

Exolent[jNr] 11-08-2009 16:03

Re: Using dynamic arrays for all players
 
PHP Code:

new Array:g_aBinds33 ];
new 
g_iTotalBinds33 ];

public 
plugin_init( )
{
    new 
iMaxPlayers get_maxplayers( );
    
    for( new 
1<= iMaxPlayersi++ )
    {
        
g_aBinds] = ArrayCreate64 ); // 64 = max bind length
    
}
}

public 
load_binds(id)
{
    
id -= TASK_ID_BINDS;
    
    new 
szData[256], szKey[64];
    
    
formatex(szKey63"%sSETTINGS"g_szAuthID[id]);
    
    
// Load bind settings
    
if( nvault_get(g_BindVaultszKeyszData255) )
    {
        new 
szSettings[2][2];
        
parse(szDataszSettings[0], 1szSettings[1], 1);
        
        
g_iSettings[0][id] = str_to_num(szSettings[0]);
        
g_iSettings[1][id] = str_to_num(szSettings[1]);
    }
    
    
get_pcvar_num(p_BindMulti) ?
    
formatex(szKey63"%s%s"g_szAuthID[id], g_szBindMode) : formatex(szKey63"%sBINDS"g_szAuthID[id]);
        
    
ArrayClearg_aBindsid ] );
    
g_iTotalBindsid ] = 0;
    
    
// Load specific bind configuration
    
if( nvault_get(g_BindVaultszKeyszData255) )
    {
        new 
szLeft[16];
        
        while( 
contain(szData"#") != -&& temp g_MaxBinds )
        {
            
strtok(szDataszLeft15szData255'#'1);
            
            
ArrayPushStringg_aBindsid ], szLeft );
            
g_iTotalBindsid ]++;
        }
    }
    
    
// Check if autobind is on
    
if( g_iSettings[0][id] )
        
set_binds(id);


PHP Code:

// looping through binds
new szBind64 ];
for( new 
0g_iTotalBindsid ]; i++ )
{
    
ArrayGetStringg_aBindsid ], iszBind63 );
    
    
// szBind = bind with index of i


No need for g_MaxBinds

fysiks 11-08-2009 16:34

Re: Using dynamic arrays for all players
 
Quote:

Originally Posted by shadow.hk (Post 983746)
So if I'm reading yours correctly, each player can only have one string?

Yes. In your case Exolent's example should work for you.


All times are GMT -4. The time now is 17:38.

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