Skip to content

CombatLib Extra 01: Reference

ThePix edited this page Nov 12, 2016 · 1 revision

Important Attributes

Player

The player's current weapon and shield are stored in attributes called "equipped" and "shield". You can change these as required, but ensure "equipped" is never null. If the player has no weapon, then set "equipped" to the built-in fists object.

The player's health is stored in an integer attribute called "hitpoints". The current spell effect is a string in "status". The "armour10" attribute contains ten times the player's current armour (this is easier than handling floating point numbers).

Here are the useful attributes (integers except where noted)

alias (string)
female (Boolean)
status (string)
equipped (object)
shield (object or null)
currentspell (object or null)
hitpoints
defence
armour10
money
turncount
xp

strength
agility
stamina
intelligence

attackbonus
defencebonus
magicbonus
armourbonus
damagebonus

Monsters

Check the "dead" attribute of a monster to see if it is dead. To kill a monster, call its "makedead" script to ensure all the housekeeping is done:

  do(monster, "makedead")

Current health is stored in "hitpoints", as with the player. Its original value will be in "fullhits", but note this will only exist after the monster has lost some hits.

dead (boolean)
target (object or null)
hitpoints
defence
level
xp

Functions You Should Use

These should not be changed, but should be used in your code to ensure everything works right.

IsUnableToHold

Use this function to check if the player can pick stuff up (is not in the form of an animal or similar).

if (IsUnableToHold) {
  msg("You cannot pick that up right now.")

UpdateArmour

This method recalculates the player's armour and defence. You should call it whenever armour or defence change.

Functions You Can Customise

Change these to do something different in your game.

OkayToLearn (object spell)

This will be called when the player tries to learn a spell, and must return a Boolean. If it returns true, the spell can be learnt, if false it cannot. You should give a message saying why not in the latter case.

This could be used to limit the player to a certain number of spells. For instance:

if (player.intelligence <= ListCount(GetDirectChildren(spells_known))) {
  msg("You do not have the intelligence to learn another spell.")
  return (false)
}
else {
  return (true)
}

OkayToCast (object spell)

This will be called when the player tries to cast a spell, and must return a Boolean. If it retursn true, the spell can be cast, if false it cannot. You should give a message saying why not in the latter case.

You could use this to check if the player has enough power points or mana to cast a spell. Note that this is the last check, so it would be safe to also reduce the player's mana in the same function.

if (player.mana < spell.level) {
  msg("You do not have enough mana for that spell.")
  return (false)
}
else {
  player.mana = player.mana - spell.level
  return (true)
}

'DisplayMoney (int money)'

This is in ShoppingLib, but is listed for completeness. Override this to change the currency in your game. It should return a string.

  return ("" + value + " gold pieces")

CalcFullHits

By default, the maximum hits are determined as 40 plus 10 times the stamina, but you can override this function to modify that. It must return an integer.

Functions for the User Interface

These functions are blank by default, but can be used to keep a fancy user interface updated.

UpdateSpells

This function gets called whenever the player's list of learnt spells changes. You can override it to update your own list. Learnt spells are kept in an object called spells_known, so you could update a second inventory like this:

  SetInv2 (GetDirectChildren (spells_known))        

UpdateStatus

This is called when the player's stats change. You can override it to have those stats display on the screen.

If you do use it, you need to also remember to call it whenever the player's status changes in your code as well.

MakeMeDead (object monster)

This is called when the monster dies, and you could use it to update the user interface to highlight that.

Commands

These help commands should be overridden to make them specific to your game:

credits

hints

version

Templates

You can override dynamic templates to customise responses. Only a limited number are implemented:

<dynamictemplate name="VenomOkay">"You spread venom over your weapon."</dynamictemplate>

<dynamictemplate name="ShieldSwap">"You put away your " + GetDisplayAlias(game.pov.shield) + " and hold your " + GetDisplayAlias (object) + " ready."</dynamictemplate>
<dynamictemplate name="ShieldUnequip">"You put away your " + GetDisplayAlias(game.pov.equipped) + "."</dynamictemplate>
<dynamictemplate name="ShieldEquip">"You hold your " + GetDisplayAlias (object) + " ready."</dynamictemplate>

<dynamictemplate name="WeaponSwap">"You put away your " + GetDisplayAlias(game.pov.shield) + " and draw your " + GetDisplayAlias (object) + " ready."</dynamictemplate>
<dynamictemplate name="WeaponUnequip">"You put away your " + GetDisplayAlias(game.pov.equipped) + "."</dynamictemplate>
<dynamictemplate name="WeaponEquip">"You draw your " + GetDisplayAlias (object) + " ready."</dynamictemplate>

<dynamictemplate name="WearableLoot">"You consider putting on the " + GetDisplayAlias (object) + ", but decide not to; better to sell it when you can. It is not like it is magical or anything."</dynamictemplate>

<dynamictemplate name="SpellLearn"><![CDATA["In a process that seems at once unfathomable, and yet familiar, the spell fades away, and you realise you are now able to cast the <i>" + GetDisplayAlias(object) + "</i> spell."]]></dynamictemplate>

If you want to convert this to another language, you will need to go through each library file and translate every string. You fully have me permission to do that, but be aware thatit will be no small job!

Clone this wiki locally