Skip to content

CombatLib Part 09: Instant Spells

ThePix edited this page Nov 12, 2016 · 3 revisions

This continues from this page, and assumes you have installed the libraries in your game, have some basic equipment, three goblins and some simple spells in your game.

In this part we will create some custom instant spells.

Instant Spells

Instant spells happen instantly, obviously, like the attack spell and banishing spell we created earlier, but entirely customisable. This option allows you to configure any such spell.

Cancel Spell

On-going spells last until another spell is cast, but you can terminate a spell earlier with the Cancel spell. This is the easiest instant spell, as it has no script! Just create an object, and set it to be an "Instant spell", and you are done.

Unlock

The player can use this to unlock any exit in the room (so use carefully!). Create the object, set it to be an "Instant spell". For the Spell effect, click on "Make editable copy", then paste in is the script:

flag = False
foreach (ex, ScopeExits ()) {
  if (GetBoolean (ex, "locked") and (Instr(ex.name, "guard") = 0)) {
    ex.locked = False
    flag = True
    msg ("...The door " + ex.alias + " magically unlocks!")
  }
}
if (not flag) {
  msg ("...There were no doors locked")
}

Actually, it does not unlock all doors. Those that are guarded will still be locked, as the player needs to kill the guards to get through. It will also not affect exits that are not currently visible.

Mark, Teleport and Returning

NOTE: Moving the player to rooms not linked by an exit when the map is displayed will cause an error. These spells should only be used if yiu do not use the map feature.

This is a set of spells to magically move the player. The are all created as before, but with different scripts pasted in.

The Mark spell just saves the current room as the destination for a future teleport.

player.teleportdestination = player.parent

The Teleport spell moves the player instantly to he marked location:

if (not HasObject(player, "teleportdestination")) {
  msg ("You need to cast <i>Mark</i> to set a destination for <i>Teleport</i>.")
}
else if (player.parent = player.teleportdestination) {
  Print ("You feel as though you are being turned inside out, suddenly you are... in the same place.")
}
else {
  Print ("You feel as though you are being turned inside out, suddenly you are elsewhere...")
  player.parent = player.teleportdestination)
}

While Returning takes the player to a specific location.

player.parent = temple_courtyard

Attack Spells

If you want to create your own attack spells, you can. Let is create a Manastorm spell. Create the object, set it to be an "Instant spell", then paste in this code (after making a editable copy!):

flag = False
msg ("A maelstrom of magical power sweeps the room.")
foreach (obj, ScopeVisibleNotHeld ()) {
  if (DoesInherit (obj, "monster") and not GetBoolean (obj, "dead")) {
    damage = GetRandomInt(1,25)
    s = "... The " + GetDisplayAlias(obj) + " takes " + damage + " points of damage. "
    if (not obj.hitpoints - damage > 0) {
      if (HasString(obj, "death")) {
        s = s + obj.death
      }
      else {
        s = s + "It falls to the ground dead"
      }
      do (obj, "makedead")
    }
    flag = True
    obj.hitpoints = obj.hitpoints - damage
    msg (s)
  }
}
if (not flag) {
  msg ("... No monsters present")
}

Others...

You can have instant spells do anything you like, but you may need to think about whether it will break the game. A healing spell, for example, should be single use, otherwise the player can just keep casting it to stay in full health.

Next...

In the next part we will look at magic items.

Clone this wiki locally