|
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
|

03-17-2017
, 16:04
TrieSetArray
|
#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(PLUGIN, VERSION, AUTHOR) g_tTrie = TrieCreate() Load() set_task(1.0, "hhud", .flags = "b") }
public hhud() { new Data[eventData] TrieGetArray(g_tTrie, eData[eChance], Data[eChance], sizeof Data[eChance]) TrieGetString(g_tTrie, eData[eMessage], Data[eMessage], sizeof Data[eMessage]) set_hudmessage(255, 255, 255, -1.0, 0.0, 0, 1.0, 1.0) show_hudmessage(0, "Chance: %d, Message: %s", Data[eChance], Data[eMessage]) }
public plugin_end() { TrieDestroy(g_tTrie) }
Load() { new File[256] get_configsdir(File, charsmax(File))
add(File, charsmax(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(iFile, szFile, charsmax(szFile))
trim(szFile)
if (szFile[0] == EOS || szFile[0] == ';' || szFile[0] == '/' && szFile[1] == '/') continue
strtok(szFile, Key, charsmax(Key), Value, charsmax(Value), '=') trim(Key) trim(Value) if (equali(Key, "ACE")) { parse(Value, Dummy, charsmax(Dummy), Type, charsmax(Type))
if (equali(Type, "EVENTCHANCE")) { parse ( Value, Dummy, charsmax(Dummy), Type, charsmax(Type), Chance, charsmax(Chance), Dummy, charsmax(Dummy) ) Data[eChance] = str_to_num(Chance) TrieSetArray(g_tTrie, eData[eChance], Data, sizeof Data) }
else if (equali(Type, "MESSAGE")) { strtok(Value, Type, charsmax(Type), Message, charsmax(Message), '@') trim(Message) formatex(Data[eMessage], charsmax(Data[eMessage]), "%s", Message) TrieSetString(g_tTrie, eData[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_tTrie, eData[eChance], Data, sizeof Data) console_print(0, "Chance: %s, Data[eChance]: %d, eData[eChance]: %d", Chance, Data[eChance], eData[eChance])
It shows
Code:
Chance: 2, Data[eChance]: 2, eData[eChance]: 0
__________________
Last edited by EFFx; 03-17-2017 at 16:08.
|
|