Ok, there was a time when i searched for a Tutorial that tells how to make a working cooldown, didint find it (even using search) so i guess there is no such tutorial here...Sooo, ive started to think myself and made a working cooldown and would like to share it with anyone who too want to add a cooldown to the plugins they are making, so here we go, just follow the yellow brick road..or just the steps...nevermind.
1. So, let's start off with the #include's :
Code:
#include <amxmodx>
#include <amxmisc>
Don't think i gotta explain this, becouse im assuming that anyone who is reading this tut, has basic knowledge of amxx scripting.
2. the plugin_init! Yay!....haha! fooled you, first lets set a bool :
Code:
new bool:cooldown = false
this bool in my opinion makes like 50% of the whole cooldown function, without it, the cooldown wont work (well for my code it wont, maybe the pros will have other ideas)
3. lets make plugin_init finnaly:
Code:
public plugin_init() {
register_plugin("Cooldown test", "1.0", "Thats you my man!")
register_clcmd("test", "test_cooldown")
register_cvar("cool", "5")
}
Ok, so, register_plugin, you know the drill what to do in this line.
Register_clcmd - this will make a cmd "test" that a client can use to call anything you want to have a cooldown
Register_cvar - will make a cvar cool, with a default number 5, this will make the server able to change the cooldown time.
4. Now make the test_cooldown public:
Code:
public test_cooldown(id){
if(cooldown == false) {
set_task(0.1,"test_cooldown1",id)
}
if(cooldown == true) {
return PLUGIN_HANDLED
}
return PLUGIN_HANDLED
}
now it checks the bool, if the bool cooldown is false, then it sets a task, thats going to trigger in 0.1 seconds, and if the bool cooldown is true (that, means that the cooldown is commencing, so it will just do nothing.
5. Now the function, that will be called if the cooldown is off:
Code:
public test_cooldown1(id){
cooldown = true
new cooling = get_cvar_num("cool")
//Here you do anything you like
set_task(cooling * 1.0, "test_cooldown2", id)
}
so when the user uses the "test" cmd it calls the public test_cooldown, and it checks if there is no cooldown working, and if it isint, then it triggers public test_cooldown1, and here you write everything you want, anything, and anyhow (just make it work) you can even make the player glow random colors, make him go bezerk, make him stand in place, anything you like, ok so - explanation: the first line cooldown = true, makes the bool with a true value, so now if a player uses the test cmd again he wont get any effect, becouse the cooldown is commencing , now you should make a new item, that checks a cvar value, this time its "cool" this will regulate how long the cooldown will be, remmeber default is 5 seconds, i dont know, but i just had to put "* 1.0" in the set_task, otherhow it just doesnt want to work, now, the set_task, will trigger test_cooldown2 when the time is over (default 5, but using the cvar you can set it to any value you like)
6. let's look into the last public test_cooldown2:
Code:
public test_cooldown2(id){
cooldown = false
}
Ok its pretty simple, this is trigger after the cooldown is over, and it makes the bool be false, so the user using the test cmd will once againt rigger the cooldown and everything will start all over, and when the cooldown is over again, this public will reset the cooldown.
7. And lastly, the full code:
Code:
#include <amxmodx>
#include <amxmisc>
new bool:cooldown = false
public plugin_init() {
register_plugin("Cooldown test", "1.0", "Thats you my man!")
register_clcmd("test", "test_cooldown")
register_cvar("cool", "5")
}
public test_cooldown(id){
if(cooldown == false) {
set_task(0.1,"test_cooldown1",id)
}
if(cooldown == true) {
return PLUGIN_HANDLED
}
return PLUGIN_HANDLED
}
public test_cooldown1(id){
cooldown = true
new cooling = get_cvar_num("cool")
//Here you do anything you like
set_task(cooling * 1.0, "test_cooldown2", id)
}
public test_cooldown2(id){
cooldown = false
}
Well thats it, i know, its not the best coding, im still learning myself, but i hope this tutorial will help some, or even many people.