Skip to content

CombatLib Part 07: Basic Magic

ThePix edited this page Nov 10, 2016 · 6 revisions

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

In this part we will create some spells.

In CombatLib spells can only be cast by the player - if you want an enemy to cast spells, you should do it as an attack instead, as discussed earlier.

Spell Level and Single Use

All spells should have a level attribute. To be able to learn or cast the spell, the player needs an intelligence plus magic bonus equal to or greater than twice the level of the spell. Set the level to zero to allow any player to use it.

For our tutorial game, we will therefore go to the player object, and on the Attributes tab, add a new integer attribute called "intelligence" and set it to 10.

For any spell, you can choose to set it to be single use. When the player casts it, the spell is destroyed and cannot be used again. This allows you to change the magic system into "Vancian Magic" or "fire-and-forget".

Spells the player knows are stored in a location called spells_known. The player can see a list of those spells by typing SPELLS.

Attack Spells

Attack spells are easy. We will create a Fireball spell. Create the object as normal, then on the Combat tab select "Attack Spell" from the list. Assign an element and a level. As with swords and monsters, the element list will include every object in the game. For Fireball we obviously need "Fire". Set the level to 5.

Note that attack spells will affect every creature in the current location except the player; doing damage equal to 1.5 times the spell level, so 6 hit points for this spell. Creatures associated with the opposed element will take four times the normal damage, whilst creatures associated with the element will take zero damage.

You can change the way the damage is calculated by setting the elementaldamage attribute of the game object. This should be set to 100 times the damage multiplier (so the default is 150).

Go into the game, and get the spell, LEARN it, then CAST it in the room with the goblins.

Create a second spell, and this time call it Firepuff. Again give it the element "Fire", but set the level to 2. If you go into the game, you will find it does less damage obviously. You should also find that if you learn the spell and then learn the Fireball spell, the Firepuff will be removed from the list. The system will automatically remove lower level versions of the same spell (for attack spells only).

Banishing Spells

Banishing spell are very powerful, use with caution!

A banishing spell will immediate remove all creatures iof the given type from the game world (including anything they are carrying). Set the type of creature in the Target field. The type can be any one of these: Beast; Human; Goblinoid; Fey; Demon; Undead; Elemental; Created; Corrupted; Plant (capitalisation is important!).

You must also add a description (for most spells this is optional, not here though). Note this should include a %, the % will be replaced by the name of the creature banished. Using the text processor to add variety is a good idea. Create a banishing spell for "Goblinoids", and give it this text. Try it out on your goblins.

The % is {random:banished to a fiendish realm:dismissed to hell:sent to a dark dimension}.

Next...

In the next part, we will look at spells that continue for a while, and create a spell to transform the player into a wolf.

Clone this wiki locally