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", ChatCmd, ADMFLAG_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 client, int args)
{
char chat[32];
int choice = -1;
GetCmdArg( 1, chat, sizeof(chat) );
g_hMap.GetValue(chat, choice);
switch(choice)
{
case 0: //sm_mycmd foo – do this
case 1: //sm_mycmd bar – do that
default: //sm_mycmd ??? – do whatever
}
return Plugin_Handled;
}