Raised This Month: $ Target: $400
 0% 

Solved Using hash maps (CreateTrie)?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kerouha
Member
Join Date: Jul 2015
Location: Russian Federation
Old 07-06-2023 , 08:18   Using hash maps (CreateTrie)?
Reply With Quote #1

How does one properly define hash maps in their code, so it's there when needed and destroyed when not? I want to use it as a sort of string switch. There is no need for it to be changed/redefined during gameplay, I still have to close it somehow?

Game is L4D2.

PHP Code:
StringMap g_hMap;

public 
void OnPluginStart()
{
    
RegAdminCmd("sm_mycmd"ChatCmdADMFLAG_GENERIC"Do something");
}

public 
void OnMapStart()
{
    
g_hMap CreateTrie();
    
FillHashMap();
}

public 
void OnMapEnd()
{
    
ClearTrie(g_hMap);
}

void FillHashMap()
{
    
g_hMap.SetValue(g_hMap"foo"0);
    
g_hMap.SetValue(g_hMap"bar"1);
    
//etc
}

Action ChatCmd(int clientint args)
{
    
char chat[32];
    
int choice = -1;

    
GetCmdArg1chatsizeof(chat) );
    
g_hMap.GetValue(chatchoice);

    switch(
choice)
    {
    case 
0//sm_mycmd foo – do this
    
case 1//sm_mycmd bar – do that
    
default: //sm_mycmd ??? – do whatever
    
}

    return 
Plugin_Handled;


Last edited by Kerouha; 07-11-2023 at 03:15. Reason: No longer relevant, code in post is fine
Kerouha 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 11:09.


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