Raised This Month: $ Target: $400
 0% 

Using dynamic arrays for all players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-07-2009 , 22:43   Re: Using dynamic arrays for all players
Reply With Quote #1

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

__________________
fysiks is offline
shadow.hk
Senior Member
Join Date: Dec 2008
Location: WA, Australia
Old 11-07-2009 , 22:52   Re: Using dynamic arrays for all players
Reply With Quote #2

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?
shadow.hk is offline
Send a message via MSN to shadow.hk
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-08-2009 , 16:03   Re: Using dynamic arrays for all players
Reply With Quote #3

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
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-08-2009 , 16:34   Re: Using dynamic arrays for all players
Reply With Quote #4

Quote:
Originally Posted by shadow.hk View Post
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.
__________________
fysiks 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 17:38.


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