Raised This Month: $ Target: $400
 0% 

[Tries] How to set 2 or more strings in one trie with one key


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 08-03-2014 , 10:00   [Tries] How to set 2 or more strings in one trie with one key
Reply With Quote #1

Hey! I am currently trying to make something like a GAG plugin. But I was wondering how can I set two or more strings in one trie with the same key if it is possible. I'm talking about reason, time and date, and admin name of the gag. The code for now:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <colorchat>

#define PLUGIN "GAG"
#define VERSION "1.0"
#define AUTHOR "Flicker"

new const szPrefix[] = "[GAG]"

const ACCESS ADMIN_BAN

new Trie:g_tGaggedPlayers

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_concmd("amx_gag""cmdGag"ACCESS"<nick> <time> ^"reason^"")
    
register_concmd("amx_ungag""cmdUnGag"ACCESS"<nick>")
    
    
register_clcmd("say""cmdSay")
    
register_clcmd("say_team""cmdSay")
    
    
g_tGaggedPlayers TrieCreate()
}

public 
cmdSay(id)
{
    new 
szID[16]
    
get_user_ip(idszIDcharsmax(szID), 1)
    
    new 
num
    
if(TrieGetCell(g_tGaggedPlayersszIDnum))
    {
        new 
szReason[32]
        
TrieGetString(g_tGaggedPlayersszIDszReasoncharsmax(szReason))
        
        
gChat(id"You are gagged")
    }
}

public 
cmdGag(idlevelcid)
{
    if(!
cmd_access(idlevelcid4))
        return 
PLUGIN_HANDLED
        
    
new arg1[32], arg2[32], arg3[32]
    
read_argv(1arg1charsmax(arg1))
    
read_argv(2arg2charsmax(arg2))
    
read_argv(3arg3charsmax(arg3))
    
    new 
target cmd_target(idarg10)
    new 
itime str_to_num(arg2)
    
    new 
szID[16]
    
get_user_authid(targetszIDcharsmax(szID))
    
    
TrieSetCell(g_tGaggedPlayersszID1)
    
TrieSetString(g_tGaggedPlayersszIDarg3)
}

stock gChat(const id, const szMsg[], any:...)
{
    new 
szText[192]
    
vformat(szTextcharsmax(szText), szMsg3)
    
ColorChat(idGREEN"%s^1 %s"szPrefixszText)
}

public 
plugin_end()
    
TrieDestroy(g_tGaggedPlayers
There is TrieSetString - but I think that it is for only one string. So, how can I put the reason, the name of admin and the date and time. Thanks!
And maybe it will be better to use Array?
__________________

Last edited by Flick3rR; 08-03-2014 at 10:02.
Flick3rR is offline
Send a message via Skype™ to Flick3rR
GordonFreeman (RU)
Veteran Member
Join Date: Jan 2010
Location: Uzbekistan
Old 08-03-2014 , 10:27   Re: [Tries] How to set 2 or more strings in one trie with one key
Reply With Quote #2

Use data structs.

Here is small example:
Code:
enum _:dataStruct {     STR1[128],     STR2[128],     STR3[128] } public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         new Trie:t = TrieCreate()         new dataArray[dataStruct],dataArray2[dataStruct]         copy(dataArray[STR1],charsmax(dataArray[STR1]),"TEST1")     copy(dataArray[STR2],charsmax(dataArray[STR2]),"TEST3")     copy(dataArray[STR3],charsmax(dataArray[STR3]),"TEST4")         TrieSetArray(t,"test",dataArray,dataStruct)     TrieGetArray(t,"test",dataArray2,dataStruct) }
__________________
The functional way is the right way
GordonFreeman (RU) is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 08-03-2014 , 10:52   Re: [Tries] How to set 2 or more strings in one trie with one key
Reply With Quote #3

I've figured out that, thanks! Just to say, I prefered using arrays.
Case closed!
P.S.: To everyone needing the same information - you may take a look at JailBreak Gang System plugin, which contains pretty useful and easy-readable examples of working with arrays!
__________________

Last edited by Flick3rR; 08-03-2014 at 10:53.
Flick3rR is offline
Send a message via Skype™ to Flick3rR
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 23:00.


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