T4 Modules Howto Guide/NPCs

From Tales of Maj'Eyal
Revision as of 17:44, 19 October 2013 by Grazz (Talk | contribs) (warning on setting rarity to 0)

Jump to: navigation, search

Actors: NPCs and Monsters

Important NPC Definitions

Note that these are also used in the copy table in a player descriptor. These expand on the properties available to all entities, see Entities.

Variable Effect
name Displayed NPC name.
short_name NPC identifier. name is used if unset
desc Optional description of NPC.
type NPC Type (No known hardcoded types)
subtype Better categorization for NPC.
display Character that the NPC is displayed as in text mode.
faction Actor faction. Defaults to "enemies".
ai Selects which ai to use for NPC.
ai_state (?) Depends on AI class.
rarity How common this NPC is to generate. Higher is rarer. If not set will not ever generate. Do not set to 0, this is bad.
level_range Minimum and maximum levels for NPC. Read NPC Level Scaling below.
autolevel Which leveling function to use to level up NPC. Read NPC Level Scaling below.
max_life Max life at level 1.
energy.mod Scales how much energy is gained per tick. Defaults to 1.
sight Sight radius.
exp_mod Scales how much exp is needed to reach a new level. Defaults to 1.
exp_worth Indicator of Actor exp value. By default, exp for killing an Actor is its level times this value.
egos See ego section in Entities
egos_chance See ego section in Entities

These variables are not set in the definitions file, though they can be. They can be useful to access in code however.

Important runtime variables Effect
energy.value Current energy of this actor. Defaults to 0.
self.energy.used Set to true if some energy was used this tick.
life Current life. Defaults to max_life.
dead true if entity is dead. Different from undead.
level Current Actor level.
exp Current experience.
max_level Maximum level for the Actor.

The example module implements several other variables in its Actor class and Combat interface. These are not hardcoded, but can be used as a base or example for implementing your own module.

Variable Effect
combat_armor Removes this amount from damage taken.
combat.dam This is added to strength to determine the damage done by attacks.

Actor class important methods

For more information, read the documentation.

Method Purpose
act() Code that gets executed every time the entity gets to act.
canSee(actor) Test if the actor can see the target actor. This does not check LOS or such, only the actual ability to see it, such as influenced by stealth, invisibility or telepathy. Returns true or false and a number from 0 to 100 representing the 'chance' to be seen.
getTarget() Gets the Actor target. Redefined by player and AI.
setTarget(target) Sets the actor target. Redefined by player and AI.
move(x, y, force) Do NOT manually set the actor's x and y values. Use this method instead. Set force to true to not test for the presence of other entities. Returns true if a move was attempted and energy should propably be used.
moveDir(dir) Moves in a certain direction. Calls move() internally.
canMove(x, y, terrain_only) Checks if the Actor can go there. if terrain_only is true it only checks terrain and ignores the presence of actors and other entities.
teleportRandom(x, y, dist, min_dist) Teleports randomly to x,y. dist is the radius of the effect, min_dist is a minimum radius of the effect and defaults to 0. Set dist to 0 for precise teleport.
useEnergy(amount) Amount of energy to subtract from the actor in energy based time systems. Often used in the act() method after taking an action that takes time.
reactionToward(target) Uses factions to check for hostility. -100 is fully hostile, 0 is neutral and 100 is friendly.
addTemporaryValue(prop, v, noupdate) Changes a property on the actor, but returns an id so the value change can be reversed with a call to removeTemporaryValue(). If noupdate is true the property is not actually changed.
removeTemporaryValue(prop, id, noupdate) Reverses a previous call to addTemporaryValue(). Use its returned id to reverse its change.
onTemporaryValueChange(prop, sub, v) Does nothing. Redefine to perform some action when temporary values are applied or removed.
attr(prop, v, fix) Non-temporarily increases or decreases an actor property. Use this for compatibility with temporary values above. If fix is set the property is set to v, not increased or decreased. Commonly, attr(prop) alone is used to check for the existance of a property instead of modifying it.
isNear(x, y, radius) Checks whether the actor is within a certain radius of the passed coordinate.

In addition, defining stats automatically creates a getStat() function. For example, defining the stat str creates a getStr() function for you.

NPC Egos

NPC Level Scaling

Depending on the zone settings, the spawned creatures can actually level with the player. This requires a level_range variable to be properly set and a levelup() method in the Actor class.

The level_range variable defines the possible range the creature can be. The entity will always be leveled up to at least its minimum level in the level range. It will also never be leveled above that range either.

The leveling method should be defined in Actor.lua. In ToME this method adds to the life, stamina and mana of actors. Alternatively, you can create several, and use the autolevel variable to pick which to call.

All creatures are always generated at level 1, then leveled up to reach their required level. Keep this is mind when creating the NPC descriptor. Note also that you can create your own levelup() function in the NPC descriptor if a unique levelup method is needed.

See Dev-Zones for more info

Go back to T4 Modules Howto Guide