ID:156833
 
Alright so I have skills in my current project that have cooldowns so they cannot be continuously used repeatedly. The thing is that the cooldown system works fine. It's just that if you activate the skill but you don't have enough energy, you're doing something, etc., the cooldown will still activate even though the skill didn't activate due to whatever reason. So for example. A player uses a skill but doesn't have the energy cost to use the skill, the player won't be able to use the skill 'til the cooldown is over even though skill didn't go through. Here is the code for the activation of the skill:

    proc/Activate(mob/User)
if(User.Cooldown(src.name,src.Cooldown*10,src))
return 1
else
if(usr.client)
if(src.Cooldown>=10)
src.overlays+=new/obj/Locked
for(var/HK/H in usr.client.screen)
if(H.skill==src)
H.overlays+=new/obj/Locked
if(src.name=="Skill1")
User.Skill1(usr)
return
if(src.name=="Skill2")
User.Skill2(usr)
return


This code works perfectly fine for putting a limit to massing the Activate button but is there a way to make it so that if the skill doesn't fully activate because of not having a required stat or something, there won't be a cooldown? The last thing I'd want to resort to is setting a cooldown code into every skill.
AbdelJN wrote:
Alright so I have skills in my current project that have cooldowns so they cannot be continuously used repeatedly. The thing is that the cooldown system works fine. It's just that if you activate the skill but you don't have enough energy, you're doing something, etc., the cooldown will still activate even though the skill didn't activate due to whatever reason. So for example. A player uses a skill but doesn't have the energy cost to use the skill, the player won't be able to use the skill 'til the cooldown is over even though skill didn't go through. Here is the code for the activation of the skill:

>   proc/Activate(mob/User)
> if(User.Cooldown(src.name,src.Cooldown*10,src))
> return 1
> else
> if(usr.client)
> if(src.Cooldown>=10)
> src.overlays+=new/obj/Locked
> for(var/HK/H in usr.client.screen)
> if(H.skill==src)
> H.overlays+=new/obj/Locked
> if(src.name=="Skill1")
> User.Skill1(usr)
> return
> if(src.name=="Skill2")
> User.Skill2(usr)
> return

This code works perfectly fine for putting a limit to massing the Activate button but is there a way to make it so that if the skill doesn't fully activate because of not having a required stat or something, there won't be a cooldown? The last thing I'd want to resort to is setting a cooldown code into every skill.


Why are you breaking down every skill in a single proc? You continue this route you'll have 500+ lines of code in a single proc with nothing but a bunch of if/else for simple things. You should define a skill under an obj type and create a proc under the base "/obj/skil/proc/Skill_Use()" something like that and redefine it for each different skill type. Makes things A LOT easier down the road. IE:

obj
skills
var
cool_down=20 //this gives each skill its own cool down timer so you can vary between each skill if you want
proc
Activate(mob/User) //Define the Activate proc here first and give it an argument for the basic cooldown stuff that obviously all skills will use
if(ismob(User)) //This makes sure the user is a mob and isn't null all in one
if(User.Cooldown(src.name,src.cool_down*10,src)) //Don't know what this does, assuming
//it does the task of finding each skill and shutting it down, post it and I maybe be able to simplify it for you
return 1
else
if(User.client)
if(src.cool_down>=10)
var/obj/Locked/L=new
src.overlays+=L.icon
del(L)
// for(var/HK/H in User.client.screen)//this seems redundant at this point, so I voided it
// if(H.skill==src)
// H.overlays+=new/obj/Locked
return 0
skill_one //Our skill #1 defined, yay!
cool_down=50 //over ride the variable
Activate(mob/User) //We need our argument again after over riding the mother proc
if(ismob(User))
if(..(User)) //Have to check the previous defined Activate() to make sure all our preliminary checks are good - no need to repeat in every proc, right?
User<<"You just used [src.name]!"
skill_two //Our skill #2 defined, yay!
cool_down=90 //over ride the variable
Activate(mob/User)
if(ismob(User))
if(..(User))
User<<"You just used [src.name]!"
In response to Teh Governator
I see where you're going, I just finished simplifying the code thanks to you [:. Now theres still a problem, the skill still activates but at the same time tells me I can't use the skill because of the cooldown. Here's the skill code:

CertainskillCard
icon='blablabla.dmi'
icon_state="blablabla"
requiredskills=null
pixel_x=7
name="Certainskill"
Cooldown=10
Click()
Activate(usr)
Activate(mob/User) //We need our argument again after over riding the mother proc
if(ismob(User))
if(..(User))
User.actualskillverb(User)


and the cooldown proc is from a cooldown library, the code is:
mob/var
_Cooldowns[]

mob/proc/Cooldown(Name,Cooldown,obj/T, message=1)
if(!_Cooldowns)
_Cooldowns=new
spawn(T.Cooldown*10)
T.overlays-=T.overlays
if(client)
for(var/HK/H in client.screen)
if(H.skill==T)
H.overlays-=/obj/Locked
H.overlays-=/obj/Locked
H.overlays-=/obj/Locked
H.overlays-=/obj/Locked
if(_Cooldowns[Name]&&_Cooldowns[Name]>world.timeofday)
if(_Cooldowns[Name]>world.timeofday+(Cooldown*3))
_Cooldowns[Name]=world.timeofday+Cooldown
//src<<"TEST"
if(message)
usr<<"You cannot use this ability yet. ([(_Cooldowns[Name]-world.timeofday)/10] Seconds Left)"
return 1



_Cooldowns[Name]=world.timeofday+Cooldown
//if(T)
//T.overlays-=/obj/Locked
return 0

In response to AbdelJN
After getting all pieces of the puzzle, I see your problem now. You left out an argument in the Cooldown() proc when you were calling it. By default it's "1" you're not providing one so, it displays the message anyhow.
You have:
User.Cooldown(src.name,src.cool_down*10,src)


You need:
User.Cooldown(src.name,src.cool_down*10,src,0)//You need either a 0 or 1 according to the arguments in this proc. A 1 which is default will display the message.
In response to Teh Governator
Thank you [: I got the problem fixed but now I'm still at the point where if you use the skill and you don't have a required stat, the cooldown still activates. At this rate I think I'd have to set requirements under the Activate proc which I don't want to resort to because requirements are already in the actual skill verbs. Also I don't want to remove the requirements from the actual skill verbs either because they're still going to be used.

Skillcard
Activate(mob/User)
if(ismob(User))
if(..(User))
User.skillverb(User)


Right now I have the skillcard that when activated, it activates the skill verb. The problem is that in the skill verb if I don't have a required stat it doesn't let you do the skill but the cooldown still activates meaning you basically have to wait for the cooldown for nothing. I want to know if theres an easy way of getting this fixed.
In response to AbdelJN
Lemme see your verb, please.
In response to Teh Governator
Teh Governator wrote:
Lemme see your verb, please.

        Skillverb(mob/M)
if(M.Energy>=M.MaxEnergy/2&&!M.Doing)
M.Energy-=M.MaxEnergy/2
view()<<"[M]: You have used skill!"
M.Frozen=1
M.Doing=1
return 0
else
M<<"You haven't enough energy to perform this skill."
M.icon_state=""
M.Frozen=0
return 1
In response to AbdelJN
Bump.
You get a cooldown if the skill doesn't go through because you are calling the cooldown procedure - which starts a cooldown - before you know the skill will go through. To fix this, don't call it until you know that the skill will go through.

Also don't use usr in procs.