I'm trying to find a way to set my ConVars in my "l4d2_player_utils.cfg" file.
Everything in this code works except for the get/set convars in my config. I've tried a lot but the cvars are modified after I do the command but the config doesn't change
Please dont give me advice about other parts of my code, I'm trying to learn more
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <ps_natives>
static Handle:hRoundRespawn = INVALID_HANDLE;
static Handle:hGameConf = INVALID_HANDLE;
new Handle:h_Trie = INVALID_HANDLE;
new pointstimer;
new pointsremindtimer;
new pointsremindtimer2;
public Plugin myinfo =
{
name = "Player Utils",
author = "Cris16228",
description = "Utils for all and Admins",
version = "1.0",
url = "N/A"
};
public void OnPluginStart()
{
h_Trie = CreateTrie();
CreateConVar("is_plugin_enabled","1","Set to 0 if you want to disable the plugin.", _, true,0.0, true,1.0);
CreateConVar("test_mode","0","Set to 1 if the server is in test mode.", _, true,0.0, true, 1.0);
CreateConVar("cost_respawn","120","How many points the respawn cost.", _,true,0.0);
CreateConVar("points_advertising_ticks","120","How many seconds before the reminder is displayed.", _,true,5.0);
CreateConVar("respawn_advertising_ticks","180","How many seconds before the reminder is displayed.", _,true,5.0);
pointsremindtimer = 1;
pointsremindtimer2 = 1;
AutoExecConfig(true, "l4d2_player_utils");
/* Enable plugin */
int enable = GetConVarInt(FindConVar("is_plugin_enabled"));
if (enable == 1)
{
CreateTimer(1.0,TimerUpdate, _, TIMER_REPEAT);
RegConsoleCmd("sm_buyrespawn", BuyRespawn);
RegAdminCmd("sm_test", SetTestMode, ADMFLAG_ROOT);
hGameConf = LoadGameConfigFile("l4drespawn");
if (hGameConf != INVALID_HANDLE)
{
StartPrepSDKCall(SDKCall_Player);
PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, "RoundRespawn");
hRoundRespawn = EndPrepSDKCall();
if (hRoundRespawn == INVALID_HANDLE) SetFailState("L4D_SM_Respawn: RoundRespawn Signature broken");
}
else
{
SetFailState("could not find gamedata file at addons/sourcemod/gamedata/l4drespawn.txt , you FAILED AT INSTALLING");
}
LogMessage("[PU] Plugin enabled and loaded");
}
else
{
SetFailState("[PU] The plugin is disabled");
}
}
public Action:BuyRespawn(client, args)
{
if(IsPlayerAlive(client))
{
ReplyToCommand(client, "\x04[\x05PU\x04] You must be dead to buy the respawn!");
return Plugin_Continue;
}
int icost = GetConVarInt(FindConVar("cost_respawn"));
new Handle:gamemodevar = FindConVar("mp_gamemode");
new String:gamemode[25];
GetConVarString(gamemodevar,gamemode,sizeof(gamemode));
int icostcoop = icost / 2;
if (StrEqual(gamemode,"survival",true))
{
if(!IsPlayerAlive(client) && PS_GetPoints(client) >= icostcoop && IsClientInGame(client))
{
ReplyToCommand(client, "\x04[\x05PU\x04] You currently have %d points",PS_GetPoints(client));
SDKCall(hRoundRespawn, client);
PS_SetBought(client, "revive");
PS_SetPoints(client, PS_GetPoints(client) - icostcoop);
ReplyToCommand(client, "\x04[\x05PU\x04] You successfully bought the respawn for %d points",icost);
decl String:nick[512];
GetClientName(client, nick, sizeof(nick));
PrintToChatAll("\x04[\x05PU\x04] %s bought the respawn for %d points (!buyrespawn).",nick,icostcoop);
}
else
{
int points = PS_GetPoints(client);
int diff = icost - points;
PrintToChat(client, "\x04[\x05PU\x04] I'm sorry but you need %d more points to buy it",diff);
}
return Plugin_Continue;
}
else if (StrEqual(gamemode,"coop",true))
{
if(!IsPlayerAlive(client) && PS_GetPoints(client) >= icostcoop && IsClientInGame(client))
{
ReplyToCommand(client, "\x04[\x05PU\x04] You currently have %d points",PS_GetPoints(client));
SDKCall(hRoundRespawn, client);
PS_SetBought(client, "revive");
PS_SetPoints(client, PS_GetPoints(client) - icostcoop);
ReplyToCommand(client, "\x04[\x05PU\x04] You successfully bought the respawn for %d points",icost);
decl String:nick[512];
GetClientName(client, nick, sizeof(nick));
PrintToChatAll("\x04[\x05PU\x04] %s bought the respawn for %d points (!buyrespawn).",nick,icostcoop);
}
else
{
int points = PS_GetPoints(client);
int diff = icost - points;
PrintToChat(client, "\x04[\x05PU\x04] I'm sorry but you need %d more points to buy it",diff);
}
return Plugin_Continue;
}
return Plugin_Continue;
}
public Action:TimerUpdate(Handle:timer)
{
pointstimer += 1;
if (pointstimer >= GetConVarInt(FindConVar("points_advertising_ticks")) * pointsremindtimer)
{
pointsremindtimer += 1;
PrintToChatAll("\x04[\x05PU\x04] Type !buy to buy items in shop.");
}
if (pointstimer >= GetConVarInt(FindConVar("respawn_advertising_ticks")) * pointsremindtimer2)
{
pointsremindtimer2 += 1;
PrintToChatAll("\x04[\x05PU\x04] If you're dead type !buyrespawn to respawn at the beginning of the map (or saferoom).");
}
}
public OnClientConnected(client)
{
new String:name[512]
int mode = GetConVarInt(FindConVar("test_mode"));
GetClientName(client, name, sizeof(name));
name = "Cris16228";
decl String:nick[512];
GetClientName(client, nick, sizeof(nick));
StrEqual(nick, name, true)
if (!StrEqual(nick, name, true) && !IsFakeClient(client) && mode >= 1)
{
KickClient(client, "The server is currently set in test mode");
PrintToChatAll("\x04[\x05PU\x04] The player %s tried to join.",nick);
LogMessage("[PU] The player %s tried to join.",nick);
}
}
public OnConfigsExecuted()
{
UpdateGeneralTrie();
}
public OnAllPluginsLoaded()
{
SetUpGeneralTrie();
}
public OnPluginEnd()
{
CloseHandle(h_Trie);
}
public SetUpGeneralTrie()
{
//SetTrieString(h_Trie, "plugin_enabled", "sm_cvar ");
//SetTrieValue(h_Trie, "pluginenabled", GetConVarInt(FindConVar("is_plugin_enabled")));
SetTrieString(h_Trie, "whitelist", "sm_cvar test_mode 0");
SetTrieValue(h_Trie, "testmode", GetConVarInt(FindConVar("test_mode")));
SetTrieString(h_Trie, "respawn_cost", "sm_cvar cost_respawn 120");
SetTrieValue(h_Trie, "cost_respawn", GetConVarInt(FindConVar("cost_respawn")));
SetTrieString(h_Trie, "points_advertising", "sm_cvar points_advertising_ticks 120");
SetTrieValue(h_Trie, "pointsadvertisingticks", GetConVarInt(FindConVar("points_advertising_ticks")));
SetTrieString(h_Trie, "respawn_advertising", "sm_cvar respawn_advertising_ticks 180");
SetTrieValue(h_Trie, "respawnadvertisingticks", GetConVarInt(FindConVar("respawn_advertising_ticks")));
}
public UpdateGeneralTrie()
{
//SetTrieValue(h_Trie, "pluginenabled", GetConVarInt(FindConVar("is_plugin_enabled")), true);
SetTrieValue(h_Trie, "testmode", GetConVarInt(FindConVar("test_mode")), true);
SetTrieValue(h_Trie, "cost_respawn", GetConVarInt(FindConVar("cost_respawn")), true);
SetTrieValue(h_Trie, "pointsadvertisingticks", GetConVarInt(FindConVar("points_advertising_ticks")), true);
SetTrieValue(h_Trie, "respawnadvertisingticks", GetConVarInt(FindConVar("respawn_advertising_ticks")), true);
}