Behavior Operations: Difference between revisions

From PSwiki
Jump to navigation Jump to search
Magodra (talk | contribs)
No edit summary
 
(115 intermediate revisions by 3 users not shown)
Line 1: Line 1:
A “Behavior” in NPCClient is a script defined in [[NPC_Behavior_Data_Structures#npcbehave.xml|npcbehave.xml]] to run to make the npc behave a certain way. It is almost like
A “Behavior” in NPCClient is a script defined in the database (see [[NPC_Behavior_Data_Structures#npcbehave.xml|npcbehave.xml]]) to run to make the npc behave a certain way. It is almost like
a state, for AI designers used to state machine npcs. Example behaviors might include “guard
a state, for AI designers used to state machine npcs. Example behaviors might include “guard
patrol”, “wander in forest”, “fight attackers”, “smith an item”. Before we talk about how
patrol”, “wander in forest”, “fight attackers”, “smith an item”. Before we talk about how
Line 7: Line 7:




== Chase Operation ==
== Assess Operation ==
(Net load: 3, CPU Load 3)
(Net load: 1, CPU Load 1)


{|
{|
Line 16: Line 16:
!Description
!Description
|-
|-
|anim
|physical
|string
|string
|
|
|The animation to use for the chase.
|The prefix for the physical perception.
|-
|-
|type
|magical
|nearest_actor,nearest_npc,nearest_player,owner,target
|string
|
|
|nearest_* is the neares entity of that type. target is current target.
|The prefix for the magical perception.
|-
|-
|range
|overall
|float
|string
|2.0
|
|The range to search for target of the chase.
|The perfix for the overall perception.
|}
 
Each of the physical, magical, or overall will be assessed as; "extremely weaker", "much weaker", "weaker", "equal", "stronger", "much stronger" or "extremely stronger".
 
 
  Ex: <assess overall="$target overall" />
 
Typical reaction to catch the response to this would be as shown in the example below. $target is used here to make sure the correct assessment is matched to the same target. A npc will
not react if the target has changed before the response is received.
 
  Ex: <react event="assess equal" type="$target overall" .../>
      <react event="assess weaker" type="$target overall" .../>
 
== Auto Memorize Operation ==
(Net load: 1, CPU Load 1)
 
{|
!Parameter
!Type
!Default
!Description
|-
|-
|chase_range
|types
|float
|string
| -1
|
|The range at where the chase should give up and issue a "<target> out of chase" perception. -1 is default to disable the max range check.
|Comma separated list of types. "all", can be used to memorize everything to all.
|-
|-
|offset
|enable
|float
|bool
|0.5
|true
|The distance to stop before the target of the chase. See [[Behavior_Offset|Offset]] for more details.
|Enables or disables the types.
|-
|-
|offset_angle
|}
|float
 
|0.0
Auto memorize is a way to turn on and off memorizing of perception. This will be memorize without actually needing to react to thees. Related to the [[Behavior_Operations#Share_Memories_Operation|Share Memories Operation]] and [[Behavior_Operations#Memorize_Operation|Memorize Operation]].
|Size of the arc used to distribute the chase when aproching the target. The angle is in degrees.
 
  Ex: <auto_memorize types="all" />
      <auto_memorize types="Hunting Ground,Marked" />
      <auto_memorize types="Marked" enable="false" />
 
You can use a reaction without a behavior lists to enable the NPC to receive perceptions to be memorized if enabled.
 
  Ex: <react type="location sensed" />
 
== Build Operation ==
(Net load: 1, CPU Load 1)
 
{|
!Parameter
!Type
!Default
!Description
|-
|-
|vel
|pickupable
|float,$WALK,$RUN
|boolean
|Default is to use the velocity from the behavior.
|false
|The velocity to use when chasing.
|If false the building deployed will not be pickupable by the players
|-
|ang_vel
|float
|
|0 is to use the default from the behavior.
|-
|collision
|string
|collision
|The name of the perception to be used when a collision perception is to be fired.
|-
|out_of_bounds
|string
|out of bounds
|The name of the perception to be used when a out of bounds perception is to be fired.
|-
|in_bounds
|string
|in bounds
|The name of the perception to be used when a in bound perception is to be fired.
|}
|}


Build a building as specified bye the NPC's current held building spot as set by the [[Tribe Scripting]] [[Tribe_Scripting#LocateBuildingSpot|locateBuildingSpot]] function.




Chasing a player is one example where both turning and moving at the same time are required to
  Ex: <build />
give a realistic effect to the behavior. We have <move> and <rotate> but this one does them
 
together and intelligently to follow a targeted player or entity. Normally, this will be used to get
== Busy Operation ==
npc’s to chase after players if players run away during a fight.
(Net load: 1, CPU Load 1)
 
{|
!Parameter
!Type
!Default
!Description
|-
|}


  Ex: <chase type="enemy" anim="walk" range=”2” />
Mark a NPC as busy. This will cancle the [[Behavior_Operations#Idle_Operation|Idle Operation]]


In this example, the npc will play the animation called “walk” while moving and turning as
appropriate to reduce his range to his most hated enemy. Of course, he is limited by his speed and
if the player can run faster than he can chase, he will never catch the player. An "<target> out of chase" perception
will be fired in this case.


The “type” attribute of the operation can be either “enemy” as shown here, “owner” to follow the
  Ex: <busy />
NPC’s owner around, or “nearest” to chase after the nearest player at the time the operation was
initiated. This operation will continue until interrupted by another behavior or until the distance to
the target from the npc is less than the range specified. (2 is the default if no range is specified.)
This operation sends DR messages whenever it turns or changes course, plus the DR messages to
start the forward motion and animation, and to stop them. The CPU load is somewhat heavy
because CD must be performed as the npc is chasing, since his path is not predetermined.


== Circle Operation ==
== Cast Operation ==
(Net load: 3, CPU Load: 2)
(Net load: 1, CPU Load 1)


{|
{|
Line 103: Line 119:
!Description
!Description
|-
|-
|anim
|spell
|string
|string
|
|
|The animation to use for the operation.
|The name of the spell to cast.
|-
|-
|radius
|k
|float
|Mandatory, no default value
|Radius to move NPC around with.
|-
|angle
|float
|2PI
|The angle to move. Calculated if 0 and duration not 0.
|-
|duration
|float
|0
|The duration to move in circle. Calculated if 0.
|-
|ang_vel
|float
|float
|
|1.0
|The angular velocity to use when moving in the circle. Calculated if 0.
|The kFactor to use when casting the spell.
|}
|}


Cast a spell on the current selected target.


  Ex: <cast spell="Flame Strike" k="3.0" />


Moving the NPC around in a circle. The following example will move the npc around using the velocity defined in the behavior in one complete circle in 10 sec.
== Change Brain Operation ==
 
(Net load: 1, CPU Load 1)
  Ex: <circle anim="walk" radius=”2” duration="10" />
 
== Debug Operation ==
(Net load: 0, CPU Load: 0)


{|
{|
Line 144: Line 143:
!Description
!Description
|-
|-
|level
|brain
|int
|string
|Mandatory
|
|The level of debug to turn on for current NPC.
|The name of the brain to load.
|-
|-
|exclusive
|brain
|string
|reload
|
|
|Will set on exclusive logging for this NPC.
|Reload the standard NPC brain stored in the sc_npc_definition table.
|-
|}
|}


Turn on and of debug printouts on the server console. Used for debuging of script operations. Level 1-4 Only the biggest events, 5-9 Medium number of events, 10-15 and more is maximum output.
Change the brain of the current selected target.


   Ex: <debug level=”2” />
   Ex: <change_brain brain="Charmed" />


== Dequip Operation ==
== Chase Operation ==
(Net load: 0, CPU Load: 0)
(Net load: 3, CPU Load 3)


{|
{|
Line 168: Line 168:
!Description
!Description
|-
|-
|slot
|anim
|string
|
|The animation to use for the chase.
|-
|adaptiv_vel_script
|string
|string
|Mandatory
|
|The slot to dequip an move back into inventory.
|A [[NPCClient math script]] used to adjust the adaptivVelocityScale. Additional variables defined for this script is "Distance" to the target of the chase and "AdaptivVelScale" that is the value used to adjust velocity. 1.1 will increase the velocity by 10%.
|}
|-
 
|type
Dequip an item held by the NPC in the given slot.
|nearest_actor, nearest_npc, nearest_player, owner, target
 
|
  Ex: <dequip slot="righthand" />
|nearest_* is the nearest entity of that type. target is current target.
 
|-
== Dig Operation ==
|range
(Net load: 0, CPU Load: 0)
|float
 
|2.0
{|
|The range to search for target of the chase.
!Parameter
!Type
!Default
!Description
|-
|-
|resource
|chase_range
|string,tribe:wealth
|float
|Mandatory
| -1
|Resource to dig for or by using the keyword tribe:wealth look up in the tribe to find the resource
|The range at where the chase should give up and issue a "<target> out of chase" perception. -1 is default to disable the max range check.
|}
|-
 
|offset
Order an NPC to start digging for a resource. The keyword "tribe:wealth" will cause the resource to be looked up in the wealth_resource_nic field in the [[NPC_Behavior_Data_Structures#tribes|tribes]] table if the NPC is part of a tribe.
|float
 
|0.5
  Ex: <dig resource="tribe:wealth" />
|The distance to stop before the target of the chase. [[NPC Variables]] will be replaced. Expressions will be resolved. See [[Behavior_Offset|Offset]] for more details.
      <dig resource="Gold Ore" />
 
== Drop Operation ==
(Net load: 0, CPU Load: 0)
 
{|
!Parameter
!Type
!Default
!Description
|-
|-
|slot
|offset_angle
|string
|float
|Mandatory
|0.0
|The slot from which the item is to be dropped.
|Size of the arc used to distribute the chase when approaching the target. The angle is in degrees.
|}
|-
 
|offset_relative_heading
This operation allows an NPC to drop an item he has in inventory on the ground.
|bool
 
|false
  Ex: <drop slot="lefthand" />
|Make the offset relative to the target heading. [[NPC Variables]] will be replaced. See [[Behavior_Offset|Offset]] for more details.
 
|-
== Eat Operation ==
|vel
(Net load: 0, CPU Load: 0)
|float,$WALK,$RUN
 
|Default is to use the velocity from the behavior.
{|
|The velocity to use when chasing.
!Parameter
!Type
!Default
!Description
|-
|-
|resource
|ang_vel
|string,tribe:wealth
|float
|Mandatory
|
|The resource to reward the tribe when eating.
|0 is to use the default from the behavior.
|}
|-
 
|collision
Simple simulation that the tribe would gain things like flesh from eating at a dead entity withing a range of 1.0. The tribe wealth resource would be read from the wealt_resource_name field in the [[NPC_Behavior_Data_Structures#tribes#tribes|tribes]] table.
|string
|collision
  Ex: <eat resource="tribe:wealth" />
|The name of the perception to be used when a collision perception is to be fired.
      <eat resource="Flesh" />
 
== Emote Operation ==
(Net load: 0, CPU Load: 0)
 
{|
!Parameter
!Type
!Default
!Description
|-
|-
|cmd
|out_of_bounds
|string
|string
|
|out of bounds
|The emote cmd to be used as defined in the emote.xml file. Including leading /.
|The name of the perception to be used when a out of bounds perception is to be fired.
|}
|-
This operation allows an NPC to do an emotion.
|in_bounds
|string
|in bounds
|The name of the perception to be used when a in bound perception is to be fired.
|}
 
 


  Ex: <emote cmd="/greet" />
Chasing a player is one example where both turning and moving at the same time are required to
give a realistic effect to the behavior. We have <move> and <rotate> but this one does them
together and intelligently to follow a targeted player or entity. Normally, this will be used to get
npc’s to chase after players if players run away during a fight.


== Equip Operation ==
  Ex: <chase type="target" anim="walk" range=”2” />
(Net load: 0, CPU Load: 0)


{|
In this example, the npc will play the animation called “walk” while moving and turning as
!Parameter
appropriate to reduce his range to his most hated enemy. Of course, he is limited by his speed and
!Type
if the player can run faster than he can chase, he will never catch the player. An "<target> out of chase" perception
!Default
will be fired in this case.
!Description
 
|-
The “type” attribute of the operation can be either “enemy” as shown here, “owner” to follow the
|item
NPC’s owner around, or “nearest” to chase after the nearest player at the time the operation was
|string
initiated. This operation will continue until interrupted by another behavior or until the distance to
|Mandatory
the target from the npc is less than the range specified. (2 is the default if no range is specified.)
|The name of the item to equip
This operation sends DR messages whenever it turns or changes course, plus the DR messages to
start the forward motion and animation, and to stop them. The CPU load is somewhat heavy
because CD must be performed as the npc is chasing, since his path is not predetermined.
 
== Circle Operation ==
(Net load: 3, CPU Load: 2)
 
{|
!Parameter
!Type
!Default
!Description
|-
|-
|slot
|anim
|string
|string
|Mandatory
|
|The sloot to dquip the item in
|The animation to use for the operation.
|-
|radius
|float
|Mandatory, no default value
|Radius to move NPC around with.
|-
|angle
|float
|2PI
|The angle to move. Calculated if 0 and duration not 0.
|-
|duration
|float
|0
|The duration to move in circle. Calculated if 0.
|-
|-
|count
|ang_vel
|int
|float
|1
|
|The number of items to equip. Will be forced to at least 1.
|The angular velocity to use when moving in the circle. Calculated if 0.
|}
|}


Equip one item from inventory into the given slot.


  Ex: <equip item="Sword" slot="righthand" count="1" />


== Invisible Operation ==
Moving the NPC around in a circle. The following example will move the npc around using the velocity defined in the behavior in one complete circle in 10 sec.
(Net load: 0, CPU Load: 0)
 
  Ex: <circle anim="walk" radius=”2” duration="10" />
 
== Control Operation ==
(Net load: 3, CPU Load: 2)


{|
{|
Line 292: Line 305:
!Default
!Default
!Description
!Description
|-
|}
|}
No parameters.


This operation makes the NPC invisible through the toggle visibility command. See [[Behavior_Operations#Visible_Operation|Visible Operation]].


  Ex: <invisible />


== Locate Operation ==
Take control of an player an move with the player.
(Net load: 0, CPU Load 0)
 
  Ex: <control />
 
== Copy_Locate Operation ==
(Net load: 0, CPU Load: 1)


{|
{|
Line 308: Line 323:
!Description
!Description
|-
|-
|obj
|source
|See table below.
|Mandatory
|The object to locate
|-
|failure
|string
|string
|
|Mandatory, no default value
|A perception to fire if fails to locate the given obj.
|The source locate to copy from.
|-
|-
|static
|destination
|boolean
|float
|false
|Mandatory, no default value
|For location the search could be made static. Se description for more details.
|The destination locate to copy to.
|-
|range
|float
| -1
|The maximum range to locate within. -1 represents infinite.
|-
|random
|boolean
|false
|If true a random return within the radius will be made. Otherwise the nearest entry will be returned.
|-
|invisible
|boolean
|false
|Set this to true if the locate operation should consider invisible objects
|-
|invincible
|boolean
|false
|Set this to true if the locate operation should consider invincible objects.
|}
|}


Obj can be one of the following:
 
 
Copy one locate from source to destination. Built in function like Wander and Navigate use the Active locate.
 
  Ex: <locate obj="some thing" destination="SpecialPlace" />
      <copy_locate source="SpecialPlace" destination="Active" />
 
== Debug Operation ==
(Net load: 0, CPU Load: 0)
 
{|
{|
!obj
!Parameter
!Type
!Default
!Description
!Description
|-
|-
|level
|int
|Mandatory
|The level of debug to turn on for current NPC.
|-
|exclusive
|string
|string
|Locate a location. This is the default if none of the following obj types is matched.
|-
|perception
|
|
|Will set on exclusive logging for this NPC.
|}
Turn on and of debug printouts on the server console. Used for debuging of script operations. Level 1-4 Only the biggest events, 5-9 Medium number of events, 10-15 and more is maximum output.
  Ex: <debug level=”2” />
== Dequip Operation ==
(Net load: 0, CPU Load: 0)
{|
!Parameter
!Type
!Default
!Description
|-
|-
|target
|slot
|Locate a target
|string
|-
|Mandatory
|owner
|The slot to dequip an move back into inventory.
|Locate the owner, if this NPC is owned (Pets and stuff)
|}
|-
 
|region
Dequip an item held by the NPC in the given slot.
|Locate a random point within the region of the NPC.
 
|-
  Ex: <dequip slot="righthand" />
|self
 
|Locate your self
== Drop Operation ==
|-
(Net load: 0, CPU Load: 0)
|tribe:home
 
|Locate the npcs [[Tribes|tribe]] home place.
{|
!Parameter
!Type
!Default
!Description
|-
|-
|tribe:memory:string
|slot
|Locate something from the [[Tribes]] memory. See the [[Behavior_Operations#ShareMemories_Operation|ShareMemories]] and [[Behavior_Operations#Memorize_Operation|Memorize]] operation.
|string
|-
|Mandatory
|tribe:resource
|The slot from which the item is to be dropped.
|Locate a resource location from the memory of the [[Tribes|tribe]].
|-
|friend
|Locate a friend.
|-
|waypoint
|Will locate a waypoint.
|-
|waypoint:group:string
|Locate a waypoint from a given group
|-
|waypoint:name:string
|Locate a waypoint by name.
|}
|}


This operation is one of the more flexible and crucial operations in npc scripting. It allows the
This operation allows an NPC to drop an item he has in inventory on the ground.
scripter to have his npc “find” a certain thing or type of thing, and remember that location for other
scripting commands later such as turning, moving or attacking. The operation will store the position
found in the NPCs as active postion and calcualte the neares waypoint and store that in the active_waypoint.
For location it is possible to make the first search a static search. So that the first time the npc
do this operation it could search for a "Baker" location. The next time the operation is used it will
use the results of the first time even if there might be Bakers closer at that time.


   Ex: <locate obj="perception" />
   Ex: <drop slot="lefthand" />
      <locate obj="enemy" />
      <locate obj="furnace" range="50" />
      <locate obj="waypoint" failure="no waypoint found" />


Example 1 finds the last perception received by the current npc and sets the active target location to
== Eat Operation ==
the location of that perception. This allows npcs who receive “Talk” perceptions to turn to face the
(Net load: 0, CPU Load: 0)
person talking to them. It allows npcs who have a spell cast on them to turn to face the caster, and
so on.


Example 2 finds the location of the currently active “enemy” of the NPC, which is the entity with
{|
the highest score on the NPC’s hate list, and sets that location as the active target location for other
!Parameter
operations. This allows NPCs to turn to face the person they are attacking, chase attackers who are
!Type
retreating, etc.
!Default
!Description
|-
|resource
|string,tribe:wealth
|Mandatory
|The resource to reward the tribe when eating.
|}


Example 3 uses predefined lists of named location types to find the closest one to the npc and sets
Simple simulation that the tribe would gain things like flesh from eating at a dead entity withing a range of 1.0. The tribe wealth resource would be read from the wealt_resource_name field in the [[NPC_Behavior_Data_Structures#tribes#tribes|tribes]] table.
the active target location to the coordinates specified there. This is the most subtle of the 3, and in
some ways the most powerful so it deserves more discussion. Consider the following pictures:
  Ex: <eat resource="tribe:wealth" />
      <eat resource="Flesh" />


http://www.planeshift.it/download/docs/npc_pic1.png
== Emote Operation ==
(Net load: 0, CPU Load: 0)


Here we have two blacksmith shops with similar items but different layouts. They might be side by
{|
side or they might be in entirely different cities. LocTypes specify a list of Anvil locations, or a list
!Parameter
of Furnace locations, as marked by the stars on these pictures. When Example 3 says to locate the
!Type
nearest furnace, an NPC in smithy #1 will find his furnace while the NPC in smithy #2 will find his
!Default
own furnace. They will be able to share one script for moving between these points and acting like
!Description
a real blacksmith in their own location, even though they are in totally different smithy shops.
|-
|cmd
|string
|
|The emote cmd to be used as defined in the emote.xml file. Including leading /.
|}
This operation allows an NPC to do an emotion.


This will become even more important when we implement player housing and player shops. It
  Ex: <emote cmd="/greet" />
will be possible with the scripts we have already today for a player to build the blacksmith shop of
his own design and for him to hire an npc smith to come work in that shop. The Smith NPC he
hired will be able to “know” how to get around the player’s shop magically.


Something intended to be supported here but not actually implemented yet was the ability to locate
== Equip Operation ==
named objects or entities as well, so an NPC could locate a sword someone dropped on the ground
and things like this. Better integration with the entity system and perhaps integration with data
from the maps themselves rather than externally generated lists of points could make this even more
powerful.
 
== Loop Operation ==
(Net load: 0, CPU Load: 0)
(Net load: 0, CPU Load: 0)


Line 445: Line 450:
!Description
!Description
|-
|-
|iterations
|item
|string
|Mandatory
|The name of the item to equip
|-
|slot
|string
|Mandatory
|The sloot to dquip the item in
|-
|count
|int
|int
|0
|1
|Number of iterations to do in this loop.
|The number of items to equip. Will be forced to at least 1.
|}
|}


This operation allows you to loop a section of your script a certain number of times. This is mostly
Equip one item from inventory into the given slot.
useful for city npcs such as smiths and tavern barkeeps. Behaviors in general will loop if not
 
replaced by another behavior, but if you want subloops within the script, this is an easy way to do it.
  Ex: <equip item="Sword" slot="righthand" count="1" />
 
 
Ex:
== Hate List Operation ==
  <loop iterations="20">
(Net load: 0, CPU Load: 0)
    <locate obj="fire" range="10" />
    <navigate anim="walk" />
    <wait anim="stand" duration="30" />
    <locate obj="anvil" range="10" />
    <navigate anim="walk" />
    <wait anim="hammer" duration="20" />
  </loop>
 
In this example, the blacksmith is scripted to walk back and forth between his fire and his anvil 20
times before moving on to the next operation in his script to act like a blacksmith.
 
This operation does not affect the network at all and does not have CPU overhead.
 
== Melee Operation ==
(Net load: 1, CPU Load: 2)


{|
{|
!Parameter
!Parameter
!Type
!Default
!Description
!Description
|-
|-
|seek_range
|delta
|float
|
|Add delta to hate list.
|-
|absolute
|float
|float
|0.0
|
|The range to search for new targets in melee
|Set the hate value.
|-
|-
|melee_range
|max
|float[0.5-3.0]
|float
|3.0
|
|The range where melee can be done. Max 3.0 to prevent npc/server conflicts.
|Hate should have a max value
|-
|-
|invisible
|min
|boolean
|float
|false
|
|Will melee operation fight invisible entities
|Hate should have a min value
|-
|-
|invincible
|perception
|boolean
|bool
|false
|false
|Will melee operation fight invincible entities.
|Use perception instead of target to find target.  
|}
|}


The <melee> operation handles starting and ending fights for the NPC. It finds the most hated
Adjust the hate list for an npc. The current target or perception target is the target entry for the adjustment.
enemy in range and tells the server to attack him. If there is no enemy in range, it finds the nearest
 
enemy that it does hate and prepares to chase him.
  Ex: <hate_list delta="0.5" max="10.0" />
 
  Ex: <locate obj="perception" />
      <hate_list absolute="5.0" />
 
      Is equvivalent with:
 
      <hate_list perception="yes" absolute="5.0" />


  Ex: <melee seek_range="10" melee_range="3" />
== Idle Operation ==
(Net load: 1, CPU Load 1)


The “melee_range” attribute specifies how far away the enemies can be while still fighting without
{|
the npc needing to move. 3 meters is the maximum of how far away a player can be to hit the npc
!Parameter
also, so in most cases this is a good value. The “seek_range” specifies how far around himself the
!Type
npc should look for other enemies if none are found within the melee_range. If there are no
!Default
enemies within the seek_range, the npc starts to calm down and his current behavior (making his
!Description
‘melee’ operation active) is lowered in priority. If an enemy is found within the seek_range, the
|-
NPC’s active enemy is set to this found person so the <chase type=”enemy”> operation can run
|}
after him.
 
This operation’s only network load is informing the server of its melee target and attack mode, and
switching these occasionally as people die, etc. The CPU load is in periodically (2x per second)
checking the hate list for the NPC to make sure the most hated person is being fought. If no one on
the hate list is within the melee range, a more expensive operation is done to find any hated people
within the seek_range, but this operation isn’t performed very often.


The NPC Hate List is a very important thing for an npc scripter to understand. Each NPC maintains
Mark a NPC as idle. This operation cancle the [[Behavior_Operations#Busy_Operation|Busy operation]].
its own list of entities that it does not like, and each of these entities gets a hate score based on what
the entity does to the npc. For example, an npc on startup has an empty hate list. But then a player
(“Androgos”) attacks him and hits him for 10 damage:


Hatelist: Androgos-10


Now Androgos is the most hated player (because he is the only one) and the npc chooses to fight
  Ex: <idle />
him back with his <melee> operation. A few seconds later in the fight, Androgos hits him again for
12 damage and Androgos’s friend “Gronomist” casts a Fire spell on the npc also, for 25 damage.


Hatelist: Androgos-22, Gronomist-25
== Invisible Operation ==
 
Next time the <melee> operation is checked, Gronomist becomes the most hated person and the npc
will switch his attack to focus on Gronomist. Meanwhile, a 3rd player in the group, “Djagg” is the
healer of the group and heals Androgos’s wounds for 15 HP, which the NPC really hates.
 
Hatelist: Androgos-22, Gronomist-25, Djagg-45
 
So now the NPC decides to go after the healer. And so on. The idea is that the tactics of the NPC
can be determined by the way he reacts to different events during combat such as spells, damage
and healing. Different reactions can be scripted for different npcs, as we will see in the next
section.
 
When a player dies, they are removed from the hatelist. So the NPC will not recognize the
reincarnated player when he comes back. This keeps the entire world from attacking players all the
time, and keeps hatelists reasonably short. Likewise, when the NPC dies, his entire hatelist is
cleared out.
 
== Memorize Operation ==
(Net load: 0, CPU Load: 0)
(Net load: 0, CPU Load: 0)
Tribe operation.


{|
{|
Line 559: Line 541:
!Description
!Description
|}
|}
No Parameters.
No parameters.


This is an operation that only will have effect for tribe members. The NPC will memorize the current perception as a private memory.
This operation makes the NPC invisible through the toggle visibility command. See [[Behavior_Operations#Visible_Operation|Visible Operation]].
See the [[Behavior_Operations#ShareMemories_Operation|ShareMemories Operation]] for how to make the memories known to other members of the tribe.


   Ex: <memorize />
   Ex: <invisible />


== Move Operation ==
== Locate Operation ==
(Net load: 0, CPU Load: 5)  
(Net load: 0, CPU Load 0)


{|
{|
Line 575: Line 556:
!Description
!Description
|-
|-
|anim
|obj
|See table below.
|Mandatory
|The object to locate. [[NPC Variables]] will be replaced.
|-
|failure
|string
|string
|
|
|The animation to use when moving.
|A perception to fire if fails to locate the given obj.
|-
|static
|boolean
|false
|For location the search could be made static. Se description for more details.
|-
|-
|duration
|range
|float
|float
|0.0
| -1
|The duration this move should have. The default is probably no good.  
|The maximum range to locate within. -1 represents infinite.
|-
|-
|vel
|random
|float,$WALK,$RUN
|boolean
|Default is to use the velocity from the behavior.
|false
|The velocity to use when moving.
|If true a random return within the radius will be made. Otherwise the nearest entry will be returned.
|-
|-
|ang_vel
|outside_region
|float
|boolean
|0.0
|false
|By defining a ang_vel the movement will be much like the [[Behavior_Operations#Circle_Operation|Circle Operation]].
|Set this to true if the locate operation should consider entities outside region as well if a region is defined. [[NPC Variables]] will be replaced.
|-
|-
|collision
|invisible
|string
|boolean
|collision
|false
|The name of the perception to be used when a collision perception is to be fired.
|Set this to true if the locate operation should consider invisible objects
|-
|-
|out_of_bounds
|invincible
|string
|boolean
|out of bounds
|false
|The name of the perception to be used when a out of bounds perception is to be fired.
|Set this to true if the locate operation should consider invincible objects.
|-
|-
|in_bounds
|destination
|string
|string
|in bounds
|Active
|The name of the perception to be used when a in bound perception is to be fired.
|Set the destination [[NPC locate location]]. [[NPC Variables]] will be replaced.
|}
|}


The most basic behavior operation in npcclient is <move>. It simply tells the npc to move forward
Obj can be one of the following:
at a certain speed in the direction he is currently pointing, and to play a named animation while
{|
doing so.
!obj
 
!Description
  Ex: <move vel="1" anim="walk" />
|-
      <move anim="walk" vel="$WALK" out_of_bounds="move_outside_region" />
|<string>
 
|Locate a location. This is the default if none of the following obj types is matched.
This operation has no preset end or duration, so it will go until the behavior is preempted by another
|-
higher priority behavior such as the one to turn, triggered by a collision perception. (See the next
|actor
section for a more detailed explanation of how behaviors pre-empt each other and change
|Located nearest actor
priorities.)
|-
 
|building_spot
This operation has low networking overhead since all it does is trigger a single Dead Reckoning
|Locate a building spot from the npc's building spot.
(DR) update to start the forward motion. It does have CPU overhead during the entire duration of it
|-
running though, since there is no way for npcclient to know what it might hit along this path. Every
|dead
500msec this operation wakes up and checks its latest movement for collisions, generating a
|Nearest dead actor
perception called “collision” for the behavior script to react to. Also at each 500msec checkpoint,
|-
it checks the owner NPC’s region setting (such as “sunny meadow” in the example above), and if
|entity:name:<name>
there is a region specifed, the operation checks its current position to make sure the NPC is still “in
|Entity with given name
bounds”. If the NPC has made it outside the region in the last half second, it fires a perception
|-
called “out of bounds”. It will not fire another “out of bounds” perception until an “in bounds”
|entity:pid:<pid>
perception has been detected.
|Entity with given pid
 
== MovePath Operation ==
(Net load: 2, CPU Load: 3)
 
{|
!Parameter
!Type
!Default
!Description
|-
|-
|path
|friend
|string
|Nearest visible friend (NPC)
|Mandatory
|-
|The name of the path to use for the movement.
|local_region
|Locate region in current sector.
|-
|ownbuffer
|Locate the own buffer.
|-
|owner
|Locate the owner, if this NPC is owned (Pets and stuff)
|-
|perception
|The location of the last received perception.
|-
|player
|Nearest player
|-
|-
|anim
|point
|string
|Random point
|
|The name of the animation to use for this movement
|-
|-
|direction
|region
|FORWARD,REVERSE
|Locate a random point within the region of the NPC.
|FORWARD
|-
|The direction to move along the path
|self
|}
|Locate your self
 
|-
This operation tell the NPC to move in a predefined path. The path is a named entity in the path network.  
|spawn
From a start waypoint to and end waypoint with any number of path points in between. The path will either
|Spawn location of the npc.
be followed in the forward or reverse direction. Upon start of this the npc will be forced to the
|-
start position of the path. The following example will move the NPC the reverse path to the clock tower.
|target
  Ex: <movepath path="Clock Tower" direction="REVERSE" />
|Locate a target. The target will be the most hated from the NPC [[hate list]].
 
|-
  Ex: <behavior "Ring the Clock">
|tribe:home
        <movepath path="Clock Tower" />
|Locate the npcs [[Tribes|tribe]] home place.
        <wait anim="Ring the Clock" />
|-
        <movepath path="Clock Tower" direction="REVERSE" />
|tribe:memory:string
      </behavior>
|Locate something from the [[Tribes]] memory. See the [[Behavior_Operations#Share_Memories_Operation|ShareMemories]] and [[Behavior_Operations#Memorize_Operation|Memorize]] operation.
 
|-
Current implementation will extrapolate on the server and send updates to the client.
|tribe:resource
 
|Locate a resource location from the memory of the [[Tribes|tribe]].
The following old description isn't quite in line with current implementation. Sure it should be possible
|-
to send the path to the client and do the math there. Suggest to include that as a option to the current
|tribe:target
implementation. With today implementation the movement could be interrupted and it will stop when finished
|Locate the most hated target for this tribe. The target will be the most hated from all the NPCs [[hate list]] in the tribe.
with the path. To get the looping behavior either the behavior should be set to looping or a loop should
|-
be created.
|waypoint
|Will locate a waypoint.
|-
|waypoint:group:string
|Locate a waypoint from a given group
|-
|waypoint:name:string
|Locate a waypoint by name.
|}


--Start old description:
This operation is one of the more flexible and crucial operations in npc scripting. It allows the
scripter to have his npc “find” a certain thing or type of thing, and remember that location for other
scripting commands later such as turning, moving or attacking. The operation will store the position
found in the NPCs as active postion and calcualte the neares waypoint and store that in the active_waypoint.
For location it is possible to make the first search a static search. So that the first time the npc
do this operation it could search for a "Baker" location. The next time the operation is used it will
use the results of the first time even if there might be Bakers closer at that time.


This operation is another very easy one: <movepath>. It tells the npc to set its preset path to a 3d
  Ex: <locate obj="perception" />
spline specified in another file by name. Each client will take care of playing the right animations
      <locate obj="target" />
along the spline as the npc progresses. The intent of this operation was really simply for birds to be
      <locate obj="furnace" range="50" />
able to fly through the air as decoration rather than any gameplay reason. Aside from birds, most
      <locate obj="waypoint" failure="no waypoint found" />
creatures do not follow 3d spline paths in their normal behaviors.


  Ex: <movepath path="bird1" />
Example 1 finds the last perception received by the current npc and sets the active target location to
the location of that perception. This allows npcs who receive “Talk” perceptions to turn to face the
person talking to them. It allows npcs who have a spell cast on them to turn to face the caster, and
so on.


This operation has no present end or duration, and will actually loop if not stopped by another
Example 2 finds the location of the currently active “enemy” of the NPC, which is the entity with
behavior.
the highest score on the NPC’s [[hate list]], and sets that location as the active target location for other
operations. This allows NPCs to turn to face the person they are attacking, chase attackers who are
retreating, etc.


This operation has almost no network overhead, as the packed bytes of the spline are sent 1 time
Example 3 uses predefined lists of named location types to find the closest one to the npc and sets
across the network to anyone needing to see this npc, and no other network activity happens until
the active target location to the coordinates specified there. This is the most subtle of the 3, and in
the <movepath> operation is interrupted.
some ways the most powerful so it deserves more discussion. Consider the following pictures:


This operation also has almost zero CPU overhead, because there is no collision detection and no
http://www.planeshift.it/public/download/docs/npc_pic1.png
bounds checking on this type of movement. The reasoning is that since predefined paths are being
followed, it is up to the designer/scripter to ensure that the path goes where they want it to and does
not hit anything along the way.


--End old description
Here we have two blacksmith shops with similar items but different layouts. They might be side by
side or they might be in entirely different cities. LocTypes specify a list of Anvil locations, or a list
of Furnace locations, as marked by the stars on these pictures. When Example 3 says to locate the
nearest furnace, an NPC in smithy #1 will find his furnace while the NPC in smithy #2 will find his
own furnace. They will be able to share one script for moving between these points and acting like
a real blacksmith in their own location, even though they are in totally different smithy shops.
 
This will become even more important when we implement player housing and player shops. It
will be possible with the scripts we have already today for a player to build the blacksmith shop of
his own design and for him to hire an npc smith to come work in that shop. The Smith NPC he
hired will be able to “know” how to get around the player’s shop magically.
 
Something intended to be supported here but not actually implemented yet was the ability to locate
named objects or entities as well, so an NPC could locate a sword someone dropped on the ground
and things like this. Better integration with the entity system and perhaps integration with data
from the maps themselves rather than externally generated lists of points could make this even more
powerful.


== MoveTo Operation ==
The Locate Operation does NOT move the NPC.
(Net load: 0, CPU Load: 3)


{|
To have the NPC move you need to have a navigate or move operation after, this can be done with subsequent
!Parameter
 
!Type
  <locate obj="something" destination="Move" />
!Default
  <navigate  />
!Description
 
|-
If you want to trigger a separate behaviour you can use a perception (this is the actual version we use in PlaneShift, using the Move Behaviour)
|x
 
|float
  <locate obj="something" destination="Move" />
|0.0
  <percept event="move" />
|X-coordinate to move to
 
== Loop Operation ==
(Net load: 0, CPU Load: 0)
 
{|
!Parameter
!Type
!Default
!Description
|-
|-
|y
|iterations
|float
|int
|0.0
|0
|Y-coordinate to move to
|Number of iterations to do in this loop. No iterations attribute or a value of -1 is loop forever.
|-
|}
|z
|float
|0.0
|Z-coordinate to move to
|-
|vel
|float,$WALK,$RUN
|Default is to use the velocity from the behavior.
|The velocity to use when moving.
|-
|anim
|string
|
|The name of the animation to use
|}


This operation tells the npc to turn and face a certain point in
This operation allows you to loop a section of your script a certain number of times. This is mostly
3d space, then move in a straight line to that location at a certain speed. The turn is not animated,
useful for city npcs such as smiths and tavern barkeeps. Behaviors in general will loop if not
so if you want an animated turn, you need a <rotate> op in front of this (see below). <moveto> also
replaced by another behavior, but if you want subloops within the script, this is an easy way to do it.
specifies an animation name to play while performing this move.


  Ex: <moveto x="-38" y="0" z="-169" anim="walk" />
Ex:
 
  <loop iterations="20">
When this operation is executed, the angle necessary to point in the right direction towards this 3d
    <locate obj="fire" range="10" />
coordinate is calculated and the DR message to start the anim, start the movement and set the
    <navigate anim="walk" />
rotation angle so it will look correct is sent. Then the operation calculates the time it will take to
    <wait anim="stand" duration="30" />
traverse the distance at the specified speed and suspends itself for that length of time before waking
    <locate obj="anvil" range="10" />
up and completing. Thus, this operation has zero processing during these ½ second update
    <navigate anim="walk" />
opportunities. No CD checking is done and no bounds checking is done.
    <wait anim="hammer" duration="20" />
  </loop>


When the operation wakes up a few seconds later, the <moveto> is considered complete, and
In this example, the blacksmith is scripted to walk back and forth between his fire and his anvil 20
npcclient sends another DR message to stop the movement.
times before moving on to the next operation in his script to act like a blacksmith.


While this operation is very cheap, it is also not very flexible because the coordinates are in the
This operation does not affect the network at all and does not have CPU overhead.
NPCType and not in the NPC. Thus any NPC using this NPC Type with this command in it is
going to have to be willing to move to this exact 3d coordinate.


== Navigate Operation ==
== Melee Operation ==
(Net load: 1, CPU Load 1)  
(Net load: 1, CPU Load: 2)


{|
{|
Line 768: Line 782:
!Description
!Description
|-
|-
|anim
|seek_range
|float
|0.0
|The range to search for new targets in melee
|-
|melee_range
|float[0.5-3.0]
|3.0
|The range where melee can be done. Max 3.0 to prevent npc/server conflicts.
|-
|attack_type
|string
|default
|The name of a special attack defined in the 'attacks' table. If this attribute is not set an ordinary attack will be queued. [[NPC Variables]] will be replaced.
|-
|stance
|string
|string
|
|normal
|The animation to use in the navigation.
|The stance to use when attacking. [[NPC Variables]] will be replaced.
|}
|-
 
|tribe
 
|boolean
The <navigate> operation is a placeholder right now and is simpler than it will be in the future. It is
|false
designed to work with <locate> and it moves the NPC in a straight line to the target location found
|When set to true the tribe [[hate list]] will be used to select target. If true and NPC not member of a tribe the NPC [[hate list]] will be used as a fall back. [[NPC Variables]] will be replaced.
by the <locate> operation.
|-
|outside_region
|boolean
|false
|Set to true to fight even outside region if a region is defined. [[NPC Variables]] will be replaced.
|-
|invisible
|boolean
|false
|Will melee operation fight invisible entities
|-
|invincible
|boolean
|false
|Will melee operation fight invincible entities.
|}


  Ex: <navigate anim="walk" />
The <melee> operation handles starting and ending fights for the NPC. It finds the most hated
enemy in range and tells the server to attack him. If there is no enemy in range, it finds the nearest
enemy that it does hate and prepares to chase him.


The only thing the operation specifies is the animation to play while moving. It works much like
  Ex: <melee seek_range="10" melee_range="3" />
<moveto> but uses the locate target destination instead of a single fixed location. The only network
overhead are the Start and Stop DR messages, and the only CPU overhead is calculating how long
to sleep between starting and stopping.


For more complex movement the [[Behavior_Operations#Wander_Operation|Wander Operation]] should be
The “melee_range” attribute specifies how far away the enemies can be while still fighting without
used that will use the path network to navigate. Though if there are no path directly to the location
the npc needing to move. 3 meters is the maximum of how far away a player can be to hit the npc
to where the NPC should go a combination of Wander and Navigate could be used. Like this example
also, so in most cases this is a good value. The “seek_range” specifies how far around himself the
where wander is used to navigate using waypoints and navigate is used navigate into the exact
npc should look for other enemies if none are found within the melee_range. If there are no
position of the tavern.
enemies within the seek_range, the npc starts to calm down and his current behavior (making his
‘melee’ operation active) is lowered in priority. If an enemy is found within the seek_range, the
NPC’s active enemy is set to this found person so the <chase type=”enemy”> operation can run
after him.
 
This operation’s only network load is informing the server of its melee target and attack mode, and
switching these occasionally as people die, etc. The CPU load is in periodically (2x per second)
checking the [[hate list]] for the NPC to make sure the most hated person is being fought. If no one on
the [[hate list]] is within the melee range, a more expensive operation is done to find any hated people
within the seek_range, but this operation isn’t performed very often.
 
See the NPC [[hate list]] for further details about the [[hate list]].


  Ex <locate obj="tavern" static="yes" random="yes" range="800" > <!-- Locate my favorite tavern -->
== Memorize Operation ==
    <wander />
(Net load: 0, CPU Load: 0)
    <navigate />


== Percept Operation ==
Tribe operation.
(Net load: 0, CPU Load: 0)


{|
{|
Line 804: Line 856:
!Default
!Default
!Description
!Description
|-
|}
|event
No Parameters.
|string
 
|
This is an operation that only will have effect for tribe members. The NPC will memorize the current perception as a private memory.
|The name of the perception event to fire
See the [[Behavior_Operations#Share_Memories_Operation|Share Memories Operation]] for how to make the memories known to other members of the tribe.
|-
|target
|self,tribe,all,target
|self
|The recipient of this perception
|-
|range
|float
|0.0
|If set to something greater than 0.0 this perception will only be deviled if within that range.
|}
This operation allows an NPC to fire a custom perception to himself.


   Ex: <percept event="done wandering" />
   Ex: <memorize />
      <percept event="need help" target="tribe" range="50" />


== Pickup Operation ==
== Move Operation ==
(Net load: 0, CPU Load: 0)  
(Net load: 0, CPU Load: 5)  


{|
{|
Line 834: Line 873:
!Description
!Description
|-
|-
|obj
|anim
|string,perception
|string
|perception
|
|The object to pick up. (Only perception implemented)
|The animation to use when moving.
|-
|duration
|float
|0.0
|The duration this move should have. The default is probably no good.  
|-
|-
|count
|vel
|int
|float,$WALK,$RUN
|1
|Default is to use the velocity from the behavior.
|Number of objects to pick up
|The velocity to use when moving.
|-
|-
|equip
|ang_vel
|slot
|float
|
|0.0
|name of slot to equip the item in (Not implemented)
|By defining a ang_vel the movement will be much like the [[Behavior_Operations#Circle_Operation|Circle Operation]].
|}
|-
This operation allows an NPC to pickup an item he finds on the ground, and optionally equip(Not implemented) it if he can use it. Only objects that are packable will be picked up.
|collision
 
|string
  Ex: <pickup obj="perception" cout="2" />
|collision
      <pickup obj="perception" equip="righthand" /> (Not Implemented)
|The name of the perception to be used when a collision perception is to be fired.
 
|-
== Reproduce Operation ==
|out_of_bounds
(Net load: 0, CPU Load: 0)
|string
 
|out of bounds
{|
|The name of the perception to be used when a out of bounds perception is to be fired.
!Parameter
|-
!Type
|in_bounds
!Default
|string
!Description
|in bounds
|The name of the perception to be used when a in bound perception is to be fired.
|}
|}
No Parameters.


The reproduce operation will spawn the target.
The most basic behavior operation in npcclient is <move>. It simply tells the npc to move forward
 
at a certain speed in the direction he is currently pointing, and to play a named animation while
  Ex: <reproduce />
doing so.


To make make a copy of your self
  Ex: <move vel="1" anim="walk" />
      <move anim="walk" vel="$WALK" out_of_bounds="move_outside_region" />


  Ex: <locate obj="self" />
This operation has no preset end or duration, so it will go until the behavior is preempted by another
      <reproduce />
higher priority behavior such as the one to turn, triggered by a collision perception. (See the next
section for a more detailed explanation of how behaviors pre-empt each other and change
priorities.)


== Resurrect Operation ==
This operation has low networking overhead since all it does is trigger a single Dead Reckoning
(Net load: 0, CPU Load: 0)
(DR) update to start the forward motion. It does have CPU overhead during the entire duration of it
running though, since there is no way for npcclient to know what it might hit along this path. Every
500msec this operation wakes up and checks its latest movement for collisions, generating a
perception called “collision” for the behavior script to react to. Also at each 500msec checkpoint,
it checks the owner NPC’s region setting (such as “sunny meadow” in the example above), and if
there is a region specifed, the operation checks its current position to make sure the NPC is still “in
bounds”. If the NPC has made it outside the region in the last half second, it fires a perception
called “out of bounds”. It will not fire another “out of bounds” perception until an “in bounds”
perception has been detected.


Tribe operation.
== MovePath Operation ==
(Net load: 2, CPU Load: 3)


{|
{|
Line 884: Line 940:
!Default
!Default
!Description
!Description
|-
|path
|string
|Mandatory
|The name of the path to use for the movement.
|-
|anim
|string
|
|The name of the animation to use for this movement
|-
|direction
|FORWARD,REVERSE
|FORWARD
|The direction to move along the path
|}
|}
No Parameters.


This operation will resurrect a tribe member within the radius of tribe home.
This operation tell the NPC to move in a predefined path. The path is a named entity in the path network.
From a start waypoint to and end waypoint with any number of path points in between. The path will either
be followed in the forward or reverse direction. Upon start of this the npc will be forced to the
start position of the path. The following example will move the NPC the reverse path to the clock tower.
  Ex: <movepath path="Clock Tower" direction="REVERSE" />


   Ex: <resurrect />
   Ex: <behavior "Ring the Clock">
 
        <movepath path="Clock Tower" />
This operation should be placed in an behavior that will be executed for dead NPCs. The reaction should
        <wait anim="Ring the Clock" />
as well have the when_dead flag set.
        <movepath path="Clock Tower" direction="REVERSE" />
  Ex: <behavior name="Resurrect" completion_decay="200" growth="0" initial="0" when_dead="yes">
        <resurrect/>
       </behavior>
       </behavior>
      <react event="tribe:resurrect"    behavior="Resurrect"    inactive_only="yes" when_dead="yes" />


== Reward Operation ==
Current implementation will extrapolate on the server and send updates to the client.
(Net load: 0, CPU Load: 0)
 
The following old description isn't quite in line with current implementation. Sure it should be possible
to send the path to the client and do the math there. Suggest to include that as a option to the current
implementation. With today implementation the movement could be interrupted and it will stop when finished
with the path. To get the looping behavior either the behavior should be set to looping or a loop should
be created.


Tribe operation.
--Start old description:


{|
This operation is another very easy one: <movepath>. It tells the npc to set its preset path to a 3d
!Parameter
spline specified in another file by name. Each client will take care of playing the right animations
!Type
along the spline as the npc progresses. The intent of this operation was really simply for birds to be
!Default
able to fly through the air as decoration rather than any gameplay reason. Aside from birds, most
!Description
creatures do not follow 3d spline paths in their normal behaviors.
|-
|resource
|string,tribe:wealth
|Mandatory
|The resource to reward to the tribe.
|-
|count
|int
|1
|The number of resource to reward.
|}


Will reward a tribe with a resource. Using the special ''tribe:wealth'' keyword will result in a lockup in the tribe for whats the wealth resource.
  Ex: <movepath path="bird1" />


  Ex: <reward resource="Gold Ore" count="2" />
This operation has no present end or duration, and will actually loop if not stopped by another
      <reward resource="tribe:wealth" />
behavior.


== Rotate Operation ==
This operation has almost no network overhead, as the packed bytes of the spline are sent 1 time
(Net load: 1, CPU Load: 0)
across the network to anyone needing to see this npc, and no other network activity happens until
the <movepath> operation is interrupted.


{|
This operation also has almost zero CPU overhead, because there is no collision detection and no
bounds checking on this type of movement. The reasoning is that since predefined paths are being
followed, it is up to the designer/scripter to ensure that the path goes where they want it to and does
not hit anything along the way.
 
--End old description
 
== MoveTo Operation ==
(Net load: 0, CPU Load: 3)
 
{|
!Parameter
!Parameter
!Type
!Type
Line 935: Line 1,010:
!Description
!Description
|-
|-
|type
|x
|inregion, random, absolute, relative, locatedest, target
|Mandatory
|The type of rotation operation to perform.
|-
|ang_vel
|float
|float
|0.0
|0.0
|Angular velocity in degree. If 0 the NPC default angular velocity will be used.
|X-coordinate to move to
|-
|-
|anim
|y
|string
|
|The animation to use for the rotation operation
|-
|max
|float
|float
|0.0
|0.0
|For inregion and random a range can be defined.
|Y-coordinate to move to
|-
|-
|min
|z
|float
|float
|0.0
|0.0
|For inregion and radom a range can be defined.
|Z-coordinate to move to
|-
|vel
|float,$WALK,$RUN
|Default is to use the velocity from the behavior.
|The velocity to use when moving.
|-
|-
|value
|anim
|float
|string
|0.0
|
|For absolute and relative a value to add in degrees should be given.
|The name of the animation to use
|}
|}


This operation <rotate> can be used to turn to a certain angle, to turn a relative amount, to turn a
This operation tells the npc to turn and face a certain point in
random amount or to turn to face a previously located object. This turn is animated, to give a more
3d space, then move in a straight line to that location at a certain speed. The turn is not animated,
realistic look.
so if you want an animated turn, you need a <rotate> op in front of this (see below). <moveto> also
specifies an animation name to play while performing this move.


   Ex: <rotate type="random" min="90" max="270" anim="walk" vel="30" />
   Ex: <moveto x="-38" y="0" z="-169" anim="walk" />
      <rotate type="locatedest" anim="walk" vel="90" />


The first example here is a random turn of between 90 and 270 degrees from the current heading,
When this operation is executed, the angle necessary to point in the right direction towards this 3d
with an angular velocity of 30 degrees per second, while playing the “walk” animation. 30 degrees
coordinate is calculated and the DR message to start the anim, start the movement and set the
per second means that the maximum turn of 270 degrees will take the npc 9 seconds.
rotation angle so it will look correct is sent. Then the operation calculates the time it will take to
traverse the distance at the specified speed and suspends itself for that length of time before waking
up and completing. Thus, this operation has zero processing during these ½ second update
opportunities. No CD checking is done and no bounds checking is done.


In the second example, we have already used our <locate> operation to find a point of interest near
When the operation wakes up a few seconds later, the <moveto> is considered complete, and
us, and we want to turn to point directly at it. Here a different (faster) angular velocity is specified
npcclient sends another DR message to stop the movement.
but other angles aren’t necessary because they are implied by the current position of the NPC and
the located special destination.


This operation requires a DR update to start and stop the rotation, as the only networking overhead.
While this operation is very cheap, it is also not very flexible because the coordinates are in the
CPU overhead is also minimal since npcclient calculates the time required to turn the full amount
NPCType and not in the NPC. Thus any NPC using this NPC Type with this command in it is
and puts this script to sleep for that many msec until the turn is done, then stops it.
going to have to be willing to move to this exact 3d coordinate.


== Sequence Operation ==
== Navigate Operation ==
(Net load: 0, CPU Load: 0)
(Net load: 1, CPU Load 1)  


{|
{|
Line 995: Line 1,066:
!Description
!Description
|-
|-
|name
|anim
|string
|string
|Mandatory
|
|The name of the sequence to control
|The animation to use in the navigation.
|-
|-
|cmd
|failure
|start,stop,loop
|string
|Mandatory
|
|The control of the sequence to issue.
|The perception to fire if the operation fails.
|-
|count
|int
|1
|The number of times to loop the sequence.
|}
|}


Sequences are defined in the map file. They can be started, stopped, or played a number of time with the loop command. This allow the NPC to interact with large animation of world objects. This
could be a winch that should run only when manned, a folding bridge or door that open and close etc.
  Ex: <sequence name="winch_up" cmd="start" />


== ShareMemories Operation ==
The <navigate> operation is a placeholder right now and is simpler than it will be in the future. It is
(Net load: 0, CPU Load: 0)
designed to work with <locate> and it moves the NPC in a straight line to the target location found
by the <locate> operation.


Tribe operation.
  Ex: <navigate anim="walk" />


{|
The only thing the operation specifies is the animation to play while moving. It works much like
!Parameter
<moveto> but uses the locate target destination instead of a single fixed location. The only network
!Type
overhead are the Start and Stop DR messages, and the only CPU overhead is calculating how long
!Default
to sleep between starting and stopping.
!Description
|}
No parameters


This operation will share all private memories of the NPC with the tribe. Private memories is created with the [[Behavior_Operations#Memorize_Operation|Memorize Operation]]. They can be retrived by the [[Behavior_Operations#Locate_Operation|Locate Operation]] using tribe:memory:"memory name".
For more complex movement the [[Behavior_Operations#Wander_Operation|Wander Operation]] should be
used that will use the path network to navigate. Though if there are no path directly to the location
to where the NPC should go a combination of Wander and Navigate could be used. Like this example
where wander is used to navigate using waypoints and navigate is used navigate into the exact
position of the tavern.


   Ex: <share_memories />
   Ex <locate obj="tavern" static="yes" random="yes" range="800" > <!-- Locate my favorite tavern -->
    <wander />
    <navigate />


== Sit Operation ==
== NOP Operation ==
(Net load: 0, CPU Load: 0)
(Net load: 0, CPU Load: 0)  


{|
{|
Line 1,040: Line 1,107:
!Default
!Default
!Description
!Description
|-
|}
|}
No parameters.
This is a no operation operation. It does absolutely nothing, though each behavior needs to have a set of operations, if nothing else insert this nop operation.


Sit tells the npc to sit down. Use [[Behavior_Operations#Standup_Operation|standup operation]] to stand up again.
   Ex: <nop />
   Ex: <sit />


== Standup Operation ==
== Percept Operation ==
(Net load: 0, CPU Load: 0)
 
{|
!Parameter
!Type
!Default
!Description
|}
No parameters.
 
Standup tells the npc to stand up. Use [[Behavior_Operations#Sit_Operation|sit operation]] to sit down again.
  Ex: <standup />
 
== Talk Operation ==
(Net load: 0, CPU Load: 0)  
(Net load: 0, CPU Load: 0)  


Line 1,069: Line 1,122:
!Description
!Description
|-
|-
|target
|event
|boolean
|true
|Talk to current target
|-
|text
|string
|string
|
|
|The string to send
|The name of the perception event to fire. [[NPC Variables]] will be replaced.
|-
|-
|public
|target
|boolean
|self,tribe,all,target
|true
|self
|Should this talk go to everyone in range, or only the target if public=false.
|The recipient of this perception
|-
|-
|type
|type
|say,me,my,narrate
|string
|say
|(null)
|The type of talk.
|The perception type. [[NPC Variables]] will be replaced.
|-
|range
|float
|0.0
|If set to something greater than 0.0 this perception will only be delivered if within that range.
|-
|condition
|string
|
|A [[NPCClient math script]] that if set will be evaluated and any non zero return value will cause the perception event to be fired.
|-
|-
|command
|failed_event
|string
|string
|
|
|A perception to send to target if it is a NPC.
|The event to percept if the condition fail. [[NPC Variables]] will be replaced.
|-
|delayed
|float
|0.0
|The amount of time to delay before the perception is fired. [[NPC Variables]] will be replaced.
|}
|}
This operation allows an NPC to fire a custom [[Behaviors_and_Reactions#Perceptions|perception]] to himself.


If target is false, this will queue a talk command to the server from the NPC. If target is true and a target exists the same talk command will be sent to the server but a "friend:''command''" perception will be sent to the
  Ex: <percept event="done wandering" />
target as well. The target will than be able to react to this perception.
      <percept event="need help" target="tribe" range="50" />
      <percept event="GoToSleep" condition="DiurnalNight" delayed="10" />


  Ex: <talk target="true" text="Kneel in front of me." command="kneel" />
== Pickup Operation ==
      <talk type="me" text="is angry" />
      <talk target="true" text="This message is only for you" public="false" />
 
== Teleport Operation ==
(Net load: 0, CPU Load: 0)  
(Net load: 0, CPU Load: 0)  


Line 1,111: Line 1,172:
!Description
!Description
|-
|-
|obj
|string,perception
|perception
|The object to pick up. (Only perception implemented)
|-
|count
|int
|1
|Number of objects to pick up
|-
|equip
|slot
|
|name of slot to equip the item in (Not implemented)
|}
|}
This operation allows an NPC to pickup an item he finds on the ground, and optionally equip(Not implemented) it if he can use it. Only objects that are pickable will be picked up.


Teleport the NPC to the current active location.
  Ex: <pickup obj="perception" count="2" />
      <pickup obj="perception" equip="righthand" /> (Not Implemented)


  Ex: <teleport />
== Release Control Operation ==
(Net load: 0, CPU Load: 0)


== Transfer Operation ==
{|
(Net load: 0, CPU Load: 0)
 
{|
!Parameter
!Parameter
!Type
!Type
Line 1,126: Line 1,201:
!Description
!Description
|-
|-
|item
|string,tribe:wealth
|Mandatory
|The name of the item to transfer
|-
|target
|tribe
|Mandatory
|The target for this transfer.
|-
|count
|int
|-1
|Number of items to transfer. -1 is all items.
|}
|}
Release the control of a player.


Transfere a number of item from one NPC to the target.
  Ex: <release_control />


  Ex: <transfer item="tribe:wealth" target="tribe" />
== Reproduce Operation ==
 
(Net load: 0, CPU Load: 0)
This example will transfer all of the tribe wealth from the NPC to the tribe.
 
== TribeHome Operation ==
(Net load: 0, CPU Load: 0)  


Tribe operation.
Tribe operation.
Line 1,158: Line 1,216:
!Default
!Default
!Description
!Description
|-
|type
|string
|
|The tribe member type for this. [[NPC Variables]] will be replaced.
|}
|}
No Parameters.


Move the tribe home to the last active position of the NPC. This operation will issue a "tribe:home moved" perception to all members of the tribe.
The reproduce operation will spawn the target with the type given. Tribes will use this to create different types of members (See: [[Tribe_Scripting#Select|Select]] statement in [[Tribe Scripting]]).
 
  Ex: <reproduce type="Warrior" />
 
To make make a copy of your self


   Ex: <tribe_home />
   Ex: <locate obj="self" />
      <reproduce />


== TribeType Operation ==
== Resurrect Operation ==
(Net load: 0, CPU Load: 0)  
(Net load: 0, CPU Load: 0)


Tribe operation.
Tribe operation.
Line 1,175: Line 1,242:
!Default
!Default
!Description
!Description
|-
|type
|int
|0
|Change tribe member type. (Tribe Need Set)
|-
|}
|}
No Parameters.
No Parameters.


Move the tribe home to the last active position of the NPC. This operation will issue a "tribe:home moved" perception to all members of the tribe.
This operation will resurrect a tribe member within the radius of tribe home.


   Ex: <tribe_type type="1" />
   Ex: <resurrect />


== Visible Operation ==
This operation should be placed in an behavior that will be executed for dead NPCs. The reaction should
(Net load: 0, CPU Load: 0)
as well have the when_dead flag set.
  Ex: <behavior name="Resurrect" completion_decay="200" growth="0" initial="0" when_dead="yes">
        <resurrect/>
      </behavior>
      <react event="tribe:resurrect"    behavior="Resurrect"    inactive_only="yes" when_dead="yes" />
 
== Reward Operation ==
(Net load: 0, CPU Load: 0)
 
Tribe operation.


{|
{|
Line 1,196: Line 1,267:
!Default
!Default
!Description
!Description
|-
|resource
|string,tribe:wealth
|Mandatory
|The resource to reward to the tribe. [[NPC Variables]] will be replaced.
|-
|count
|int
|1
|The number of resource to reward.
|}
|}
No Parameters.


This operation makes the NPC visible if it where invisible. See [[Behavior_Operations#Invisible_Operation|Invisible Operation]].
Will reward a tribe with a resource. Using the special ''tribe:wealth'' keyword will result in a lockup in the tribe for whats the wealth resource.


   Ex: <visible />
   Ex: <reward resource="Gold Ore" count="2" />
      <reward resource="tribe:wealth" />


== Wait Operation ==
== Rotate Operation ==
(Net load: 0, CPU Load: 0)  
(Net load: 1, CPU Load: 0)


{|
{|
Line 1,212: Line 1,293:
!Description
!Description
|-
|-
|duration
|type
|See table below.
|Mandatory
|The type of rotation operation to perform.
|-
|ang_vel
|float
|float
|0.0
|0.0
|The duration to wait
|Angular velocity in degree. If 0 the NPC default angular velocity will be used.
|-
|-
|anim
|anim
|string
|string
|
|
|The animation to play while waiting.
|The animation to use for the rotation operation
|}
|-
 
|max
This operation makes the NPC wait a specified length of time before progressing to the next
|float
operation. It will loop an animation during this time also for you, so you can use it for crafting
|0.0
actions, guard monitoring, or whatever you need that is a timed animated activity.
|For inregion and random a range can be defined.
 
|-
  Ex: <wait anim="stand" duration="30" />
|min
 
|float
This example tells the NPC to play the “stand” animation and do nothing for 30 seconds. This
|0.0
requires a network DR message with the specified animation, and another to stop the animation
|For inregion and radom a range can be defined.
when the duration is over. There is almost no CPU required because the script goes to sleep for the
|-
duration and is woken up automatically at the end.
|value
 
|float
As with any other scripted operation, this operation can be interrupted if another behavior preempts
|0.0
this one from completing. So if an npc is playing the above operation, and just standing there for
|For absolute and relative a value to add in degrees should be given.
30 seconds, and is attacked by someone, presumably an attack behavior would become top priority
|}
and the npc would stop waiting and attack back.
 
This concludes the section on the detailed operations possible with npc scripting today. Now we
will discuss how these operations work together to define behaviors and how behaviors interact
with each other.
 
== Wander Operation ==
(Net load: 2, CPU Load 1)


{|
{|
!Parameter
!Type
!Type
!Default
!Description
!Description
|-
|-
|anim
|inregion
|string
|
|
|The animation to play while wandering.
|-
|-
|vel
|random
|float
|
|
|-
|absolute
|
|
|-
|-
|random
|relative
|boolean
|
|false
|Turn on never ending random wandering.
|-
|-
|underground
|locatedest
|boolean
|Face in the direciton of the last located position.
|invalid
|If not set ignore underground, set true only wander underground, if set false never wander underground waypoints
|-
|-
|underwater
|locaterotation
|boolean
|Face in the direction of the last located rotation angle.
|invalid
|If not set ignore underwater, set true only wander underwater, if set false never wander underwater waypoints
|-
|-
|private
|target
|boolean
|
|invalid
|If not set ignore private, set true only wander private, if set false never wander private waypoints
|-
|-
|public
|boolean
|invalid
|If not set ignore public, set true only wander public, if set false never wander public waypoints.
|-
|city
|boolean
|invalid
|If not set ignore city, set true only wander city, if set false never wander city waypoints.
|-
|indoor
|boolean
|invalid
|If not set ignore indoor, set true only wander indoor, set false never wander indoor waypoints.
|}
|}


Using random <move> and <rotate> operations works well for creating randomized wandering
This operation <rotate> can be used to turn to a certain angle, to turn a relative amount, to turn a
behaviors in open, outdoor spaces and scripters should be using that approach there. However, in tighter, indoor areas like the hydlaa sewers or the dungeon, a more specific type of randomness is required.
random amount or to turn to face a previously located object. This turn is animated, to give a more
realistic look.
 
  Ex: <rotate type="random" min="90" max="270" anim="walk" vel="30" />
      <rotate type="locatedest" anim="walk" vel="90" />


The <wander> operation makes the npc in question walk between an independently defined set of
The first example here is a random turn of between 90 and 270 degrees from the current heading,
“waypoints”. Each waypoint is a 3d coordinate and a tolerance radius. The radius adds a ‘fuzzy’
with an angular velocity of 30 degrees per second, while playing the “walk” animation. 30 degrees
factor so that multiple npcs sharing the same set of waypoints will not all walk to the exact same
per second means that the maximum turn of 270 degrees will take the npc 9 seconds.
centimeter location. Even in tight locations, a tolerance radius of .5-1m will be a lot better than 0m. Waypoints will be created with the path system available as GM commands.


  Ex: <wander anim="walk" />
In the second example, we have already used our <locate> operation to find a point of interest near
us, and we want to turn to point directly at it. Here a different (faster) angular velocity is specified
but other angles aren’t necessary because they are implied by the current position of the NPC and
the located special destination.


As you see, the only thing specified by the wander operation is the animation to play while
This operation requires a DR update to start and stop the rotation, as the only networking overhead.
wandering. The NPC starts by walking to the nearest waypoint to its current location, then follows
CPU overhead is also minimal since npcclient calculates the time required to turn the full amount
the waypoint choices to decide where to go next. This operation will take the NPC to the current active
and puts this script to sleep for that many msec until the turn is done, then stops it.
waypoint as selected by the last [[Behavior_Operations#Locate_Operation|Locate Operation]].


Each waypoint have a set off properties. It can be marked as indoor,underground,underwater,private,public, or city.
== Script Operation ==
If the wander operations in specified with the indoor flag set to true only waypoints with the indoor attribute set to true will be used when wandering. Changing
(Net load: 0, CPU Load: 0)
waypoint attributes can be done by the GM command /path (TBD, Not impemented yet, has to be done in DB for now).'


Each waypoint is connected with a [[Sc_waypoint_linksTable|path]]. The path has a set of properites like TELEPORT, NO_WANDER, ONEWAY.
{|
 
!Parameter
This operation is very light on the network because it is all straight-line navigation between known,
!Type
preset points. There is 1 DR update per point hit by the npc. It is also quite light on CPU power
!Default
requirements because the points are known, which means no collision detection has to be done.
!Description
|-
|name
|string
|Mandatory
|The name of the script
|}


One tricky thing about this is that normally non-horizontal walking is accomplished on the client
Run a [[ProgressionEvents|Progression Event]] script. Target and Actor env is set for the script at the server.
with collision detection with the ground/stairs. In order to get the most accurate-looking result on
  Ex: <script name="my_script" />
the client, the client DOES do collision detection on these npcs. However, npcclient does simple
linear interpolation between the starting and ending y-coordinates of the 2 waypoints as an
approximation. Thus the server and client will not have the identical y-coordinate in all cases. This
should almost never be noticeable, though.


== Watch Operation ==
== Sequence Operation ==
(Net load: 0, CPU Load: 0)  
(Net load: 0, CPU Load: 0)


{|
{|
Line 1,339: Line 1,398:
!Description
!Description
|-
|-
|type
|name
|nearest_actor,nearest_npc,nearest_player,owner,target
|string
|Mandatory
|Mandatory
|The type of watch to do.
|The name of the sequence to control
|-
|cmd
|start,stop,loop
|Mandatory
|The control of the sequence to issue.
|-
|count
|int
|1
|The number of times to loop the sequence.
|}
 
Sequences are defined in the map file. They can be started, stopped, or played a number of time with the loop command. This allow the NPC to interact with large animation of world objects. This
could be a winch that should run only when manned, a folding bridge or door that open and close etc.
  Ex: <sequence name="winch_up" cmd="start" />
 
== Set Buffer Operation ==
(Net load: 0, CPU Load: 0)
 
{|
!Parameter
!Type
!Default
!Description
|-
|buffer
|string
|Mandatory
|The name of the buffer.
|-
|value
|string
|Mandatory
|The value to set for the buffer.
|-
|type
|npc,tribe
|npc
|The type of buffer to set.
|}
 
Set either a NPC or a Tribe buffer. [[NPC Variables]] $NBUFFER[Buffer] (NPC Buffer) and $TBUFFER[Buffer] (Tribe Buffer) are replaced multiple places with the value of the buffer.
 
  Ex: <set_buffer buffer="Building" value="Small Tent" />
 
== Share Memories Operation ==
(Net load: 0, CPU Load: 0)
 
Tribe operation.
 
{|
!Parameter
!Type
!Default
!Description
|}
No parameters
 
This operation will share all private memories of the NPC with the tribe. Private memories is created with the [[Behavior_Operations#Memorize_Operation|Memorize Operation]]. They can be retrived by the [[Behavior_Operations#Locate_Operation|Locate Operation]] using tribe:memory:"memory name". Memories can also be crated using the [[Behavior_Operations#Auto_Memorize_Operation|Auto Memorize Operation]].
 
  Ex: <share_memories />
 
== Sit Operation ==
(Net load: 0, CPU Load: 0)
 
{|
!Parameter
!Type
!Default
!Description
|}
No parameters.
 
Sit tells the npc to sit down. Use [[Behavior_Operations#Standup_Operation|standup operation]] to stand up again.
  Ex: <sit />
 
== Sound Operation ==
(Net load: 0, CPU Load: 0)
 
{|
!Parameter
!Type
!Default
!Description
|-
!name
!String
!
!the sound to play, references dt_sound datatable
|-
!loop
!boolean
!
!NOT WORKING YET. Should loop the sound.
|}
 
 
Will play a sound at the location of the NPC.
  Ex: <sound name="mandolin1_song" loop="yes" />
 
== Standup Operation ==
(Net load: 0, CPU Load: 0)
 
{|
!Parameter
!Type
!Default
!Description
|}
No parameters.
 
Standup tells the npc to stand up. Use [[Behavior_Operations#Sit_Operation|sit operation]] to sit down again.
  Ex: <standup />
 
== Talk Operation ==
(Net load: 0, CPU Load: 0)
 
{|
!Parameter
!Type
!Default
!Description
|-
|target
|boolean
|true
|Talk to current target
|-
|text
|string
|
|The string to send
|-
|public
|boolean
|true
|Should this talk go to everyone in range, or only the target if public=false.
|-
|type
|say,me,my,narrate
|say
|The type of talk.
|-
|command
|string
|
|A perception to send to target if it is a NPC. [[NPC Variables]] will be replaced.
|}
 
If target is false, this will queue a talk command to the server from the NPC. If target is true and a target exists the same talk command will be sent to the server but a "''command''" perception will be sent to the
target as well. The target will than be able to react to this perception.
 
  Ex: <talk target="true" text="Kneel in front of me." command="kneel" />
      <talk type="me" text="is angry" />
      <talk target="true" text="This message is only for you" public="false" />
 
== Teleport Operation ==
(Net load: 0, CPU Load: 0)
 
{|
!Parameter
!Type
!Default
!Description
|-
|}
 
Teleport the NPC to the current active location.
 
  Ex: <teleport />
 
== Transfer Operation ==
(Net load: 0, CPU Load: 0)
 
{|
!Parameter
!Type
!Default
!Description
|-
|item
|string,tribe:wealth
|Mandatory
|The name of the item to transfer. [[NPC Variables]] will be replaced.
|-
|target
|tribe
|Mandatory
|The target for this transfer.
|-
|count
|int
|-1
|Number of items to transfer. -1 is all items.
|}
 
Transfere a number of item from one NPC to the target.
 
  Ex: <transfer item="tribe:wealth" target="tribe" />
 
This example will transfer all of the tribe wealth from the NPC to the tribe.
 
== Tribe Home Operation ==
(Net load: 0, CPU Load: 0)
 
Tribe operation.
 
{|
!Parameter
!Type
!Default
!Description
|}
No Parameters.
 
Move the tribe home to the last active position of the NPC. This operation will issue a "tribe:home moved" perception to all members of the tribe.
 
  Ex: <tribe_home />
 
== Tribe Type Operation ==
(Net load: 0, CPU Load: 0)
 
Tribe operation.
 
{|
!Parameter
!Type
!Default
!Description
|-
|type
|string
|
|Change tribe member type.
|-
|}
No Parameters.
 
Change the Tribe Member type of the current NPC to the new type.
 
  Ex: <tribe_type type="Queen" />
 
== Unbuild Operation ==
(Net load: 0, CPU Load: 0)
 
Tribe operation.
 
{|
!Parameter
!Type
!Default
!Description
|-
|}
 
Unbuild a building. The building has to be targeted.
 
  Ex: <unbild />
 
== Visible Operation ==
(Net load: 0, CPU Load: 0)
 
{|
!Parameter
!Type
!Default
!Description
|}
No Parameters.
 
This operation makes the NPC visible if it where invisible. See [[Behavior_Operations#Invisible_Operation|Invisible Operation]].
 
  Ex: <visible />
 
== Wait Operation ==
(Net load: 0, CPU Load: 0)
 
{|
!Parameter
!Type
!Default
!Description
|-
|duration
|float
|Mandatory
|The duration to wait.  [[NPC Variables]] will be replaced.
|-
|random
|float
|0.0
|The random duration to wait.  [[NPC Variables]] will be replaced.
|-
|anim
|string
|
|The animation to play while waiting.
|}
 
This operation makes the NPC wait a specified length of time before progressing to the next
operation. It will loop an animation during this time also for you, so you can use it for crafting
actions, guard monitoring, or whatever you need that is a timed animated activity.
 
  Ex: <wait duration="30" anim="stand" />
      <wait duration="$NBUFFER[Sit_Duration]" anim="sit" />
 
This example tells the NPC to play the “stand” animation and do nothing for 30 seconds. This
requires a network DR message with the specified animation, and another to stop the animation
when the duration is over. There is almost no CPU required because the script goes to sleep for the
duration and is woken up automatically at the end.
 
As with any other scripted operation, this operation can be interrupted if another behavior preempts
this one from completing. So if an npc is playing the above operation, and just standing there for
30 seconds, and is attacked by someone, presumably an attack behavior would become top priority
and the npc would stop waiting and attack back.
 
This concludes the section on the detailed operations possible with npc scripting today. Now we
will discuss how these operations work together to define behaviors and how behaviors interact
with each other.
 
== Wander Operation ==
(Net load: 2, CPU Load 1)
 
{|
!Parameter
!Type
!Default
!Description
|-
|anim
|string
|
|The animation to play while wandering.
|-
|vel
|float
|
|
|-
|random
|boolean
|false
|Turn on never ending random wandering.
|-
|underground
|boolean
|invalid
|If not set ignore underground, set true only wander underground, if set false never wander underground waypoints
|-
|underwater
|boolean
|invalid
|If not set ignore underwater, set true only wander underwater, if set false never wander underwater waypoints
|-
|private
|boolean
|invalid
|If not set ignore private, set true only wander private, if set false never wander private waypoints
|-
|public
|boolean
|invalid
|If not set ignore public, set true only wander public, if set false never wander public waypoints.
|-
|city
|boolean
|invalid
|If not set ignore city, set true only wander city, if set false never wander city waypoints.
|-
|indoor
|boolean
|invalid
|If not set ignore indoor, set true only wander indoor, set false never wander indoor waypoints.
|}
 
Using random <move> and <rotate> operations works well for creating randomized wandering
behaviors in open, outdoor spaces and scripters should be using that approach there. However, in tighter, indoor areas like the hydlaa sewers or the dungeon, a more specific type of randomness is required.
 
The <wander> operation makes the npc in question walk between an independently defined set of
“waypoints”. Each waypoint is a 3d coordinate and a tolerance radius. The radius adds a ‘fuzzy’
factor so that multiple npcs sharing the same set of waypoints will not all walk to the exact same
centimeter location. Even in tight locations, a tolerance radius of .5-1m will be a lot better than 0m. Waypoints will be created with the path system available as GM commands.
 
  Ex: <wander anim="walk" />
 
As you see, the only thing specified by the wander operation is the animation to play while
wandering. The NPC starts by walking to the nearest waypoint to its current location, then follows
the waypoint choices to decide where to go next. This operation will take the NPC to the current active
waypoint as selected by the last [[Behavior_Operations#Locate_Operation|Locate Operation]].
 
Each waypoint have a set off properties. It can be marked as indoor,underground,underwater,private,public, or city.
If the wander operations in specified with the indoor flag set to true only waypoints with the indoor attribute set to true will be used when wandering. Changing
waypoint attributes can be done by the GM command /path (TBD, Not impemented yet, has to be done in DB for now).'
 
Each waypoint is connected with a [[Sc_waypoint_linksTable|path]]. The path has a set of properites like TELEPORT, NO_WANDER, ONEWAY.
 
This operation is very light on the network because it is all straight-line navigation between known,
preset points. There is 1 DR update per point hit by the npc. It is also quite light on CPU power
requirements because the points are known, which means no collision detection has to be done.
 
One tricky thing about this is that normally non-horizontal walking is accomplished on the client
with collision detection with the ground/stairs. In order to get the most accurate-looking result on
the client, the client DOES do collision detection on these npcs. However, npcclient does simple
linear interpolation between the starting and ending y-coordinates of the 2 waypoints as an
approximation. Thus the server and client will not have the identical y-coordinate in all cases. This
should almost never be noticeable, though.
 
== Watch Operation ==
(Net load: 0, CPU Load: 0)
 
{|
!Parameter
!Type
!Default
!Description
|-
|type
|nearest_actor,nearest_npc,nearest_player,owner,target
|Mandatory
|The type of watch to do.
|-
|-
|range
|range
|float
|float
|0.0
|0.0
|The watch range. A perception will be generated when watched entity move out of range.
|The watch range. A perception will be generated when watched entity move out of range.
|-
|-
|invisible
|invisible
|boolean
|boolean
|false
|false
|Set to true to watch invisible entities.
|Set to true to watch invisible entities.
|-
|-
|invincible
|invincible
|boolean
|boolean
|false
|false
|Set to true to watch invincible entities.
|Set to true to watch invincible entities.
|-
|-
|search_range
|search_range
|float
|float
|2.0
|2.0
|When watching nearest, this range set the limit for how fare that entity can be.
|When watching nearest, this range set the limit for how fare that entity can be.
|}
|}
 
Watch over nearby entities. The "nearest out of range","owner out of range", or "target out of range" perception will be generated when the watched entity move out of range.
 
  Ex: <behavior name="Watch">
        <watch type="owner" range="3.0" />
      </behavior>
      <react event="owner out of range"  behavior="follow_chase"  />
 
In this example the NPC will watch the owner. If the owner move out of the watch range 3.0 the "owner out of range" perception will be fired and the new follow_chase behavior will start.
 
== Work Operation ==
(Net load: 0, CPU Load: 0)
 
{|
!Parameter
!Type
!Default
!Description
|-
|type
|dig,fish,harvest
|Mandatory
|The type of work to do
|-
|resource
|string,tribe:wealth
|Mandatory
|Resource to work for or by using the keyword tribe:wealth look up in the tribe to find the resource.
|}
 
Order an NPC to start digging for a resource. The keyword "tribe:wealth" will cause the resource to be looked up in the wealth_resource_nic field in the [[NPC_Behavior_Data_Structures#tribes|tribes]] table if the NPC is part of a tribe.


Watch over nearby entities. The "nearest out of range","owner out of range", or "target out of range" perception will be generated when the watched entity move out of range.
  Ex: <work type="dig" resource="tribe:wealth" />
      <work type="dig" resource="Gold Ore" />


  Ex: <behavior name="Watch">
        <watch type="owner" range="3.0" />
      </behavior>
      <react event="owner out of range"  behavior="follow_chase"  />
In this example the NPC will watch the owner. If the owner move out of the watch range 3.0 the "owner out of range" perception will be fired and the new follow_chase behavior will start.




[[Category:Engine documents]]
[[Category:Engine documents]] [[Category:NPCClient Design]] [[Category:NPCClient Scripting]]

Latest revision as of 22:03, 19 July 2022

A “Behavior” in NPCClient is a script defined in the database (see npcbehave.xml) to run to make the npc behave a certain way. It is almost like a state, for AI designers used to state machine npcs. Example behaviors might include “guard patrol”, “wander in forest”, “fight attackers”, “smith an item”. Before we talk about how everything fits together we will go over what is possible in npcclient with these detailed behavior scripts. The following is a list and reference description of each behavior script operation or command you can use. They are put together in sequences called beaviors as will be described later in Behaviors_and_Reactions.


Assess Operation

(Net load: 1, CPU Load 1)

Parameter Type Default Description
physical string The prefix for the physical perception.
magical string The prefix for the magical perception.
overall string The perfix for the overall perception.

Each of the physical, magical, or overall will be assessed as; "extremely weaker", "much weaker", "weaker", "equal", "stronger", "much stronger" or "extremely stronger".


 Ex: <assess overall="$target overall" />

Typical reaction to catch the response to this would be as shown in the example below. $target is used here to make sure the correct assessment is matched to the same target. A npc will not react if the target has changed before the response is received.

 Ex: <react event="assess equal" type="$target overall" .../>
     <react event="assess weaker" type="$target overall" .../>

Auto Memorize Operation

(Net load: 1, CPU Load 1)

Parameter Type Default Description
types string Comma separated list of types. "all", can be used to memorize everything to all.
enable bool true Enables or disables the types.

Auto memorize is a way to turn on and off memorizing of perception. This will be memorize without actually needing to react to thees. Related to the Share Memories Operation and Memorize Operation.

 Ex: <auto_memorize types="all" />
     <auto_memorize types="Hunting Ground,Marked" />
     <auto_memorize types="Marked" enable="false" />
 

You can use a reaction without a behavior lists to enable the NPC to receive perceptions to be memorized if enabled.

 Ex: <react type="location sensed" />

Build Operation

(Net load: 1, CPU Load 1)

Parameter Type Default Description
pickupable boolean false If false the building deployed will not be pickupable by the players

Build a building as specified bye the NPC's current held building spot as set by the Tribe Scripting locateBuildingSpot function.


 Ex: <build />

Busy Operation

(Net load: 1, CPU Load 1)

Parameter Type Default Description

Mark a NPC as busy. This will cancle the Idle Operation


 Ex: <busy />

Cast Operation

(Net load: 1, CPU Load 1)

Parameter Type Default Description
spell string The name of the spell to cast.
k float 1.0 The kFactor to use when casting the spell.

Cast a spell on the current selected target.

 Ex: <cast spell="Flame Strike" k="3.0" />

Change Brain Operation

(Net load: 1, CPU Load 1)

Parameter Type Default Description
brain string The name of the brain to load.
brain reload Reload the standard NPC brain stored in the sc_npc_definition table.

Change the brain of the current selected target.

 Ex: <change_brain brain="Charmed" />

Chase Operation

(Net load: 3, CPU Load 3)

Parameter Type Default Description
anim string The animation to use for the chase.
adaptiv_vel_script string A NPCClient math script used to adjust the adaptivVelocityScale. Additional variables defined for this script is "Distance" to the target of the chase and "AdaptivVelScale" that is the value used to adjust velocity. 1.1 will increase the velocity by 10%.
type nearest_actor, nearest_npc, nearest_player, owner, target nearest_* is the nearest entity of that type. target is current target.
range float 2.0 The range to search for target of the chase.
chase_range float -1 The range at where the chase should give up and issue a "<target> out of chase" perception. -1 is default to disable the max range check.
offset float 0.5 The distance to stop before the target of the chase. NPC Variables will be replaced. Expressions will be resolved. See Offset for more details.
offset_angle float 0.0 Size of the arc used to distribute the chase when approaching the target. The angle is in degrees.
offset_relative_heading bool false Make the offset relative to the target heading. NPC Variables will be replaced. See Offset for more details.
vel float,$WALK,$RUN Default is to use the velocity from the behavior. The velocity to use when chasing.
ang_vel float 0 is to use the default from the behavior.
collision string collision The name of the perception to be used when a collision perception is to be fired.
out_of_bounds string out of bounds The name of the perception to be used when a out of bounds perception is to be fired.
in_bounds string in bounds The name of the perception to be used when a in bound perception is to be fired.


Chasing a player is one example where both turning and moving at the same time are required to give a realistic effect to the behavior. We have <move> and <rotate> but this one does them together and intelligently to follow a targeted player or entity. Normally, this will be used to get npc’s to chase after players if players run away during a fight.

 Ex: <chase type="target" anim="walk" range=”2” />

In this example, the npc will play the animation called “walk” while moving and turning as appropriate to reduce his range to his most hated enemy. Of course, he is limited by his speed and if the player can run faster than he can chase, he will never catch the player. An "<target> out of chase" perception will be fired in this case.

The “type” attribute of the operation can be either “enemy” as shown here, “owner” to follow the NPC’s owner around, or “nearest” to chase after the nearest player at the time the operation was initiated. This operation will continue until interrupted by another behavior or until the distance to the target from the npc is less than the range specified. (2 is the default if no range is specified.) This operation sends DR messages whenever it turns or changes course, plus the DR messages to start the forward motion and animation, and to stop them. The CPU load is somewhat heavy because CD must be performed as the npc is chasing, since his path is not predetermined.

Circle Operation

(Net load: 3, CPU Load: 2)

Parameter Type Default Description
anim string The animation to use for the operation.
radius float Mandatory, no default value Radius to move NPC around with.
angle float 2PI The angle to move. Calculated if 0 and duration not 0.
duration float 0 The duration to move in circle. Calculated if 0.
ang_vel float The angular velocity to use when moving in the circle. Calculated if 0.


Moving the NPC around in a circle. The following example will move the npc around using the velocity defined in the behavior in one complete circle in 10 sec.

 Ex: <circle anim="walk" radius=”2” duration="10" />

Control Operation

(Net load: 3, CPU Load: 2)

Parameter Type Default Description


Take control of an player an move with the player.

 Ex: <control />

Copy_Locate Operation

(Net load: 0, CPU Load: 1)

Parameter Type Default Description
source string Mandatory, no default value The source locate to copy from.
destination float Mandatory, no default value The destination locate to copy to.


Copy one locate from source to destination. Built in function like Wander and Navigate use the Active locate.

 Ex: <locate obj="some thing" destination="SpecialPlace" />
     <copy_locate source="SpecialPlace" destination="Active" />

Debug Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
level int Mandatory The level of debug to turn on for current NPC.
exclusive string Will set on exclusive logging for this NPC.

Turn on and of debug printouts on the server console. Used for debuging of script operations. Level 1-4 Only the biggest events, 5-9 Medium number of events, 10-15 and more is maximum output.

 Ex: <debug level=”2” />

Dequip Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
slot string Mandatory The slot to dequip an move back into inventory.

Dequip an item held by the NPC in the given slot.

 Ex: <dequip slot="righthand" />

Drop Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
slot string Mandatory The slot from which the item is to be dropped.

This operation allows an NPC to drop an item he has in inventory on the ground.

 Ex: <drop slot="lefthand" />

Eat Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
resource string,tribe:wealth Mandatory The resource to reward the tribe when eating.

Simple simulation that the tribe would gain things like flesh from eating at a dead entity withing a range of 1.0. The tribe wealth resource would be read from the wealt_resource_name field in the tribes table.

 Ex: <eat resource="tribe:wealth" />
     <eat resource="Flesh" />

Emote Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
cmd string The emote cmd to be used as defined in the emote.xml file. Including leading /.

This operation allows an NPC to do an emotion.

 Ex: <emote cmd="/greet" />

Equip Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
item string Mandatory The name of the item to equip
slot string Mandatory The sloot to dquip the item in
count int 1 The number of items to equip. Will be forced to at least 1.

Equip one item from inventory into the given slot.

 Ex: <equip item="Sword" slot="righthand" count="1" />

Hate List Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
delta float Add delta to hate list.
absolute float Set the hate value.
max float Hate should have a max value
min float Hate should have a min value
perception bool false Use perception instead of target to find target.

Adjust the hate list for an npc. The current target or perception target is the target entry for the adjustment.

 Ex: <hate_list delta="0.5" max="10.0" />
 Ex: <locate obj="perception" />
     <hate_list absolute="5.0" />
 
     Is equvivalent with:
 
     <hate_list perception="yes" absolute="5.0" />

Idle Operation

(Net load: 1, CPU Load 1)

Parameter Type Default Description

Mark a NPC as idle. This operation cancle the Busy operation.


 Ex: <idle />

Invisible Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description

No parameters.

This operation makes the NPC invisible through the toggle visibility command. See Visible Operation.

 Ex: <invisible />

Locate Operation

(Net load: 0, CPU Load 0)

Parameter Type Default Description
obj See table below. Mandatory The object to locate. NPC Variables will be replaced.
failure string A perception to fire if fails to locate the given obj.
static boolean false For location the search could be made static. Se description for more details.
range float -1 The maximum range to locate within. -1 represents infinite.
random boolean false If true a random return within the radius will be made. Otherwise the nearest entry will be returned.
outside_region boolean false Set this to true if the locate operation should consider entities outside region as well if a region is defined. NPC Variables will be replaced.
invisible boolean false Set this to true if the locate operation should consider invisible objects
invincible boolean false Set this to true if the locate operation should consider invincible objects.
destination string Active Set the destination NPC locate location. NPC Variables will be replaced.

Obj can be one of the following:

obj Description
<string> Locate a location. This is the default if none of the following obj types is matched.
actor Located nearest actor
building_spot Locate a building spot from the npc's building spot.
dead Nearest dead actor
entity:name:<name> Entity with given name
entity:pid:<pid> Entity with given pid
friend Nearest visible friend (NPC)
local_region Locate region in current sector.
ownbuffer Locate the own buffer.
owner Locate the owner, if this NPC is owned (Pets and stuff)
perception The location of the last received perception.
player Nearest player
point Random point
region Locate a random point within the region of the NPC.
self Locate your self
spawn Spawn location of the npc.
target Locate a target. The target will be the most hated from the NPC hate list.
tribe:home Locate the npcs tribe home place.
tribe:memory:string Locate something from the Tribes memory. See the ShareMemories and Memorize operation.
tribe:resource Locate a resource location from the memory of the tribe.
tribe:target Locate the most hated target for this tribe. The target will be the most hated from all the NPCs hate list in the tribe.
waypoint Will locate a waypoint.
waypoint:group:string Locate a waypoint from a given group
waypoint:name:string Locate a waypoint by name.

This operation is one of the more flexible and crucial operations in npc scripting. It allows the scripter to have his npc “find” a certain thing or type of thing, and remember that location for other scripting commands later such as turning, moving or attacking. The operation will store the position found in the NPCs as active postion and calcualte the neares waypoint and store that in the active_waypoint. For location it is possible to make the first search a static search. So that the first time the npc do this operation it could search for a "Baker" location. The next time the operation is used it will use the results of the first time even if there might be Bakers closer at that time.

 Ex: <locate obj="perception" />
     <locate obj="target" />
     <locate obj="furnace" range="50" />
     <locate obj="waypoint" failure="no waypoint found" />

Example 1 finds the last perception received by the current npc and sets the active target location to the location of that perception. This allows npcs who receive “Talk” perceptions to turn to face the person talking to them. It allows npcs who have a spell cast on them to turn to face the caster, and so on.

Example 2 finds the location of the currently active “enemy” of the NPC, which is the entity with the highest score on the NPC’s hate list, and sets that location as the active target location for other operations. This allows NPCs to turn to face the person they are attacking, chase attackers who are retreating, etc.

Example 3 uses predefined lists of named location types to find the closest one to the npc and sets the active target location to the coordinates specified there. This is the most subtle of the 3, and in some ways the most powerful so it deserves more discussion. Consider the following pictures:

npc_pic1.png

Here we have two blacksmith shops with similar items but different layouts. They might be side by side or they might be in entirely different cities. LocTypes specify a list of Anvil locations, or a list of Furnace locations, as marked by the stars on these pictures. When Example 3 says to locate the nearest furnace, an NPC in smithy #1 will find his furnace while the NPC in smithy #2 will find his own furnace. They will be able to share one script for moving between these points and acting like a real blacksmith in their own location, even though they are in totally different smithy shops.

This will become even more important when we implement player housing and player shops. It will be possible with the scripts we have already today for a player to build the blacksmith shop of his own design and for him to hire an npc smith to come work in that shop. The Smith NPC he hired will be able to “know” how to get around the player’s shop magically.

Something intended to be supported here but not actually implemented yet was the ability to locate named objects or entities as well, so an NPC could locate a sword someone dropped on the ground and things like this. Better integration with the entity system and perhaps integration with data from the maps themselves rather than externally generated lists of points could make this even more powerful.

The Locate Operation does NOT move the NPC.

To have the NPC move you need to have a navigate or move operation after, this can be done with subsequent

  <locate obj="something" destination="Move" />
  <navigate  />

If you want to trigger a separate behaviour you can use a perception (this is the actual version we use in PlaneShift, using the Move Behaviour)

  <locate obj="something" destination="Move" />
  <percept event="move" />

Loop Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
iterations int 0 Number of iterations to do in this loop. No iterations attribute or a value of -1 is loop forever.

This operation allows you to loop a section of your script a certain number of times. This is mostly useful for city npcs such as smiths and tavern barkeeps. Behaviors in general will loop if not replaced by another behavior, but if you want subloops within the script, this is an easy way to do it.

Ex:

 <loop iterations="20">
   <locate obj="fire" range="10" />
   <navigate anim="walk" />
   <wait anim="stand" duration="30" />
   <locate obj="anvil" range="10" />
   <navigate anim="walk" />
   <wait anim="hammer" duration="20" />
 </loop>

In this example, the blacksmith is scripted to walk back and forth between his fire and his anvil 20 times before moving on to the next operation in his script to act like a blacksmith.

This operation does not affect the network at all and does not have CPU overhead.

Melee Operation

(Net load: 1, CPU Load: 2)

Parameter Type Default Description
seek_range float 0.0 The range to search for new targets in melee
melee_range float[0.5-3.0] 3.0 The range where melee can be done. Max 3.0 to prevent npc/server conflicts.
attack_type string default The name of a special attack defined in the 'attacks' table. If this attribute is not set an ordinary attack will be queued. NPC Variables will be replaced.
stance string normal The stance to use when attacking. NPC Variables will be replaced.
tribe boolean false When set to true the tribe hate list will be used to select target. If true and NPC not member of a tribe the NPC hate list will be used as a fall back. NPC Variables will be replaced.
outside_region boolean false Set to true to fight even outside region if a region is defined. NPC Variables will be replaced.
invisible boolean false Will melee operation fight invisible entities
invincible boolean false Will melee operation fight invincible entities.

The <melee> operation handles starting and ending fights for the NPC. It finds the most hated enemy in range and tells the server to attack him. If there is no enemy in range, it finds the nearest enemy that it does hate and prepares to chase him.

 Ex: <melee seek_range="10" melee_range="3" />

The “melee_range” attribute specifies how far away the enemies can be while still fighting without the npc needing to move. 3 meters is the maximum of how far away a player can be to hit the npc also, so in most cases this is a good value. The “seek_range” specifies how far around himself the npc should look for other enemies if none are found within the melee_range. If there are no enemies within the seek_range, the npc starts to calm down and his current behavior (making his ‘melee’ operation active) is lowered in priority. If an enemy is found within the seek_range, the NPC’s active enemy is set to this found person so the <chase type=”enemy”> operation can run after him.

This operation’s only network load is informing the server of its melee target and attack mode, and switching these occasionally as people die, etc. The CPU load is in periodically (2x per second) checking the hate list for the NPC to make sure the most hated person is being fought. If no one on the hate list is within the melee range, a more expensive operation is done to find any hated people within the seek_range, but this operation isn’t performed very often.

See the NPC hate list for further details about the hate list.

Memorize Operation

(Net load: 0, CPU Load: 0)

Tribe operation.

Parameter Type Default Description

No Parameters.

This is an operation that only will have effect for tribe members. The NPC will memorize the current perception as a private memory. See the Share Memories Operation for how to make the memories known to other members of the tribe.

 Ex: <memorize />

Move Operation

(Net load: 0, CPU Load: 5)

Parameter Type Default Description
anim string The animation to use when moving.
duration float 0.0 The duration this move should have. The default is probably no good.
vel float,$WALK,$RUN Default is to use the velocity from the behavior. The velocity to use when moving.
ang_vel float 0.0 By defining a ang_vel the movement will be much like the Circle Operation.
collision string collision The name of the perception to be used when a collision perception is to be fired.
out_of_bounds string out of bounds The name of the perception to be used when a out of bounds perception is to be fired.
in_bounds string in bounds The name of the perception to be used when a in bound perception is to be fired.

The most basic behavior operation in npcclient is <move>. It simply tells the npc to move forward at a certain speed in the direction he is currently pointing, and to play a named animation while doing so.

 Ex: <move vel="1" anim="walk" />
     <move anim="walk" vel="$WALK" out_of_bounds="move_outside_region" />

This operation has no preset end or duration, so it will go until the behavior is preempted by another higher priority behavior such as the one to turn, triggered by a collision perception. (See the next section for a more detailed explanation of how behaviors pre-empt each other and change priorities.)

This operation has low networking overhead since all it does is trigger a single Dead Reckoning (DR) update to start the forward motion. It does have CPU overhead during the entire duration of it running though, since there is no way for npcclient to know what it might hit along this path. Every 500msec this operation wakes up and checks its latest movement for collisions, generating a perception called “collision” for the behavior script to react to. Also at each 500msec checkpoint, it checks the owner NPC’s region setting (such as “sunny meadow” in the example above), and if there is a region specifed, the operation checks its current position to make sure the NPC is still “in bounds”. If the NPC has made it outside the region in the last half second, it fires a perception called “out of bounds”. It will not fire another “out of bounds” perception until an “in bounds” perception has been detected.

MovePath Operation

(Net load: 2, CPU Load: 3)

Parameter Type Default Description
path string Mandatory The name of the path to use for the movement.
anim string The name of the animation to use for this movement
direction FORWARD,REVERSE FORWARD The direction to move along the path

This operation tell the NPC to move in a predefined path. The path is a named entity in the path network. From a start waypoint to and end waypoint with any number of path points in between. The path will either be followed in the forward or reverse direction. Upon start of this the npc will be forced to the start position of the path. The following example will move the NPC the reverse path to the clock tower.

 Ex: <movepath path="Clock Tower" direction="REVERSE" />
 Ex: <behavior "Ring the Clock">
       <movepath path="Clock Tower" />
       <wait anim="Ring the Clock" />
       <movepath path="Clock Tower" direction="REVERSE" />
     </behavior>

Current implementation will extrapolate on the server and send updates to the client.

The following old description isn't quite in line with current implementation. Sure it should be possible to send the path to the client and do the math there. Suggest to include that as a option to the current implementation. With today implementation the movement could be interrupted and it will stop when finished with the path. To get the looping behavior either the behavior should be set to looping or a loop should be created.

--Start old description:

This operation is another very easy one: <movepath>. It tells the npc to set its preset path to a 3d spline specified in another file by name. Each client will take care of playing the right animations along the spline as the npc progresses. The intent of this operation was really simply for birds to be able to fly through the air as decoration rather than any gameplay reason. Aside from birds, most creatures do not follow 3d spline paths in their normal behaviors.

 Ex: <movepath path="bird1" />

This operation has no present end or duration, and will actually loop if not stopped by another behavior.

This operation has almost no network overhead, as the packed bytes of the spline are sent 1 time across the network to anyone needing to see this npc, and no other network activity happens until the <movepath> operation is interrupted.

This operation also has almost zero CPU overhead, because there is no collision detection and no bounds checking on this type of movement. The reasoning is that since predefined paths are being followed, it is up to the designer/scripter to ensure that the path goes where they want it to and does not hit anything along the way.

--End old description

MoveTo Operation

(Net load: 0, CPU Load: 3)

Parameter Type Default Description
x float 0.0 X-coordinate to move to
y float 0.0 Y-coordinate to move to
z float 0.0 Z-coordinate to move to
vel float,$WALK,$RUN Default is to use the velocity from the behavior. The velocity to use when moving.
anim string The name of the animation to use

This operation tells the npc to turn and face a certain point in 3d space, then move in a straight line to that location at a certain speed. The turn is not animated, so if you want an animated turn, you need a <rotate> op in front of this (see below). <moveto> also specifies an animation name to play while performing this move.

 Ex: <moveto x="-38" y="0" z="-169" anim="walk" />

When this operation is executed, the angle necessary to point in the right direction towards this 3d coordinate is calculated and the DR message to start the anim, start the movement and set the rotation angle so it will look correct is sent. Then the operation calculates the time it will take to traverse the distance at the specified speed and suspends itself for that length of time before waking up and completing. Thus, this operation has zero processing during these ½ second update opportunities. No CD checking is done and no bounds checking is done.

When the operation wakes up a few seconds later, the <moveto> is considered complete, and npcclient sends another DR message to stop the movement.

While this operation is very cheap, it is also not very flexible because the coordinates are in the NPCType and not in the NPC. Thus any NPC using this NPC Type with this command in it is going to have to be willing to move to this exact 3d coordinate.

Navigate Operation

(Net load: 1, CPU Load 1)

Parameter Type Default Description
anim string The animation to use in the navigation.
failure string The perception to fire if the operation fails.


The <navigate> operation is a placeholder right now and is simpler than it will be in the future. It is designed to work with <locate> and it moves the NPC in a straight line to the target location found by the <locate> operation.

 Ex: <navigate anim="walk" />

The only thing the operation specifies is the animation to play while moving. It works much like <moveto> but uses the locate target destination instead of a single fixed location. The only network overhead are the Start and Stop DR messages, and the only CPU overhead is calculating how long to sleep between starting and stopping.

For more complex movement the Wander Operation should be used that will use the path network to navigate. Though if there are no path directly to the location to where the NPC should go a combination of Wander and Navigate could be used. Like this example where wander is used to navigate using waypoints and navigate is used navigate into the exact position of the tavern.

 Ex <locate obj="tavern" static="yes" random="yes" range="800" > 
    <wander /> 
    <navigate />

NOP Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description

This is a no operation operation. It does absolutely nothing, though each behavior needs to have a set of operations, if nothing else insert this nop operation.

 Ex: <nop />

Percept Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
event string The name of the perception event to fire. NPC Variables will be replaced.
target self,tribe,all,target self The recipient of this perception
type string (null) The perception type. NPC Variables will be replaced.
range float 0.0 If set to something greater than 0.0 this perception will only be delivered if within that range.
condition string A NPCClient math script that if set will be evaluated and any non zero return value will cause the perception event to be fired.
failed_event string The event to percept if the condition fail. NPC Variables will be replaced.
delayed float 0.0 The amount of time to delay before the perception is fired. NPC Variables will be replaced.

This operation allows an NPC to fire a custom perception to himself.

 Ex: <percept event="done wandering" />
     <percept event="need help" target="tribe" range="50" />
     <percept event="GoToSleep" condition="DiurnalNight" delayed="10" />

Pickup Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
obj string,perception perception The object to pick up. (Only perception implemented)
count int 1 Number of objects to pick up
equip slot name of slot to equip the item in (Not implemented)

This operation allows an NPC to pickup an item he finds on the ground, and optionally equip(Not implemented) it if he can use it. Only objects that are pickable will be picked up.

 Ex: <pickup obj="perception" count="2" />
     <pickup obj="perception" equip="righthand" /> (Not Implemented)

Release Control Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description

Release the control of a player.

 Ex: <release_control />

Reproduce Operation

(Net load: 0, CPU Load: 0)

Tribe operation.

Parameter Type Default Description
type string The tribe member type for this. NPC Variables will be replaced.

The reproduce operation will spawn the target with the type given. Tribes will use this to create different types of members (See: Select statement in Tribe Scripting).

 Ex: <reproduce type="Warrior" />

To make make a copy of your self

 Ex: <locate obj="self" />
     <reproduce />

Resurrect Operation

(Net load: 0, CPU Load: 0)

Tribe operation.

Parameter Type Default Description

No Parameters.

This operation will resurrect a tribe member within the radius of tribe home.

 Ex: <resurrect />

This operation should be placed in an behavior that will be executed for dead NPCs. The reaction should as well have the when_dead flag set.

 Ex: <behavior name="Resurrect" completion_decay="200" growth="0" initial="0" when_dead="yes">
        <resurrect/>
     </behavior>
     <react event="tribe:resurrect"    behavior="Resurrect"     inactive_only="yes" when_dead="yes" />

Reward Operation

(Net load: 0, CPU Load: 0)

Tribe operation.

Parameter Type Default Description
resource string,tribe:wealth Mandatory The resource to reward to the tribe. NPC Variables will be replaced.
count int 1 The number of resource to reward.

Will reward a tribe with a resource. Using the special tribe:wealth keyword will result in a lockup in the tribe for whats the wealth resource.

 Ex: <reward resource="Gold Ore" count="2" />
     <reward resource="tribe:wealth" />

Rotate Operation

(Net load: 1, CPU Load: 0)

Parameter Type Default Description
type See table below. Mandatory The type of rotation operation to perform.
ang_vel float 0.0 Angular velocity in degree. If 0 the NPC default angular velocity will be used.
anim string The animation to use for the rotation operation
max float 0.0 For inregion and random a range can be defined.
min float 0.0 For inregion and radom a range can be defined.
value float 0.0 For absolute and relative a value to add in degrees should be given.
Type Description
inregion
random
absolute
relative
locatedest Face in the direciton of the last located position.
locaterotation Face in the direction of the last located rotation angle.
target

This operation <rotate> can be used to turn to a certain angle, to turn a relative amount, to turn a random amount or to turn to face a previously located object. This turn is animated, to give a more realistic look.

 Ex: <rotate type="random" min="90" max="270" anim="walk" vel="30" />
     <rotate type="locatedest" anim="walk" vel="90" />

The first example here is a random turn of between 90 and 270 degrees from the current heading, with an angular velocity of 30 degrees per second, while playing the “walk” animation. 30 degrees per second means that the maximum turn of 270 degrees will take the npc 9 seconds.

In the second example, we have already used our <locate> operation to find a point of interest near us, and we want to turn to point directly at it. Here a different (faster) angular velocity is specified but other angles aren’t necessary because they are implied by the current position of the NPC and the located special destination.

This operation requires a DR update to start and stop the rotation, as the only networking overhead. CPU overhead is also minimal since npcclient calculates the time required to turn the full amount and puts this script to sleep for that many msec until the turn is done, then stops it.

Script Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
name string Mandatory The name of the script

Run a Progression Event script. Target and Actor env is set for the script at the server.

 Ex: <script name="my_script" />

Sequence Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
name string Mandatory The name of the sequence to control
cmd start,stop,loop Mandatory The control of the sequence to issue.
count int 1 The number of times to loop the sequence.

Sequences are defined in the map file. They can be started, stopped, or played a number of time with the loop command. This allow the NPC to interact with large animation of world objects. This could be a winch that should run only when manned, a folding bridge or door that open and close etc.

 Ex: <sequence name="winch_up" cmd="start" />

Set Buffer Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
buffer string Mandatory The name of the buffer.
value string Mandatory The value to set for the buffer.
type npc,tribe npc The type of buffer to set.

Set either a NPC or a Tribe buffer. NPC Variables $NBUFFER[Buffer] (NPC Buffer) and $TBUFFER[Buffer] (Tribe Buffer) are replaced multiple places with the value of the buffer.

 Ex: <set_buffer buffer="Building" value="Small Tent" />

Share Memories Operation

(Net load: 0, CPU Load: 0)

Tribe operation.

Parameter Type Default Description

No parameters

This operation will share all private memories of the NPC with the tribe. Private memories is created with the Memorize Operation. They can be retrived by the Locate Operation using tribe:memory:"memory name". Memories can also be crated using the Auto Memorize Operation.

 Ex: <share_memories />

Sit Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description

No parameters.

Sit tells the npc to sit down. Use standup operation to stand up again.

 Ex: <sit />

Sound Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
name String the sound to play, references dt_sound datatable
loop boolean NOT WORKING YET. Should loop the sound.


Will play a sound at the location of the NPC.

 Ex: <sound name="mandolin1_song" loop="yes" />

Standup Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description

No parameters.

Standup tells the npc to stand up. Use sit operation to sit down again.

 Ex: <standup />

Talk Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
target boolean true Talk to current target
text string The string to send
public boolean true Should this talk go to everyone in range, or only the target if public=false.
type say,me,my,narrate say The type of talk.
command string A perception to send to target if it is a NPC. NPC Variables will be replaced.

If target is false, this will queue a talk command to the server from the NPC. If target is true and a target exists the same talk command will be sent to the server but a "command" perception will be sent to the target as well. The target will than be able to react to this perception.

 Ex: <talk target="true" text="Kneel in front of me." command="kneel" />
     <talk type="me" text="is angry" />
     <talk target="true" text="This message is only for you" public="false" />

Teleport Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description

Teleport the NPC to the current active location.

 Ex: <teleport />

Transfer Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
item string,tribe:wealth Mandatory The name of the item to transfer. NPC Variables will be replaced.
target tribe Mandatory The target for this transfer.
count int
Number of items to transfer. -1 is all items.

Transfere a number of item from one NPC to the target.

 Ex: <transfer item="tribe:wealth" target="tribe" />

This example will transfer all of the tribe wealth from the NPC to the tribe.

Tribe Home Operation

(Net load: 0, CPU Load: 0)

Tribe operation.

Parameter Type Default Description

No Parameters.

Move the tribe home to the last active position of the NPC. This operation will issue a "tribe:home moved" perception to all members of the tribe.

 Ex: <tribe_home />

Tribe Type Operation

(Net load: 0, CPU Load: 0)

Tribe operation.

Parameter Type Default Description
type string Change tribe member type.

No Parameters.

Change the Tribe Member type of the current NPC to the new type.

 Ex: <tribe_type type="Queen" />

Unbuild Operation

(Net load: 0, CPU Load: 0)

Tribe operation.

Parameter Type Default Description

Unbuild a building. The building has to be targeted.

 Ex: <unbild />

Visible Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description

No Parameters.

This operation makes the NPC visible if it where invisible. See Invisible Operation.

 Ex: <visible />

Wait Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
duration float Mandatory The duration to wait. NPC Variables will be replaced.
random float 0.0 The random duration to wait. NPC Variables will be replaced.
anim string The animation to play while waiting.

This operation makes the NPC wait a specified length of time before progressing to the next operation. It will loop an animation during this time also for you, so you can use it for crafting actions, guard monitoring, or whatever you need that is a timed animated activity.

 Ex: <wait duration="30" anim="stand" />
     <wait duration="$NBUFFER[Sit_Duration]" anim="sit" />

This example tells the NPC to play the “stand” animation and do nothing for 30 seconds. This requires a network DR message with the specified animation, and another to stop the animation when the duration is over. There is almost no CPU required because the script goes to sleep for the duration and is woken up automatically at the end.

As with any other scripted operation, this operation can be interrupted if another behavior preempts this one from completing. So if an npc is playing the above operation, and just standing there for 30 seconds, and is attacked by someone, presumably an attack behavior would become top priority and the npc would stop waiting and attack back.

This concludes the section on the detailed operations possible with npc scripting today. Now we will discuss how these operations work together to define behaviors and how behaviors interact with each other.

Wander Operation

(Net load: 2, CPU Load 1)

Parameter Type Default Description
anim string The animation to play while wandering.
vel float
random boolean false Turn on never ending random wandering.
underground boolean invalid If not set ignore underground, set true only wander underground, if set false never wander underground waypoints
underwater boolean invalid If not set ignore underwater, set true only wander underwater, if set false never wander underwater waypoints
private boolean invalid If not set ignore private, set true only wander private, if set false never wander private waypoints
public boolean invalid If not set ignore public, set true only wander public, if set false never wander public waypoints.
city boolean invalid If not set ignore city, set true only wander city, if set false never wander city waypoints.
indoor boolean invalid If not set ignore indoor, set true only wander indoor, set false never wander indoor waypoints.

Using random <move> and <rotate> operations works well for creating randomized wandering behaviors in open, outdoor spaces and scripters should be using that approach there. However, in tighter, indoor areas like the hydlaa sewers or the dungeon, a more specific type of randomness is required.

The <wander> operation makes the npc in question walk between an independently defined set of “waypoints”. Each waypoint is a 3d coordinate and a tolerance radius. The radius adds a ‘fuzzy’ factor so that multiple npcs sharing the same set of waypoints will not all walk to the exact same centimeter location. Even in tight locations, a tolerance radius of .5-1m will be a lot better than 0m. Waypoints will be created with the path system available as GM commands.

 Ex: <wander anim="walk" />

As you see, the only thing specified by the wander operation is the animation to play while wandering. The NPC starts by walking to the nearest waypoint to its current location, then follows the waypoint choices to decide where to go next. This operation will take the NPC to the current active waypoint as selected by the last Locate Operation.

Each waypoint have a set off properties. It can be marked as indoor,underground,underwater,private,public, or city. If the wander operations in specified with the indoor flag set to true only waypoints with the indoor attribute set to true will be used when wandering. Changing waypoint attributes can be done by the GM command /path (TBD, Not impemented yet, has to be done in DB for now).'

Each waypoint is connected with a path. The path has a set of properites like TELEPORT, NO_WANDER, ONEWAY.

This operation is very light on the network because it is all straight-line navigation between known, preset points. There is 1 DR update per point hit by the npc. It is also quite light on CPU power requirements because the points are known, which means no collision detection has to be done.

One tricky thing about this is that normally non-horizontal walking is accomplished on the client with collision detection with the ground/stairs. In order to get the most accurate-looking result on the client, the client DOES do collision detection on these npcs. However, npcclient does simple linear interpolation between the starting and ending y-coordinates of the 2 waypoints as an approximation. Thus the server and client will not have the identical y-coordinate in all cases. This should almost never be noticeable, though.

Watch Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
type nearest_actor,nearest_npc,nearest_player,owner,target Mandatory The type of watch to do.
range float 0.0 The watch range. A perception will be generated when watched entity move out of range.
invisible boolean false Set to true to watch invisible entities.
invincible boolean false Set to true to watch invincible entities.
search_range float 2.0 When watching nearest, this range set the limit for how fare that entity can be.

Watch over nearby entities. The "nearest out of range","owner out of range", or "target out of range" perception will be generated when the watched entity move out of range.

 Ex: <behavior name="Watch">
       <watch type="owner" range="3.0" />
     </behavior>
     <react event="owner out of range"   behavior="follow_chase"  />

In this example the NPC will watch the owner. If the owner move out of the watch range 3.0 the "owner out of range" perception will be fired and the new follow_chase behavior will start.

Work Operation

(Net load: 0, CPU Load: 0)

Parameter Type Default Description
type dig,fish,harvest Mandatory The type of work to do
resource string,tribe:wealth Mandatory Resource to work for or by using the keyword tribe:wealth look up in the tribe to find the resource.

Order an NPC to start digging for a resource. The keyword "tribe:wealth" will cause the resource to be looked up in the wealth_resource_nic field in the tribes table if the NPC is part of a tribe.

 Ex: <work type="dig" resource="tribe:wealth" />
     <work type="dig" resource="Gold Ore" />