Raised This Month: $ Target: $400
 0% 

TrieSetArray


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 03-17-2017 , 16:04   TrieSetArray
Reply With Quote #1

I was trying to learn about Tries, but I'm so confused then I decided to post it here.

Thats my code:

PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

enum eventData
{
    
eChance,
    
eMessage[45]
}

new 
eData[eventData]

new 
Trie:g_tTrie

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
g_tTrie TrieCreate()
    
    
Load()
    
    
set_task(1.0"hhud", .flags "b")
}

public 
hhud()
{
    new 
Data[eventData]
    
TrieGetArray(g_tTrieeData[eChance], Data[eChance], sizeof Data[eChance])
    
TrieGetString(g_tTrieeData[eMessage], Data[eMessage], sizeof Data[eMessage])
    
    
set_hudmessage(255255255, -1.00.001.01.0)
    
show_hudmessage(0"Chance: %d, Message: %s"Data[eChance], Data[eMessage])
}

public 
plugin_end()
{
    
TrieDestroy(g_tTrie)
}

Load()
{
    new 
File[256]
    
get_configsdir(Filecharsmax(File))

    
add(Filecharsmax(File), "/example.ini")

    new 
iFile fopen(File"r")
    if (!
iFile)
        return

    new 
Data[eventData
    new 
szFile[512], Key[64], Value[256], Type[32], Chance[4], Dummy[4], Message[256]

    while (!
feof(iFile))
    {
        
fgets(iFileszFilecharsmax(szFile))

        
trim(szFile)

        if (
szFile[0] == EOS || szFile[0] == ';' || szFile[0] == '/' && szFile[1] == '/')
            continue

        
strtok(szFileKeycharsmax(Key), Valuecharsmax(Value), '=')
        
        
trim(Key)
        
trim(Value)
        
        if (
equali(Key"ACE"))
        {
            
parse(ValueDummycharsmax(Dummy), Typecharsmax(Type))

            if (
equali(Type"EVENTCHANCE"))
            {
                
parse
                
(
                    
Value
                    
Dummycharsmax(Dummy), 
                    
Typecharsmax(Type), 
                    
Chancecharsmax(Chance),
                    
Dummycharsmax(Dummy)
                )
                
                
Data[eChance] = str_to_num(Chance)
                
TrieSetArray(g_tTrieeData[eChance], Datasizeof Data)
            }

            else if (
equali(Type"MESSAGE"))
            {
                
strtok(ValueTypecharsmax(Type), Messagecharsmax(Message), '@')
                
trim(Message)
                
                
formatex(Data[eMessage], charsmax(Data[eMessage]), "%s"Message)
                
                
TrieSetString(g_tTrieeData[eMessage], Data[eMessage])
            }
        }    
    }


The problem is: The Chance is showing 0, why?

.ini:

Code:
ACE = 1 EVENTCHANCE 2 
ACE = 1 MESSAGE @ You just clutched!
I've added a debug:

PHP Code:
Data[eChance] = str_to_num(Chance)
TrieSetArray(g_tTrieeData[eChance], Datasizeof Data)
                
console_print(0"Chance: %s, Data[eChance]: %d, eData[eChance]: %d"ChanceData[eChance], eData[eChance]) 
It shows

Code:
Chance: 2, Data[eChance]: 2, eData[eChance]: 0
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 03-17-2017 at 16:08.
EFFx is offline
 


Thread Tools
Display Modes

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 18:04.


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