Monday, April 1, 2013

Using cooldown_check tutorial for Hellcore

Hellcore provides an easy way to implement cooldowns for whatever use you desire, using the verb 'cooldown_check'.  The verb is located on $creature and can be used by $player as well.

The verb itself:

:cooldown_check(ANY action, INT seconds-of-cooldown[, INT silent, INT dont-start, INT force-new)

The arguments:

action - this can be any type, either an object representing an action, or a string, or whatever.
seconds-of-cooldown - self explanatory, this is the actual cooldown itself.  Best stored on a property relevant to your use.
silent - if true, no cooldown message will be printed to the player.
dont-start - if true, no cooldown countdown will be started.
force-new - if true, a new cooldown coutndown will be forcibly started regardless of cooldown remaining.

Usage example:

For the example consider an action, let's call it "pray" since that's what I worked on last.  Your _finish verb might look something like this:

pray:_finish
who = args[1];
target = args[2][1];
if ( ! who:cooldown_check( this, this.cooldown_period) )
  return E_NONE;
endif

This would do a check on the cooldown for the pray $action object.  If the cooldown hasn't elapsed, a message is printed to 'who' by cooldown_check, and we abort our action by returning E_NONE.  It is ideal to preform the cooldown check in _finish, since if the check passes in _start but the player aborts the action they will be on cooldown without actually having preformed the action.