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

how to set a specific admin previlege to use a ConVar


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pillowCloud
Member
Join Date: Aug 2015
Location: AlliedModders
Old 06-05-2019 , 14:59   how to set a specific admin previlege to use a ConVar
Reply With Quote #1

hi, i want to set a specific admin previlege for a ConVar.

i want to do something like this, but it's not working:
PHP Code:
Handle:GambleChance INVALID_HANDLE;

public 
void OnPluginStart()
{
    
GambleChance CreateConVar("gamble_chance""50""Sets gamble winning chance"ADMFLAG_RCON);


Last edited by pillowCloud; 06-05-2019 at 15:24.
pillowCloud is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 06-05-2019 , 16:57   Re: how to set a specific admin previlege to use a ConVar
Reply With Quote #2

PHP Code:
#include <sourcemod>

ConVar GambleChance;

public 
OnPluginStart()
{
    
GambleChance CreateConVar("gamble_chance""50""Sets gamble winning chance");
    
RegAdminCmd("sm_set_gamble_chance"SetGambleChanceCMDADMFLAG_RCON".");
}

public 
Action:SetGambleChanceCMD(clientargs)
{
    if (
args 1)
    {
        
PrintToChat(client"Usage: sm_set_gamble_chance <value>");
        return 
Plugin_Handled;
    }

    new 
String:sValue[256]; 
    
GetCmdArg(1sValuesizeof(sValue)); 
    
    new 
value StringToInt(sValue);
    
    
GambleChance.IntValue value;
    
//ServerCommand("gamble_chance %i", value);
    
    
PrintToChat(client"You've set the value of gamble_chance to %i."value);
    
    return 
Plugin_Handled;

__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards is offline
pillowCloud
Member
Join Date: Aug 2015
Location: AlliedModders
Old 06-07-2019 , 09:38   Re: how to set a specific admin previlege to use a ConVar
Reply With Quote #3

Quote:
Originally Posted by 1337norway View Post
PHP Code:
#include <sourcemod>

ConVar GambleChance;

public 
OnPluginStart()
{
    
GambleChance CreateConVar("gamble_chance""50""Sets gamble winning chance");
    
RegAdminCmd("sm_set_gamble_chance"SetGambleChanceCMDADMFLAG_RCON".");
}

public 
Action:SetGambleChanceCMD(clientargs)
{
    if (
args 1)
    {
        
PrintToChat(client"Usage: sm_set_gamble_chance <value>");
        return 
Plugin_Handled;
    }

    new 
String:sValue[256]; 
    
GetCmdArg(1sValuesizeof(sValue)); 
    
    new 
value StringToInt(sValue);
    
    
GambleChance.IntValue value;
    
//ServerCommand("gamble_chance %i", value);
    
    
PrintToChat(client"You've set the value of gamble_chance to %i."value);
    
    return 
Plugin_Handled;

hi,
firstable, thanks for your help.

the problem is that anyone with ADMIN_CVAR privilege can also change this cvar, and i need to make it useable only for admins with ADMIN_RCON privilege.

Last edited by pillowCloud; 06-07-2019 at 09:39.
pillowCloud is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 06-07-2019 , 12:39   Re: how to set a specific admin previlege to use a ConVar
Reply With Quote #4

Maybe this will work:

PHP Code:
#include <sourcemod>

ConVar GambleChance;
bool:AllowChange false;

public 
OnPluginStart()
{
    
GambleChance CreateConVar("gamble_chance""50""Sets gamble winning chance");
    
RegAdminCmd("sm_set_gamble_chance"SetGambleChanceCMDADMFLAG_RCON".");
    
HookConVarChange(GambleChanceOnConVarChange)
}

public 
OnConVarChange(Handle:convar, const String:oldValue[], const String:newValue[])
{
    if(
AllowChange)
        return;
    
    
GambleChance.IntValue StringToInt(oldValue);
    return;
}

public 
Action:SetGambleChanceCMD(clientargs)
{
    if (
args 1)
    {
        
PrintToChat(client"Usage: sm_set_gamble_chance <value>");
        return 
Plugin_Handled;
    }

    new 
String:sValue[256]; 
    
GetCmdArg(1sValuesizeof(sValue)); 
    
    new 
value StringToInt(sValue);
    
    
AllowChange true;
    
    
GambleChance.IntValue value;

    
AllowChange false;
    
    
PrintToChat(client"You've set the value of gamble_chance to %i."value);
    
    return 
Plugin_Handled;

__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards is offline
pillowCloud
Member
Join Date: Aug 2015
Location: AlliedModders
Old 06-12-2019 , 13:25   Re: how to set a specific admin previlege to use a ConVar
Reply With Quote #5

Quote:
Originally Posted by 1337norway View Post
Maybe this will work:

PHP Code:
#include <sourcemod>

ConVar GambleChance;
bool:AllowChange false;

public 
OnPluginStart()
{
    
GambleChance CreateConVar("gamble_chance""50""Sets gamble winning chance");
    
RegAdminCmd("sm_set_gamble_chance"SetGambleChanceCMDADMFLAG_RCON".");
    
HookConVarChange(GambleChanceOnConVarChange)
}

public 
OnConVarChange(Handle:convar, const String:oldValue[], const String:newValue[])
{
    if(
AllowChange)
        return;
    
    
GambleChance.IntValue StringToInt(oldValue);
    return;
}

public 
Action:SetGambleChanceCMD(clientargs)
{
    if (
args 1)
    {
        
PrintToChat(client"Usage: sm_set_gamble_chance <value>");
        return 
Plugin_Handled;
    }

    new 
String:sValue[256]; 
    
GetCmdArg(1sValuesizeof(sValue)); 
    
    new 
value StringToInt(sValue);
    
    
AllowChange true;
    
    
GambleChance.IntValue value;

    
AllowChange false;
    
    
PrintToChat(client"You've set the value of gamble_chance to %i."value);
    
    return 
Plugin_Handled;

Thanks alot, it's working great!
pillowCloud 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 18:42.


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