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

Cooldowns


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Doman
Junior Member
Join Date: Mar 2007
Old 03-07-2007 , 12:52   Cooldowns
Reply With Quote #1

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.
Doman is offline
teame06
i have a hat
Join Date: Feb 2005
Location: Hat City
Old 03-07-2007 , 14:24   Re: Cooldowns
Reply With Quote #2

http://forums.alliedmods.net/showthread.php?t=43049
__________________
No private support via Instant Message
GunGame:SM Released
teame06 is offline
Send a message via AIM to teame06
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-07-2007 , 19:29   Re: Cooldowns
Reply With Quote #3

It's not even well coded... I shouldn't really say anything though, most of my tutorials are written on the spot. I don't even try compiling them, I think the only one I did was the SQLx one since there was so much code.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Doman
Junior Member
Join Date: Mar 2007
Old 03-08-2007 , 03:57   Re: Cooldowns
Reply With Quote #4

I did note that the pros can make a better code, but this works and i tested it...it's just a nother kinda n00by way of doing cooldowns...
Doman is offline
pope
Junior Member
Join Date: Nov 2005
Location: New York
Old 03-08-2007 , 04:58   Re: Cooldowns
Reply With Quote #5

I would think something like this would work better, maybe someone cares to comment though?

Code:
#include <amxmodx> #include <amxmisc> new gExampleCoolDown new gPlayerCoolDown[33] new gSysTime public plugin_init() {         register_plugin("Cooldown", "1.0", "Pope Hannibal")     register_clcmd("test", "test_example")     gExampleCoolDown = register_cvar("pl_ExampleCoolDown", "5")     } public test_example(id) {         gSysTime = get_systime()         if ( gPlayerCoolDown[id] == 0 || ( gSysTime - gPlayerCoolDown[id] ) > get_pcvar_num(gExampleCoolDown) ) {         Call_Power(id)         gPlayerCoolDown[id] = gSysTime     }         else {         client_print(id, print_chat, "Power Hasn't Cooled Down Yet")     }         return PLUGIN_HANDLED } public Call_Power(id) {         //Whatever... }
__________________

Last edited by pope; 03-08-2007 at 05:01.
pope is offline
Send a message via AIM to pope Send a message via MSN to pope Send a message via Yahoo to pope
VEN
Veteran Member
Join Date: Jan 2005
Old 03-08-2007 , 05:46   Re: Cooldowns
Reply With Quote #6

You shouldn't use system time in this case, use get_gametime() (gpGlobals->time) instead.
VEN is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 03-08-2007 , 06:45   Re: Cooldowns
Reply With Quote #7

Quote:
Originally Posted by pope View Post
I would think something like this would work better, maybe someone cares to comment though?
Quote:
Originally Posted by teame06 View Post
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 03-08-2007 , 08:35   Re: Cooldowns
Reply With Quote #8

As this 'tutorial' is unnecessary and could lead to bad programming practices, it doesn't belong here. Moving to the Scripting board.
__________________
Brad 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 18:15.


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