AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Help with saving an array with tries (https://forums.alliedmods.net/showthread.php?t=295138)

OciXCrom 03-17-2017 09:19

Help with saving an array with tries
 
PHP Code:

#define MAX_ITEMS 100

new g_iLimit[33][MAX_ITEMS]
new 
Trie:g_tLimit

public client_putinserver(id)
    
TrieGetArray(g_tLimitszUserg_iLimit[id], sizeof(g_iLimit[]))
    
public 
client_disconnect(id)
    
TrieSetArray(g_tLimitszUserg_iLimit[id], sizeof(g_iLimit[])) 

This doesn't seem to work. Am I doing something wrong here, or is it not possible to use trie arrays for this? What I'm trying to do is save the limit for each item until the end of the map.

PRoSToTeM@ 03-17-2017 09:54

Re: Help with saving an array with tries
 
Can you show TrieCreate call for g_tLimit?

OciXCrom 03-17-2017 10:01

Re: Help with saving an array with tries
 
PHP Code:

public plugin_init()
    
g_tLimit TrieCreate() 


PRoSToTeM@ 03-17-2017 10:58

Re: Help with saving an array with tries
 
What is szUser? Can you try this?
PHP Code:

new const someUser[] = "wadjwdja";
const 
somePlayer 0;
const 
someField1 0;
const 
someField2 MAX_ITEMS/2;
const 
someField3 MAX_ITEMS 1;
g_iLimit[somePlayer][someField1] = 7;
g_iLimit[somePlayer][someField2] = 13;
g_iLimit[somePlayer][someField3] = 55;
TrieSetArray(g_tLimitsomeUserg_iLimit[somePlayer], sizeof(g_iLimit[]));
g_iLimit[somePlayer][someField1] = 0;
g_iLimit[somePlayer][someField2] = 0;
g_iLimit[somePlayer][someField3] = 0;
TrieGetArray(g_tLimitsomeUserg_iLimit[somePlayer], sizeof(g_iLimit[]));
server_print("someField1=%d, someField2=%d, someField3=%d"g_iLimit[somePlayer][someField1], g_iLimit[somePlayer][someField2], g_iLimit[somePlayer][someField3]); 


OciXCrom 03-18-2017 10:39

Re: Help with saving an array with tries
 
szUser is the player's name/ip/steamid.
That worked. It printed 7, 13 and 55 as set in the code.

This worked as well:

PHP Code:

public client_putinserver(id)
{
    
g_iLimit[id][someField1] = 0;
    
g_iLimit[id][someField2] = 0;
    
g_iLimit[id][someField3] = 0;
    
    new 
szName[32]
    
get_user_name(idszNamecharsmax(szName))
    
    
TrieGetArray(g_tLimitszNameg_iLimit[id], sizeof(g_iLimit[]));
    
server_print("someField1=%d, someField2=%d, someField3=%d"g_iLimit[id][someField1], g_iLimit[id][someField2], g_iLimit[id][someField3]);  
}

public 
client_disconnect(id)
{
    
g_iLimit[id][someField1] = 7;
    
g_iLimit[id][someField2] = 13;
    
g_iLimit[id][someField3] = 55;
    
    new 
szName[32]
    
get_user_name(idszNamecharsmax(szName))
    
    
TrieSetArray(g_tLimitszNameg_iLimit[id], sizeof(g_iLimit[]));


And, oh..... I just noticed how blind I am. It didn't work for me because I had this line in the beginning of client_putinserver():

PHP Code:

arrayset(g_iLimit[id], 0sizeof(g_iLimit[])) 

Problem solved. :)


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

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