| Overview | Screenshots | Downloads | News | Documentation | Thanks | Simugraph Home Page |
Descriptions are up to date with H-World version 0.3.5
H-World uses Lua as scripting language. The scripts reside in the 'scripts' directory. At program start H-World reads 'init.lua' from the scripts directory. You can either put all your functions in that one file or just use the 'init.lua' file to read other lua scripts. The default game 'The Jungle' coming with H-World uses the latter approach.
More details about Lua can be found at www.lua.org.
There are several ways to invoke Lua scripts in H-World:
Some scripts are triggered automatically:
Items can be configured to have usages. A block like this is used to tell H-World which usages an item provides:
usages = 1 usage[0].name = lua_call usage[0].verb = quaff
The example is from a healing potion.
The usage name 'lua_call' tells H-World that this usage calls a lua function names 'quaff'. An item can have an number of usages. See item configuration for more details how to configure items in H-World.
The 'quaff' lua function looks like this:
example_quaff.html
The signature of a usage function is always function functionname (user, inventory, item). The user and item parameters are both of type thing that is the common base type for everything inside H-World.
Item properties can be read by the following function:
value = thing_get_value(thing, "property_name")
Item properties can be set by the following function:
thing_set_value(thing, "property_name", value)
Please read item configuration for more details how to configure item properties in H-World.
Items can have properties for calling lua functions if the item is weld or unweld by the player:
lua_wield = functionname lua_unwield = functionname
Items which have this properties defined just call the configured lua functions if they are weld or unweld. The functions signature is the same as for usage functions:
function functionname (user, item)
In ./scripts/usages.lua there are two procedures base_wield(user, item) and base_unwield(user, item). They are called by the H-World CRPG engine every time that an item is weld or taken off. Global functionality that applies to all or a large number of items should go there.
See the section about configuring usages to learn more how to define and write the lua functions.
See item configuration for more details how to configure items in H-World.
If an item in the inventory view is dropped onto another item of different type, then H-World calls drop_item(user, item, drop) which is defined in ./scripts/recipes.lua. This procedure then evalutes if those items are combinabale somohow, or if some effect is triggered by connecting those items.
There are a few examples for mixing potions implemented in the example game "The Jungle". Further ideas thet can be implemneted via recipes could be magical items that can be combined to more powerful magical items, socketed items and gems as knwon from Diablo II, or for technical setting, adding fuel or batteries to gadgets and devices. I guess the inventive game creator will find a lot more usages for recipes.
The H-World engine calls some Lua function upon certain events, e.g. creation of an item/monster or killing/destroying one. This allows to add custom code to these events. The callback functions are usually part of [module]/scripts/core.lua
| Callback function | Description |
|---|---|
|
Call
calculate_ident_string(thing, memorized) Arguments thing: type thing_t, the thing to check memorized: nil if not memorized, non-nil if memorized Return value ident string |
Description:
Available:
|
|
Call
calculate_plain_ident_string(thing, memorized) Arguments thing: type thing_t, the thing to check memorized: nil if not memorized, non-nil if memorized Return value ident string |
Description:
Available:
|
|
Call
check_item_constraints(limb, thing) Arguments limb: type thing_t, the limb to hold the item thing: type thing_t, the thing to check return: 1 if ok, 0 otherwise |
Description:
Available:
|
|
Call
on_creation(thing, n) Arguments thing:type thing_t, the thing that just was created n:type number, always 0 so far Return value always 0 so far |
Description:
Available:
|
|
Call
on_kill(thing, n) Arguments thing: type thing_t, the thing to be destroyed n: type number, 0 if thing dies silently Return value always 0 so far |
Description:
Available:
|
Beings in H-World can be configured to call Lua scripts as part of their AI (see [module]/data/beings.sects). Each AI action is a pair of Lua functions, one to check if it is good to execute the actions now, and one that actually executed the action. The AI driver will first evaluate all checks and then execute the actions that has the highest check result. Actions that have a check result of -1 are not executed at all, even if there are no other actions available.
Find below the AI function pairt from H-World 0.3.9 that handles monster sleep and wakeup procedures:
The H-World engine provides a number of procedure calls to Lua scripts. Find each call described briefly below.
| Procedure | Description |
|---|---|
|
Call
Arguments
Return value
|
Description:
Available:
|
|
Call
Arguments
Return value
|
Description:
Available:
|
|
Call
Arguments
Return value
|
Description:
Available:
|
|
Call
Arguments
Return value
|
Description:
Available:
|
|
Call
Arguments
Return value
|
Description:
Available:
|
|
Call
Arguments
Return value
|
Description:
Available:
|
|
Call
Arguments
Return value
|
Description:
Available:
|
|
Call
Arguments
Return value
|
Description:
Available:
|
|
Call
Arguments
Return value
|
Description:
Available:
|
|
Call
Arguments
Return value
|
Description:
Available:
|
|
Call
Arguments
Return values:
|
Description:
Available:
|
|
Call
Arguments
Return values:
|
Description:
Available:
|
|
Call
Arguments
Return values:
|
Description:
Available:
|
|
Call
Arguments
Return values:
|
Description:
Available:
|
|
Call
Arguments
Return values:
|
Description:
Available:
|
|
Call
Arguments
Return values:
|
Description:
Available:
|
|
Call
Arguments
Return values:
|
Description:
Available:
|
|
Call
Arguments
Return values:
|
Description:
Available:
|
|
Call
Arguments
Return values:
|
Description:
Available:
|
|
Call
Arguments
Return values:
|
Description:
Available:
|
|
Call
Arguments
Return values:
|
Description:
Available:
|
| Procedure | Description |
|---|---|
|
Call
Arguments
a random integer value in range 0..n-1 |
Description:
Available:
|
|
Call
Arguments
Return value
|
Description:
Available:
|
|
Call
Arguments
Return value
|
Description:
Available:
|
| Procedure | Description |
|---|---|
|
Call
Arguments
Return value
|
Description:
Available:
|
|
Call
Arguments
Return value
|
Description:
Available:
|
|
Call
Arguments
Return value
|
Description:
Available:
|
|
Call
Arguments
Return value
|
Description:
Available:
|
| Procedure | Description |
|---|---|
|
Call
Arguments
Return value
|
Description:
Available:
|
|
Call
Arguments
Return value
|
Description:
Available:
|
|
Call
Arguments
Return value
|
Description:
Available:
|
|
Call
Arguments
Return value
|
Description:
Available:
|
|
Call
Arguments
Return value
|
Description:
Available:
|
| Procedure | Description |
|---|---|
|
Call
Arguments
Return values
|
Description:
Available:
|
|
Call
Arguments
Return values
|
Description:
Available:
|