Handling cool down

The Pixie
Most computer RPG games stop the player casting spells (or biotics or whatever) too frequently by giving them a cool down period. If you just cast Fireball, you have to wait 5 seconds before you can cast it again, for example.

Here is an example function to handle that in Quest.

  <function name="CastElementalSpell" parameters="name, hits, cooldown"><![CDATA[
if (not HasInt(player, "last_" + name)) {
set (player, "last_" + name, -cooldown)
}
if ((GetInt(player, "last_" + name) + cooldown) < player.turncount) {
// Hand spell effect here!!!
msg ("You cast a " + name + ", doing " + hits + " hits to all the monsters around you.")
set (player, "last_" + name, player.turncount)
}
else {
msg ("You cannot cast a " + name + " yet (" + (GetInt(player, "last_" + name) + cooldown + 1 - player.turncount) + " seconds).")
}
]]></function>


It requires an integer attribute on the player called "turncount", and a timer that increments that by 1 each second. For fireball, you might use it like this:

  CastElementalSpell("Fireball", 20, 5)


Here is a full working example (spells do not do anything, but you should get the idea):

Avantar
Very useful!

Thank you for this.

This topic is now closed. Topics are closed after 14 days of inactivity.

Support

Forums