Raised This Month: $51 Target: $400
 12% 

[L4D2] Get and Set convar values in a config


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
_Cri_
New Member
Join Date: May 2019
Old 05-15-2019 , 03:44   [L4D2] Get and Set convar values in a config
Reply With Quote #1

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.0true,1.0);
    
CreateConVar("test_mode","0","Set to 1 if the server is in test mode."_true,0.0true1.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"SetTestModeADMFLAG_ROOT);
        
hGameConf LoadGameConfigFile("l4drespawn");
        if (
hGameConf != INVALID_HANDLE)
        {
            
StartPrepSDKCall(SDKCall_Player);
            
PrepSDKCall_SetFromConf(hGameConfSDKConf_Signature"RoundRespawn");
            
hRoundRespawn EndPrepSDKCall();
            if (
hRoundRespawn == INVALID_HANDLESetFailState("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(clientargs)
{
    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(hRoundRespawnclient);
            
PS_SetBought(client"revive");
            
PS_SetPoints(clientPS_GetPoints(client) - icostcoop);
            
ReplyToCommand(client"\x04[\x05PU\x04] You successfully bought the respawn for %d points",icost);
            
decl String:nick[512];
            
GetClientName(clientnicksizeof(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(hRoundRespawnclient);
            
PS_SetBought(client"revive");
            
PS_SetPoints(clientPS_GetPoints(client) - icostcoop);
            
ReplyToCommand(client"\x04[\x05PU\x04] You successfully bought the respawn for %d points",icost);
            
decl String:nick[512];
            
GetClientName(clientnicksizeof(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(clientnamesizeof(name));
    
name "Cris16228";
    
decl String:nick[512];
    
GetClientName(clientnicksizeof(nick));
    
StrEqual(nicknametrue)
    if (!
StrEqual(nicknametrue) && !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);


Last edited by _Cri_; 05-17-2019 at 04:16.
_Cri_ is offline
CliptonHeist
Senior Member
Join Date: Feb 2016
Old 05-15-2019 , 04:52   Re: [L4D2] Get and Set convar values in a config
Reply With Quote #2

You're not writing to the config file at any point? Although, I wouldn't recommend trying to set convars this way as the cfg files that are created by your plugin are usually setup by the server owner how they like them, so if you go and mess with them whenever a command is run people aren't going to be happy.

Last edited by CliptonHeist; 05-15-2019 at 05:00.
CliptonHeist 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 09:34.


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