How to limit a command to usage every x minutes

Questions, on how to perform AMXX scripting, are inside of this forum.
User avatar
Archive-Poster
Posts: 1189
Gender:
United States of America

How to limit a command to usage every x minutes

Post by Archive-Poster »

Could somebody share an example of limiting a client chat command to only once every minute?
Trying to figure this out with and without a timer... w.e is easier.

Something like if somebody uses = /health it would be blocked from usage by everyone in the server for a a minute with a message like, you must wait x amount b4 you can use this command again
User avatar
Archive-Poster
Posts: 1189
Gender:
United States of America

Re: How to limit a command to usage every x minutes

Post by Archive-Poster »

Sorry for the wrong section.

So well.. I managed to put a working version of it up I just copy and paste things around here lol.. but it's only limiting it for the player who typed the command.. was thinking the first person to type it.. is the one that executes it and then it would be blocked for 2 minutes for everyone else. It's looking like this:


How to make it just block the command from being used during that cooldown period, with a message saying "You must wait X, amount before you can advertise again"

Code: Select all

#include <amxmodx>
#include <amxmisc>

#define TIMER_TASK 32490283099

#define COOLDOWN 2 //minutes
new last_used[33]



public plugin_init()
{
	
	register_plugin("test", "1.0", "test")

	register_clcmd("say /advertise", "check", 0, "- show message");
	
}

public client_disconnected(id) {
    last_used[id] = 0;
}
public client_connect(id) {
    last_used[id] = 0;
}

public check(id) {
    if( (get_systime() - last_used[id]) < COOLDOWN*60) {
        client_print(id,print_chat,"[AMXX] You must wait %d minute%s to use this command again.",COOLDOWN, COOLDOWN == 1 ? "" : "s")
        return PLUGIN_HANDLED
    }
    last_used[id] = get_systime()
    set_task(1.0, "advertise")
    return PLUGIN_HANDLED
}

public advertise(id) {
   // Some function here that would be executed ONCE! then limited.
   // maybe... client.print an advertisement.. etc.
}
User avatar
Archive-Poster
Posts: 1189
Gender:
United States of America

Re: How to limit a command to usage every x minutes

Post by Archive-Poster »

Remove [33] and [id].
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests