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

Multiple array format / structure


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
killergirl
Senior Member
Join Date: Jul 2010
Old 11-10-2012 , 13:37   Multiple array format / structure
Reply With Quote #1

Edit: found the answer: http://forums.alliedmods.net/showthread.php?t=140103

How am I supposed to create a multidimensional array?

Code:
#define MAX_USER 120
#define U_LEN 32
#define U_PASS 32

new reg_users[MAX_USER][U_LEN][U_PASS]

formatex(reg_users[ sizeof(reg_users) ][U_LEN], 31, "admin")
formatex(reg_users[ sizeof(reg_users) ][U_PASS], 31, "123456")
Like in PHP:

PHP Code:
$users = array();
$users[] = array( 'username' => 'admin',
                     
'password' => '12345' );

$users[] = array( 'username' => 'admin2',
                     
'password' => '543211' ); 
it should be:

PHP Code:
$users[0]['username'// points to -> admin
$users[0]['password'// point to -> 12345

$users[1]['username']  // points to -> admin2
$users[1]['password'// points to -> 543211 
But how am I supposed to do this in amxx?

Last edited by killergirl; 11-10-2012 at 13:49.
killergirl is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 11-10-2012 , 13:50   Re: Multiple array format / structure
Reply With Quote #2

Use a trie so you don't have a max users ?

PHP Code:
#define U_LEN 32
#define U_PASS 32

new Trie:g_tUsersLogins

public plugin_init()
{
    
g_tUsersLogins TrieCreate()
}

StoreUserDatas(idszName[U_LEN], szPass[U_PASS])
{
    if( 
TrieKeyExists(g_tUsersLoginsszName) )
    {
        
// name is not avalaible
        
return 0
    
}
    
TrieSetArray(g_tUsersLoginsszNameszPass)
    return 
1

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
killergirl
Senior Member
Join Date: Jul 2010
Old 11-10-2012 , 14:38   Re: Multiple array format / structure
Reply With Quote #3

Thanks ConnorMcLeod but the compiler doesn't compile it. I get some error:

error 088: number of arguments does not match definition.

Am I need to compile with amxx 1.8.2 ? It does it means when somebody uses my plugin it must have 1.8.2 version?
killergirl is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-10-2012 , 14:44   Re: Multiple array format / structure
Reply With Quote #4

Quote:
Originally Posted by killergirl View Post
Thanks ConnorMcLeod but the compiler doesn't compile it. I get some error:

error 088: number of arguments does not match definition.

Am I need to compile with amxx 1.8.2 ? It does it means when somebody uses my plugin it must have 1.8.2 version?
It compiles for me.

No, you don't have to use 1.8.2. You only need to have 1.8+
__________________

Last edited by fysiks; 11-10-2012 at 14:46.
fysiks is offline
killergirl
Senior Member
Join Date: Jul 2010
Old 11-10-2012 , 14:49   Re: Multiple array format / structure
Reply With Quote #5

PHP Code:
new Trie:VipUsers

public plugin_init(){
   
VipUsers TrieCreate()
}

public 
get_users() SQL_ThreadQuery(g_sqlTuple"_handle_get_users""SELECT * FROM `vip_system`");
public 
_handle_get_users(FailStateHandle:QueryszError[], iError){
    
QueryStatus(FailStateszErroriError)
    
    static 
user[32], pass[32]
    
    while(
SQL_MoreResults(Query)){
        
        
SQL_ReadResult(Query1user31)
        
SQL_ReadResult(Query2pass31)
        
        
TrieSetArray(VipUsersuserpass)
        
        
SQL_NextRow(Query)
    }
    
    
SQL_FreeHandle(Query)

killergirl is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-10-2012 , 14:53   Re: Multiple array format / structure
Reply With Quote #6

The function requires 4 arguments so I don't know why Connor's code compiles. You should use TrieSetString() anyways.
__________________
fysiks is offline
killergirl
Senior Member
Join Date: Jul 2010
Old 11-10-2012 , 15:11   Re: Multiple array format / structure
Reply With Quote #7

Wow, it's very interesting... Thanks fysiks, now it compiles.

I can't find any documentation for Trie (slap me if I'm wrong) and I'm trying to understand the code what I found in trietest.sma. Is there any documentation for Trie?

Is Trie a multidimensional array? What's the terminology for Trie? I never heard about it.

How am I supposed to retrieve data from "Trie"? LOL

Thanks !
killergirl is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-10-2012 , 15:18   Re: Multiple array format / structure
Reply With Quote #8

http://forums.alliedmods.net/showthread.php?t=88396

Also, /addons/amxmodx/scripting/includes/celltrie.inc.

I can't recall of much more than that.
__________________
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 11:29.


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