======NPC Behavior====== ---- **NPC Behavior** determines how an [[NPC]] moves around the [[map]] and reacts to their surroundings. It can be configured in the [[Map Editor]] from the "Behavior Settings" section of their [[Entity Properties]] panel. {{:wiki:npc_behavior_dialog.png?nolink|}} Refer to the table below for a description of each setting. ^Icon^Setting^Description^ |{{:wiki:properties.png?nolink|}}|Preset|Unique name for the set of behavior rules. To store the current settings to a named preset, click the "Save" button to the right of the dropdown box. The "No Behavior" option indicates that this [[NPC]] will be immobile and cannot be interacted with in any way.| |{{:interact.png?nolink|}}|When Player Interacts|Determines what will happen when the [[player character]] interacts with this [[NPC]]. If the "Start Dialogue" or "Start Battle" option is selected, an additional dropdown will allow you to choose which [[dialogue]] or [[battle]] to start.| |{{:wiki:navigation_adjacent.png?nolink|}}|When Next to Player|Determines what will happen when this [[NPC]] is on a [[tile]] adjacent to the [[player character]]. If the "Start Dialogue" or "Start Battle" option is selected, an additional dropdown will allow you to choose which [[dialogue]] or [[battle]] to start.| |{{:wiki:skull.png?nolink|}}|On Death|Determines what will happen when this [[NPC]] is defeated. If the "Run Script" option is selected, an additional dropdown will allow you to choose which [[script]] to run.| |{{:wiki:script_start.png?nolink|}}|Can Trigger Scripts|When enabled, this [[NPC]] is able to trigger [[script|scripts]] on [[tile|tiles]], for example when stepping onto a trap or a hazardous [[tile]]. The "Triggerable by NPCs" option (see [[Entity Properties]]) must also be enabled for a [[tile|tile's]] [[script]] in order for the [[NPC]] to trigger it.| |{{:wiki:sword.png?nolink|}}|Attackable in Real-Time|When enabled, this [[NPC]] can be attacked in the game world in real-time. Their loot drop and experience points that will be given to the attacking [[character]] when defeated can be set if this option is toggled on. Their stats, like health and attack strength, are configured from the [[Model Properties]] panel of the [[Voxel Editor]].| |{{:wiki:group.png?nolink|}}|Movement Area|Determines where this [[NPC]] is permitted to move, for example to any open [[tile|tiles]] or only those within a [[groups|group]] defined for the [[map]].| |{{:wiki:clock.png?nolink|}}|Movement Interval|Determines how long this [[NPC]] will wait (in seconds) between each movement attempt. This can either be a fixed value or a random value within a range.| |{{:wiki:arrow_out.png?nolink|}}|Movement Direction|Determines the direction in which this [[NPC]] will attempt to move. This can either be a random direction, a relative direction (forward, to their left. etc.), or an absolute [[cardinal direction]]. With the "Random" option, they will only move if the randomly selected direction is passable and unobstructed, while "Random (Forced)" indicates that only open paths should be considered (therefore they will always move if an open path is available).| |{{:wiki:stop_sign.png?nolink|}}|Reaction to Obstacle|Determines how this [[NPC]] will react to an obstacle in their path. The options currently include turning left, turning right, reversing direction, or stopping permanently.| |{{:wiki:character_move.png?nolink|}}|Player Interest|Determines if this [[NPC]] should attempt to move towards the [[player character]] ("Seek Out Player") when at a certain distance, or attempt to move away from them ("Avoid Player"). If set to "None", the [[player character|player character's]] proximity will have no effect on the [[NPC]].| |{{:wiki:map_fog.png?nolink|}}|Interest Range|Determines how close the [[player character]] must be in order for them to either be sought out or avoided by this [[NPC]]. This value is measured in number of [[tile|tiles]].| In the example below, the slime has been configured to always move forward at an interval of zero seconds. It is also configured to turn right in reaction to an obstacle. {{:wiki:npc_behavior_example.gif?nolink|}} =====Scripting===== Refer to the table below for a list of behavior settings that can be accessed from a [[script]]. The behavior data is stored as a [[codex]], and each setting can be modified or retrieved using its corresponding key. ^Key^Possible Values^Data Type^ |"interaction_by_player"|"none", "start_dialogue", "start_battle", "run_script"|[[String]]| |"interaction_by_player_dialogue"|[[Dialogue]] name when "interaction_by_player" is "start_dialogue".|[[String]]| |"interaction_by_player_battle"|[[Battle]] name when "interaction_by_player" is "start_battle".|[[String]]| |"interaction_by_player_script"|[[Script]] name when "interaction_by_player" is "run_script".|[[String]]| |"next_to_player"|"none", "start_dialogue", "start_battle", "run_script"|[[String]]| |"next_to_player_dialogue"|[[Dialogue]] name when "next_to_player" is "start_dialogue".|[[String]]| |"next_to_player_battle"|[[Battle]] name when "next_to_player" is "start_battle".|[[String]]| |"next_to_player_script"|[[Script]] name when "next_to_player" is "run_script".|[[String]]| |"collide_with_player"|"none", "run_script"|[[String]]| |"collide_with_player_script"|[[Script]] name when "collide_with_player" is "run_script".|[[String]]| |"on_death"|"none", "run_script"|[[String]]| |"on_death_script"|[[Script]] name when "on_death" is "run_script".|[[String]]| |"can_trigger_scripts"|true, false|[[Boolean]]| |"attackable_in_realtime"|true, false|[[Boolean]]| |"hostility"|Hostility when "attackable_in_realtime" is true. Value can be "always", "attacked", or "never".|[[String]]| |"loot_drop"|Loot drop name when "attackable_in_realtime" is true.|[[String]]| |"xp_value"|Experience points when "attackable_in_realtime" is true.|[[Number]]| |"move_area"|"all", "none", "group"|[[String]]| |"move_area_group"|[[groups|Group]] name when "move_area" is "group".|[[String]]| |"move_interval"|"fixed", "random_range"|[[String]]| |"move_interval_value"|Interval in seconds ([[number]] for "fixed" interval, [[array]] for "random_range" interval).|[[Number]], [[Array]]| |"move_direction"|"none", "random", "random_forced", "forward", "backward", "opposite", "left", "right", "north", "south", "west", "east"|[[String]]| |"obstacle_reaction"|"none", "turn_left", "turn_right", "reverse_direction", "stop", "run_script"|[[String]]| |"obstacle_reaction_script"|[[Script]] name when "obstacle_reaction" is "run_script".|[[String]]| |"player_interest"|"none", "seek_player", "avoid_player"|[[String]]| |"player_interest_range"|Interest range in [[tile|tiles]] when "player_interest" is "seek_player" or "avoid_player".|[[Number]]| **Examples:** entity["some_npc"].behavior["move_interval"] = 1; Changes the movement interval so the character moves every 1 second. entity["some_npc"].behavior["attackable_in_realtime"] = true; Changes the character to be attackable in real-time. entity["some_npc"].behavior = "Other Behavior"; Changes the character's behavior to the "Other Behavior" preset. ~~NOTOC~~