Alright, so initially I was using a sourcemod plugin to open a keyvalues file, and pull out the settings for game modes. However, now more than one plugin need this information and I decided it would be much easier to just open this config file once, store the settings in c++ in a struct or something similar, and create a native to pull out the data I needed. I have hit a road block though, as I didnt completely think through how to set it up, so I am hoping theres something similar I can do.
Basically I have this, which opens the config file, pulls out the settings and sticks them in my struct.
Code:
void CBaseGameRules::ParseGameSettings()
{
char path[256];
KeyValues *kv = new KeyValues("GameSettings");
g_pSM->BuildPath(Path_SM, path, sizeof(path)-1, "rocketarena/configs/gamemode_settings.cfg");
kv->LoadFromFile(filesystem, path);
KeyValues *cv = kv->FindKey(g_szGameMode);
if(cv)
{
gamesettings_t.default_health = cv->GetInt("default_health");
gamesettings_t.default_armor = cv->GetInt("default_armor");
gamesettings_t.powerups_enabled = cv->GetInt("enable_powerups");
gamesettings_t.selfdamage_enabled = cv->GetInt("enable_selfdamage");
gamesettings_t.falldamage_enabled = cv->GetInt("enable_falldamage");
gamesettings_t.max_rocketammo = cv->GetInt("max_rocketammo");
gamesettings_t.max_grenadeammo = cv->GetInt("max_grenadeammo");
gamesettings_t.max_railgunammo = cv->GetInt("max_railgunammo");
gamesettings_t.max_lightningammo = cv->GetInt("max_lightningammo");
gamesettings_t.max_shotgunammo = cv->GetInt("max_shotgunammo");
gamesettings_t.max_plasmaammo = cv->GetInt("max_plasmaammo");
gamesettings_t.max_machinegunammo = cv->GetInt("max_machinegunammo");
gamesettings_t.enable_rocketlauncher = cv->GetInt("enable_rocketlauncher");
gamesettings_t.enable_grenadelauncher = cv->GetInt("enable_grenadelauncher");
gamesettings_t.enable_railgun = cv->GetInt("enable_railgun");
gamesettings_t.enable_lightninggun = cv->GetInt("enable_lightninggun");
gamesettings_t.enable_shotgun = cv->GetInt("enable_shotgun");
gamesettings_t.enable_plasmagun = cv->GetInt("enable_plasmagun");
gamesettings_t.enable_machinegun = cv->GetInt("enable_machinegun");
gamesettings_t.enable_melee = cv->GetInt("enable_melee");
}
}
Then I was going to try and do something like this with a native to retrieve the data I needed, but it doesnt work since 'str' isnt a member of the struct. So I am wondering if something similar is possible, or if im going to have to go with a much slower method such as hash maps, or something not as clean like arrays.
Code:
cell_t GetGamemodeSetting(IPluginContext *pContext, const cell_t *params)
{
//Get the setting string pointer for Param[1]
char *str;
pContext->LocalToString(params[1], &str);
int ret = 0;
//ret = *(&gamesettings_t.str();
ret = gamesettings_t.str();
return ret;
}
__________________