User Tools

Site Tools


hpl3:game:scripting:entity_components

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
hpl3:game:scripting:entity_components [2012/12/06 09:16]
thomas
hpl3:game:scripting:entity_components [2014/02/13 15:22]
thomas [General]
Line 8: Line 8:
 ===== CharMover ===== ===== CharMover =====
  
-**Creation function:** ''​cLuxCharMover@ ​cLux_CreateEntityModule_CharMover(iLuxEntity @apEntity, iCharacterBody @apCharBody)''​+**Creation function:** ''​cLuxCharMover@ ​cLux_CreateEntityComponent_CharMover(iLuxEntity @apEntity, iCharacterBody @apCharBody)''​
  
 ==== General ==== ==== General ====
Line 15: Line 15:
 ===== PathFinder ===== ===== PathFinder =====
  
-**Creation function:** ''​cLuxPathFinder@ ​cLux_CreateEntityModule_PathFinder(iLuxEntity @apEntity)''​+**Creation function:** ''​cLuxPathFinder@ ​cLux_CreateEntityComponent_PathFinder(iLuxEntity @apEntity)''​
  
 ==== General ==== ==== General ====
Line 22: Line 22:
 ===== StateMachine ===== ===== StateMachine =====
  
-**Creation function:** ''​cLuxPathFinder@ ​cLux_CreateEntityModule_StateMachine(iLuxEntity @apEntity)''​+**Creation function:** ''​cLuxPathFinder@ ​cLux_CreateEntityComponent_StateMachine(iLuxEntity @apEntity)''​
  
 ==== General ==== ==== General ====
Line 31: Line 31:
 To use the statemachine,​ you need to create states right after having created the module. It is very important that all states are always created in the same order for all entities using the same script file (basically meaning you should not dynamically create states during the update loop or similar). For instance: To use the statemachine,​ you need to create states right after having created the module. It is very important that all states are always created in the same order for all entities using the same script file (basically meaning you should not dynamically create states during the update loop or similar). For instance:
  
-<code c++>​@mpStateMachine = cLux_CreateEntityModule_StateMachine(mBaseObj);+<code c++>​@mpStateMachine = cLux_CreateEntityComponent_StateMachine(mBaseObj);
 mpStateMachine.AddState("​Idle",​ eState_Idle);​ mpStateMachine.AddState("​Idle",​ eState_Idle);​
 mpStateMachine.AddState("​Move",​ eState_Move);​ mpStateMachine.AddState("​Move",​ eState_Move);​
Line 79: Line 79:
 <code c++> mpStateMachine.ChangeSubState(-1)</​code>​ <code c++> mpStateMachine.ChangeSubState(-1)</​code>​
 which set no state at all as sub state. This is actually the default setting when ever a new normal state is started. which set no state at all as sub state. This is actually the default setting when ever a new normal state is started.
 +
 +==== Default State ====
 +
 +The default state is a state that can be used by both normal states and sub states. To add it just write a state function with the name "​Default"​ instead of a state name. (This means a state cannot be named "​Default"​.) Then this function will be called if the current state does not contain it. So for instance if you have something like:
 +<code c++>
 +void State_Default_Update(float afTimeStep){
 +...
 +}
 +
 +void State_State1_Update(float afTimeStep){
 +...
 +}
 +</​code>​
 +If the state machine is currently in ''​State1''​ then the ''​Update''​ for ''​State1''​ will be called. However, if the current state is ''​State2''​ and it does not have an implemention of ''​Update'',​ the ''​Default''​ version of ''​Update''​ will be called.
 +
 +There is a special case for ''​State_Default_Message''​. This is also called if the state specific function returns false.
 +
 +
 +
 +
 ==== Timers ==== ==== Timers ====
  
Line 86: Line 106:
 ===== SoundListener ===== ===== SoundListener =====
  
-**Creation function:** ''​cLuxSoundListener @ cLux_CreateEntityModule_SoundListener ​(iLuxEntity @apEntity)''​+**Creation function:** ''​cLuxSoundListener @ cLux_CreateEntityComponent_SoundListener ​(iLuxEntity @apEntity)''​
  
 ==== General ==== ==== General ====
-This simply ​makes the entity into a sound listener and it will now receive the event message eLuxEntityMessage_SoundHeard whenever a sound of a specific type (specfied ​in "​sounds/​ai_reaction_sounds.dat"​).+This makes the entity into a sound listener and it will now receive the event message eLuxEntityMessage_SoundHeard ​(mvX=postion and mlX=Prio) ​whenever a sound of a specific type is played ​(specified ​in "​sounds/​ai_reaction_sounds.dat"​, or whatever is set in the game.cfgor an event is broadcasted (Sound_CreateAIEventAtEntity()).  
 + 
 +If attached to an Agent, then setting SensesActive to false disables the listener too. 
 + 
 +Also note that footstep sounds are not sound entities and thus do not generate event automatically. Therefore the MoveState does a special broadcast of the events (properties are the top). 
 + 
 +==== Properties ==== 
 +There are two properties that regulate how the listener reacts to sounds. 
 + 
 +**Radius**\\ 
 +This is used when checking if the listener overlaps with a sound event. Position is gotten by calling GetPosition() in the Entity (In Agents, center of the char collider) and defualt is 0.5 meters. This can be extended to make a listener get better hearing.\\ 
 +//Reason we do not calculate any volume is because it becomes a bit vague and hard to keep track of, this is a more robust and easy to understand system.// 
 + 
 +**MinHearPrio**\\ 
 +The minimum prio a sound must have for the listener to hear it. Usually common sounds like small object physics impacts have 0, walking steps 1 and running 2.  Can also be good to change this depending on state to set the alertness of an entity. 
 + 
 +==== Debugging ==== 
 + 
 +You can check Show Sound AI Events in the debug window to see two sphere drawn of each triggered event. The red sphere notes the center and the white one the range. 
 +==== The File ==== 
 +The ai_reaction_sounds.dat file is basically just an xml file where you set which sounds should generate events and how the genreated event should look like. Important to note that the sound types are parsed from top to bottom when the game is parsed. This means that if a sound applies to many types, the top one will be chosen. This could come in handy for special cases. 
 + 
 +The properties are as follows: 
 + 
 +**SubStrings**\\ 
 +A list of strings, separated by space and/or comma, that the sound'​s data name (NOT its entity name) must contain. 
 + 
 +**Radius**\\ 
 +The radius of the generated event. 
 + 
 +**Prio**\\ 
 +As listners can be setup to not hear sounds below a certain prio, this can be used to exclude certain listeners. Listener AI also often use this to see what sound to check out if more than one are heard (largest prio picked). 
 + 
 +**Params**\\ 
 +A type can have many params, but it almost always is enough with one. You can set MinValue to see cull out certain sounds and note that this can be used to have different radius on a sound depending on a param (several types, same substrings, but different param min values). Just makes sure to have the largest min values first! (Otherwise they will never get picked).\\ 
 +If a name for the param is not set, then index is used instead.
  
 ===== HeadTracker ===== ===== HeadTracker =====
  
-**Creation function:** ''​cLuxHeadTracker @ cLux_CreateEntityModule_HeadTracker(iLuxEntity @apEntity)''​+**Creation function:** ''​cLuxHeadTracker @ cLux_CreateEntityComponent_HeadTracker(iLuxEntity @apEntity)''​
  
 ==== General ==== ==== General ====
Line 100: Line 155:
 ===== ForceEmitter ===== ===== ForceEmitter =====
  
-**Creation function:** ''​cLuxForceEmitter @ cLux_CreateEntityModule_ForceEmitter(iLuxEntity @apEntity)''​+**Creation function:** ''​cLuxForceEmitter @ cLux_CreateEntityComponent_ForceEmitter(iLuxEntity @apEntity)''​
  
 ==== General ==== ==== General ====
 This will give the entity a force field (cForceField) which makes certain things in the game world (such as undergrowth) animate and react to its presence . If MaxForceSpeed is higher than 0 it will also vary in strength depending on the speed of the MainBody (or character if set). This will give the entity a force field (cForceField) which makes certain things in the game world (such as undergrowth) animate and react to its presence . If MaxForceSpeed is higher than 0 it will also vary in strength depending on the speed of the MainBody (or character if set).
 +
 +===== BarkMachine =====
 +
 +**Creation function:** ''​cLuxBarkMachine ​  @ cLux_CreateEntityComponent_BarkMachine ​ (iLuxEntity @apEntity)''​
 +
 +==== General ====
 +This creates a component that can have one or more states with random sounds or voice quips (barks). It is meant to be used with entities that require different sounds/​voices to be randomly played depending on which state it is in.
 +
 +===== BackboneTail=====
 +
 +**Creation function:** ''​cLuxBackboneTail ​  @ cLux_CreateEntityComponent_BackboneTail ​ (iLuxEntity @apEntity)''​
 +
 +==== General ====
 +When this is added, the backbone of the entity (as defined in the ent file) will be bent as the entity moves along. It is meant to be used by things like fishes, etc to get more natural like movement, but can of course be used for whatever. Note that all setup should be done in the ent file, and have the component load the type variables.
hpl3/game/scripting/entity_components.txt · Last modified: 2017/04/20 07:57 by alexkalopsia