Raised This Month: $ Target: $400
 0% 

TrieSetArray


Post New Thread Reply   
 
Thread Tools Display Modes
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
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-17-2017 , 16:11   Re: TrieSetArray
Reply With Quote #2

eData is never set.

Also, you misunderstand something about Trie. You associate a key (string) to a value (cell, string or array).
I'm not totally sure what you're trying to do with Trie here.
__________________

Last edited by Arkshine; 03-17-2017 at 16:13.
Arkshine is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 03-17-2017 , 16:23   Re: TrieSetArray
Reply With Quote #3

I'm just trying to understand more than now. Like how to get a value in string, array, because that tutorial haven't all things - https://forums.alliedmods.net/showthread.php?t=201872
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-17-2017 , 17:06   Re: TrieSetArray
Reply With Quote #4

This tutorial has examples on how to retrieve a string or array.

You should explain what you don't understand exactly. If you mean dealing with enum structure which can include array/string, then you need Trie*Array (last example of the link). You should first fix your code to use a real key.
__________________

Last edited by Arkshine; 03-17-2017 at 17:13.
Arkshine is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 03-17-2017 , 17:48   Re: TrieSetArray
Reply With Quote #5

I already fixed it by myself. I can post the solution here but its about the my Round End Events, so will not be helpful to others members.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx 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 18:04.


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