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

Creating custom chat triggers for pre-compiled plugins


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Loof27
New Member
Join Date: Aug 2022
Old 08-30-2022 , 19:06   Creating custom chat triggers for pre-compiled plugins
Reply With Quote #1

I have a CSGO server I host as just a practice server for my discord, and I have been trying to find a way for users to easily change the tickrate of the server for nade lineups. I found this (https://forums.alliedmods.net/showthread.php?t=319147) plugin which lets me easily change it from console, but I want it to be user facing so the tickrate can be changed just from a chat command. From my (VERY very limited) understanding of sourcemod plugins, if a cvar is created with the sm_ prefix, there is an auto generated chat trigger. The issue is that the included cvars don't use the sm_ prefix, and while I do have access to the .sp file so I can change the cvar, it gives me an error while compiling. I probably need some 3rd party dependency but I don't know what it is.

I found a plugin that looks like it lets you make custom chat triggers here (https://github.com/MoritzLoewenstein/ChatTriggers), but it gives an error on startup and I don't know sourcemod well enough to even attempt to fix it

Is there a super easy way to do this and I'm just stupid? How am I supposed to make a chat trigger for a console command?

Last edited by Loof27; 08-30-2022 at 19:09. Reason: grammar
Loof27 is offline
azalty
AlliedModders Donor
Join Date: Feb 2020
Location: France
Old 09-04-2022 , 10:19   Re: Creating custom chat triggers for pre-compiled plugins
Reply With Quote #2

You need to run the TickRateControl plugin.
Then, compile the plugin below. Don't forget to use the include file TickRateControl.inc from https://forums.alliedmods.net/showthread.php?t=319147

PHP Code:
#include <sourcemod>
#include <TickRateControl>

ConVar g_hForceRetry;

public 
Plugin myinfo 
{
    
name "Change tickrate",
    
author "azalty",
    
description "Allows players to change the server's tickrate with sm_tickrate",
    
version "1.0.0",
    
url "forums.alliedmods.net/showpost.php?p=2788087&postcount=2"
}

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_tickrate"Cmd_Tickrate);
}

public 
void OnAllPluginsLoaded()
{
    if (!
g_hForceRetry)
        
g_hForceRetry FindConVar("tickrate_force_retry");
}

Action Cmd_Tickrate(int clientint args)
{
    if (
args != 1)
    {
        
ReplyToCommand(client"Usage: sm_tickrate (tickrate)");
        return 
Plugin_Handled;
    }
    
char sArg[16];
    
GetCmdArg(1sArgsizeof(sArg));
    
    
float tickrate StringToFloat(sArg);
    if (!(
21.0 <= tickrate <= 128.0))
    {
        
ReplyToCommand(client"Invalid tickrate, please use a value between 21 and 128.");
        return 
Plugin_Handled;
    }
    
    
ReplyToCommand(client"Changing tickrate to %.1f"tickrate);
    
    if (
g_hForceRetry)
        
TickRate_SetTickRate(tickrateg_hForceRetry.BoolValue);
    else
        
TickRate_SetTickRate(tickrate);
    
    return 
Plugin_Handled;

If you want to restrict the access to the command, just modify admin_overrides.cfg for the sm_tickrate command
__________________
GitHub | Discord: @azalty | Steam

Last edited by azalty; 09-04-2022 at 10:22. Reason: added return Plugin_Handled and this post's link as the plugin url
azalty is offline
Loof27
New Member
Join Date: Aug 2022
Old 09-05-2022 , 00:57   Re: Creating custom chat triggers for pre-compiled plugins
Reply With Quote #3

Quote:
Originally Posted by azalty View Post
You need to run the TickRateControl plugin.
Then, compile the plugin below. Don't forget to use the include file TickRateControl.inc from https://forums.alliedmods.net/showthread.php?t=319147

PHP Code:
#include <sourcemod>
#include <TickRateControl>

ConVar g_hForceRetry;

public 
Plugin myinfo 
{
    
name "Change tickrate",
    
author "azalty",
    
description "Allows players to change the server's tickrate with sm_tickrate",
    
version "1.0.0",
    
url "forums.alliedmods.net/showpost.php?p=2788087&postcount=2"
}

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_tickrate"Cmd_Tickrate);
}

public 
void OnAllPluginsLoaded()
{
    if (!
g_hForceRetry)
        
g_hForceRetry FindConVar("tickrate_force_retry");
}

Action Cmd_Tickrate(int clientint args)
{
    if (
args != 1)
    {
        
ReplyToCommand(client"Usage: sm_tickrate (tickrate)");
        return 
Plugin_Handled;
    }
    
char sArg[16];
    
GetCmdArg(1sArgsizeof(sArg));
    
    
float tickrate StringToFloat(sArg);
    if (!(
21.0 <= tickrate <= 128.0))
    {
        
ReplyToCommand(client"Invalid tickrate, please use a value between 21 and 128.");
        return 
Plugin_Handled;
    }
    
    
ReplyToCommand(client"Changing tickrate to %.1f"tickrate);
    
    if (
g_hForceRetry)
        
TickRate_SetTickRate(tickrateg_hForceRetry.BoolValue);
    else
        
TickRate_SetTickRate(tickrate);
    
    return 
Plugin_Handled;

If you want to restrict the access to the command, just modify admin_overrides.cfg for the sm_tickrate command
Thank you, this worked perfectly! It took me a solid minute to figure out I had to compile the this with the other plugin loaded in the same instance of sourcemod. I have my server loaded on a separate headless machine and I just re-downloaded sourcemod on my main pc to compile it, but once I realized what you meant it was pretty straightforward
Loof27 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 14:06.


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