Raised This Month: $ Target: $400
 0% 

[CS:GO] Let admins run a cvar command from game chat


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alster551
Junior Member
Join Date: Sep 2016
Old 09-22-2016 , 09:18   [CS:GO] Let admins run a cvar command from game chat
Reply With Quote #1

I'm new to this sourcemod/sourcepawn/C++ coding, and i'm trying to make a "simple" plugin that lets admins extend the map time by x amount, simply by typing !extend x in the game chat.

I'm continuously getting errors, which I seem to fix, yet when I run the command nothing happens in game (it recognizes it as a command, but wont do anything)

Currently I have this:

Code:
public void OnPluginStart()
{
	RegAdminCmd("sm_extend", Command_Extend, ADMFLAG_KICK, "Extends the map by a given time");
}
public Action Command_Extend(int client, int args)
{
	if (args < 1 || args > 1)
	{
		PrintToConsole(client, "Usage: sm_extend <time to extend map by>");
		PrintToChat(client, "Usage: sm_extend <time to extend map by>");
		return Plugin_Handled;
	}
	
	char arg1[32];
	
	new timeLimit;
	new arg2;
	new timeLimitCvar;
	
	timeLimitCvar = GetConVarInt("mp_timelimit");
	
	arg2 = GetCmdArg(1, arg1, sizeof(arg1));
	
	timeLimit = timeLimitCvar + arg2;
	
	ServerCommand("mp_timelimit %s", timeLimit)
 
	return Plugin_Handled;
}
Im currently getting error 35 on line 32 (timeLimitCvar = GetConVarInt("mp_timelimit");)

Does anyone know what i'm doing wrong? Like I said im new to this stuff, but id like to think its something simple
alster551 is offline
good_live
AlliedModders Donor
Join Date: Oct 2013
Old 09-22-2016 , 09:29   Re: [CS:GO] Let admins run a cvar command from game chat
Reply With Quote #2

GetConVarInt requiers a handle as first parameter:
https://sm.alliedmods.net/new-api/convars/GetConVarInt

You could get the handle with https://sm.alliedmods.net/new-api/convars/FindConVar.

Also:
PHP Code:
if (args || args 1
is equal to
PHP Code:
if(args != 1
which is easier to read ^^

Last edited by good_live; 09-22-2016 at 09:29.
good_live is offline
alster551
Junior Member
Join Date: Sep 2016
Old 09-22-2016 , 09:36   Re: [CS:GO] Let admins run a cvar command from game chat
Reply With Quote #3

Quote:
Originally Posted by good_live View Post
GetConVarInt requiers a handle as first parameter:
https://sm.alliedmods.net/new-api/convars/GetConVarInt

You could get the handle with https://sm.alliedmods.net/new-api/convars/FindConVar.

Also:
PHP Code:
if (args || args 1
is equal to
PHP Code:
if(args != 1
which is easier to read ^^
I see, how would I actually implement that handle though? I'm a complete noob
alster551 is offline
good_live
AlliedModders Donor
Join Date: Oct 2013
Old 09-22-2016 , 09:45   Re: [CS:GO] Let admins run a cvar command from game chat
Reply With Quote #4

PHP Code:
ConVar g_cTimeLimit;

public 
void OnPluginStart()
{
    
RegAdminCmd("sm_extend"Command_ExtendADMFLAG_KICK"Extends the map by a given time");
    
g_cTimeLimit FindConVar("mp_timelimit");
}
public 
Action Command_Extend(int clientint args)
{
    if (
args != 1)
    {
        
ReplyToCommand(client"Usage: sm_extend <time to extend map by>");
        return 
Plugin_Handled;
    }
    
    
char sArg[32];
    
GetCmdArg(1sArgsizeof(sArg));
    
    
int iExtendTime StringToInt(sArg);
    
    if(
iExtendTime <= 0)
    {
        
ReplyToCommand(client"You can only extend the maptime!");
        return 
Plugin_Handled;
    }
    
    
g_cTimeLimit.IntValue += iExtendTime;
    return 
Plugin_Handled;

Haven't tested that.
good_live is offline
alster551
Junior Member
Join Date: Sep 2016
Old 09-22-2016 , 09:50   Re: [CS:GO] Let admins run a cvar command from game chat
Reply With Quote #5

Quote:
Originally Posted by good_live View Post
PHP Code:
ConVar g_cTimeLimit;

public 
void OnPluginStart()
{
    
RegAdminCmd("sm_extend"Command_ExtendADMFLAG_KICK"Extends the map by a given time");
    
g_cTimeLimit FindConVar("mp_timelimit");
}
public 
Action Command_Extend(int clientint args)
{
    if (
args != 1)
    {
        
ReplyToCommand(client"Usage: sm_extend <time to extend map by>");
        return 
Plugin_Handled;
    }
    
    
char sArg[32];
    
GetCmdArg(1sArgsizeof(sArg));
    
    
int iExtendTime StringToInt(sArg);
    
    if(
iExtendTime <= 0)
    {
        
ReplyToCommand(client"You can only extend the maptime!");
        return 
Plugin_Handled;
    }
    
    
g_cTimeLimit.IntValue += iExtendTime;
    return 
Plugin_Handled;

Haven't tested that.
That works! Thanks!
alster551 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 21:19.


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