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

Help creating delay to use command


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Piksu
Junior Member
Join Date: Oct 2016
Old 06-30-2019 , 11:42   Help creating delay to use command
Reply With Quote #1

Hello,

I'm trying to add an antispam feature to simple chat trigger plugin.

#include <sourcemod>

public Plugin myinfo =
{
name = "Messager",
author = "",
description = "Send message via chat triggers",
version = "1.0",
url = ""
};

public void OnPluginStart()
{
RegConsoleCmd("discord", Command_discord);
}

public Action Command_discord(int client, int args)
{
PrintToChatAll("Link to Discord server")
return Plugin_Handled;
}

This works as it should but it can be spammed by users. What would be the easiest way to add 5-second delay to each PrintToChatAll action?
Piksu is offline
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 06-30-2019 , 13:25   Re: Help creating delay to use command
Reply With Quote #2

shouldn't antiflood take care of that?
__________________
I do make plugins upon requests, so hit me up on discord if you're interested: Stefan Milivojevic#5311
I am inevitable is offline
Piksu
Junior Member
Join Date: Oct 2016
Old 06-30-2019 , 14:01   Re: Help creating delay to use command
Reply With Quote #3

Quote:
Originally Posted by I am inevitable View Post
shouldn't antiflood take care of that?
It does block it after a few messages but it still creates a lot of spam. Hence I would like to add the 5-second delay.
Piksu is offline
midnight9
Senior Member
Join Date: Nov 2012
Old 06-30-2019 , 14:10   Re: Help creating delay to use command
Reply With Quote #4

You could change PrintToChatAll("Link to Discord server") to PrintToChat(client, "Link to Discord server") so the message is only displayed to player that executes command?
midnight9 is offline
Piksu
Junior Member
Join Date: Oct 2016
Old 06-30-2019 , 14:15   Re: Help creating delay to use command
Reply With Quote #5

Quote:
Originally Posted by midnight9 View Post
You could change PrintToChatAll("Link to Discord server") to PrintToChat(client, "Link to Discord server") so the message is only displayed to player that executes command?
The plugin has other chat triggers also which arent showed in my code above. The plugin is also meant to be used as rules reminder by players when needed. ( Like !freeday shows freedays rules) Anyway thanks for help!
Piksu is offline
Pilo
AlliedModders Donor
Join Date: Jan 2019
Location: Israel
Old 06-30-2019 , 14:55   Re: Help creating delay to use command
Reply With Quote #6

PHP Code:
#include <sourcemod>

public Plugin myinfo =
{
    
name "Messager",
    
author "",
    
description "Send message via chat triggers",
    
version "1.0",
    
url ""
};

public 
void OnPluginStart()
{
    
RegConsoleCmd("discord"Command_discord);
}

public 
Action Command_discord(int clientint args)
{
    if (
IsClientInGame(client) && !IsFakeClient(client))
    {
        
PrintToChat(client"\x04https://discord.gg/******");
    }
    return 
Plugin_Handled;

__________________

Taking Private(PAID) Plugins In PM
Feel free to Donate with PayPal
Feel free to message me in Discord Pilo#8253
Total donated : 25$
Pilo is offline
Pilo
AlliedModders Donor
Join Date: Jan 2019
Location: Israel
Old 06-30-2019 , 15:01   Re: Help creating delay to use command
Reply With Quote #7

PHP Code:
#include <sourcemod>

float g_fSeconds[MAXPLAYERS 1];
ConVar gcv_WaitTime;

public 
Plugin myinfo =
{
    
name "Messager",
    
author "",
    
description "Send message via chat triggers",
    
version "1.0",
    
url ""
};

public 
void OnPluginStart()
{
    
RegConsoleCmd("discord"Command_discord);
    
gcv_WaitTime CreateConVar("sm_discord_command_wait_time""5.0""!discord Wait time (Note : must be float!)");
}

public 
void OnClientConnected(int client)
{
    
g_fSeconds[client] = 0.0;
}

public 
void OnClientDisconnect(int client)
{
    
g_fSeconds[client] = 0.0;
}

public 
Action Command_discord(int clientint args)
{
    if (
IsClientInGame(client) && !IsFakeClient(client))
    {
        if (
g_fSeconds[client] > 0.0)
        {
            
PrintToChat(client"You need to wait %f more time to use this command."g_fSeconds[client]);
        }
        else
        {
            
PrintToChatAll("\x04https://discord.gg/******");
        }
        
g_fSeconds[client] = GetConVarFloat(gcv_WaitTime);
        
CreateTimer(1.0Timer_CooldownclientTIMER_REPEAT);
    }
    return 
Plugin_Handled;
}

public 
Action Timer_Cooldown(Handle timerany data)
{
    
int client data;
    if (
g_fSeconds[client] > 0.0)
    {
        
g_fSeconds[client]--;
    }
    else
    {
        return 
Plugin_Stop;
    }
    return 
Plugin_Continue;

Untested.
Anyway if you need help feel free to add me on discord : Pilo#8253
__________________

Taking Private(PAID) Plugins In PM
Feel free to Donate with PayPal
Feel free to message me in Discord Pilo#8253
Total donated : 25$
Pilo is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 06-30-2019 , 17:26   Re: Help creating delay to use command
Reply With Quote #8

If you want to do this to multiple commands, there's this plugin: https://forums.alliedmods.net/showthread.php?p=2100802
__________________
ddhoward is offline
Piksu
Junior Member
Join Date: Oct 2016
Old 07-01-2019 , 06:06   Re: Help creating delay to use command
Reply With Quote #9

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

float g_fSeconds[MAXPLAYERS 1];
ConVar gcv_WaitTime;

public 
Plugin myinfo =
{
    
name "Messager",
    
author "",
    
description "Send message via chat triggers",
    
version "1.0",
    
url ""
};

public 
void OnPluginStart()
{
    
RegConsoleCmd("discord"Command_discord);
    
gcv_WaitTime CreateConVar("sm_discord_command_wait_time""5.0""!discord Wait time (Note : must be float!)");
}

public 
void OnClientConnected(int client)
{
    
g_fSeconds[client] = 0.0;
}

public 
void OnClientDisconnect(int client)
{
    
g_fSeconds[client] = 0.0;
}

public 
Action Command_discord(int clientint args)
{
    if (
IsClientInGame(client) && !IsFakeClient(client))
    {
        if (
g_fSeconds[client] > 0.0)
        {
            
PrintToChat(client"You need to wait %f more time to use this command."g_fSeconds[client]);
        }
        else
        {
            
PrintToChatAll("\x04https://discord.gg/******");
        }
        
g_fSeconds[client] = GetConVarFloat(gcv_WaitTime);
        
CreateTimer(1.0Timer_CooldownclientTIMER_REPEAT);
    }
    return 
Plugin_Handled;
}

public 
Action Timer_Cooldown(Handle timerany data)
{
    
int client data;
    if (
g_fSeconds[client] > 0.0)
    {
        
g_fSeconds[client]--;
    }
    else
    {
        return 
Plugin_Stop;
    }
    return 
Plugin_Continue;

Untested.
Anyway if you need help feel free to add me on discord : Pilo#8253
Works perfectly. Thanks a lot!
Piksu 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 16:53.


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