{{tag>dragonscript behavior}}
[[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[abstractions#behavior_elementsquick_and_easy_development|Behavior Elements: Quick and Easy Development]] >> **ECBehaviorOccupier**
* [[behaviors_use_cases|Behaviors Explained: By Use-Case]]
* [[behaviors_a_to_z|Behaviors Explained: From A to Z]]
====== ECBehaviorOccupier ======
Behavior element behavior adding support to uccipy an [[behavior_interactionspot|CBehaviorInteractionSpot]].
[[behavior_interactionspot|CBehaviorInteractionSpot]] defines position and orientation actors or the player have to assume to interact properly with this element. The ECBehaviorOccupier behavior provides support to claim such interaction spots.
{{youtube>BbP-lMrr0tQ?medium}}
Behavior in action (starting at timestamp 1:28)
====== Instance Counts ======
Usually an element has one instance of ECBehaviorOccupier but it is possible to use multiple instance for example to track different interacions. Think of a chair the actor can sit down upon. The actor can use one occupier to track sitting on the chair while using another occupier to track interacting with something while being seated.
====== Element Class Properties ======
Element class properties have the prefix **occupier.** or **occupier(id)**. if id is not empty.
This behavior does not define element properties (reserved for future expansion).
====== Required Behaviors ======
This behavior does not required other behaviors to be present.
====== Optional Behaviors ======
This behavior does not support optional behaviors.
====== Persistency ======
This behavior does support element class to be persistable (setPersistable). Saves [[behavior_interactionspot|CBehaviorInteractionSpot]] if present.
====== API Documentation ======
#@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorOccupier.html,ECBehaviorOccupier~@#.
Since DragonScript Module Version **1.4**
====== Use Cases ======
* Ensure actor/player is at a specific position and orientation relative to an interactive element to ensure animation of actor/player and interactive element properly line up.
* Ensure only one actor/player uses an interactive element at each time.
====== Element Class Example ======
class PlayerActor extends BaseActor
public var ECBehaviorOccupier.Instance occupier
public func new(PlayerActorClass eclass) super(eclass)
// Store occupier instance. This way you can access it in player
// actions without needing to look it up.
occupier = eclass.occupier.instance(this)
end
end
class PlayerActorClass extends BaseActorClass
public var ECBehaviorOccupier occupier
public func new() super("PlayerActor")
// Create occupier. Game code can then use the occupier instance
// to claim encountered ECBehaviorInteractionSpot instances
occupier = ECBehaviorOccupier.new(this)
// If you want to track more than one interaction spot you can
// add multiple occupier instances each with an own ID.
//occupierSeated = ECBehaviorOccupier.new(this, "seated")
end
public func Element createElement()
// Create instance of player actor. If you do not want to store the
// occupier instance aside you can drop the createElement() function.
// The base class then creates an instance of BaseActor
return PlayerActor.new(this)
end
end
In the [[https://github.com/LordOfDragons/deexamples|ExampleApp]] you can find a complete example of using this behavior:
* [[https://github.com/LordOfDragons/deexamples/blob/master/exampleApp/data/scripts/InteractionSpotExampleClass.ds|InteractionSpotExampleClass.ds]]: Element class providing an interaction spot the player can use
* [[https://github.com/LordOfDragons/deexamples/blob/master/exampleApp/data/scripts/BehaviorInteractToggle.ds|BehaviorInteractToggle.ds]]: Interaction behavior allowing player to toggle the animated state of an element. This behavior stores the interaction spot the player has to claim.
* [[https://github.com/LordOfDragons/deexamples/blob/master/exampleApp/data/scripts/PlayerActorClass.ds|PlayerActorClass.ds]]: Player actor class. Uses occupier behavior to safely do interactions.
* [[https://github.com/LordOfDragons/deexamples/blob/master/exampleApp/data/scripts/PlayerActionInteractToggle.ds|PlayerActionInteractToggle.ds]]: Player action interacting with BehaviorInteractToggle. Tries to claim the assigned interaction spot and if successful moves to the spot and uses the element. Once finished releases the interaction spot.