Making an Entity frobable

From The DarkMod Wiki
Revision as of 21:56, 24 September 2020 by Geep (talk | contribs) (→‎Configuring an Entity for Use)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Originally written by sparhawk on http://forums.thedarkmod.com/topic/1722

Create an Entity Definition

In order to make an entity frobable several steps must be done. Each entity has a definition file (*.def) where the name of the entity is specified. This definition will determine basic properties that will be set for ALL entity instances of this type. Alternatively an entity is instanciated in the map file and properties can be set there as well. In this case the property will only apply to that particular instance of the entity. Example: Doors should be frobable by default but there may be doors that are not frobable because they are only there as decoration and no geometry is behind it.

  • frobable : BOOL [1|0] A value of 1 means that this entity is frobable, a value of 0 means it is not. 0 doesn't have to be specified because it is the default. This only has to be used if the class of that entity is made frobable but a particular instance should be not (i.E. a door that can't be opened and serves only as decoration). If only this value is present then the default frobdistance will be used.
  • frob_distance: INT 0...N Frobdistance overrides the default frobdistance for a particular entity class or instance. If this key is used, frobable doesn't have to be present if the value is not zero. If the value is zero and frobable is also zero the item is not frobable (default and doesn't need to be specified). If both keys are being used (frobable and frob_distance) frob_distance will take precedence and is used. The number specifies the distance in engine units. A value between 70 and 90 seems to be a good distance.

In order to make the item highlight you must update the material definition and include the following code:

 {
    if ( parm11 >= 0.5 )
       blend  add
       map    <path to highlight texture>
       rgb 0 < n < 1
 }

Using an entity

In order for an entity being used it must have a reference to all the entities it can be used by. Each entity stores a list of all entities it can be used by. When the USE key is pressed it will be first tested if an item is selected in the inventory. If this is the case it is assumed that the currently highlighted entity will be used the selected entity (i.E. a door is being frobbed and a key is active). The entities UsedBy() function is called with the selected entity being passed in as an argument. The highlighted entity can then check if it has the passed in entity in it's usedby list and if this is the case, perform the appropriate action. A scriptfunction will be called in this case which can be defined by the user and which key is named "use_action_script". If the UsedBy function returns false the USE key will be passed on to the next action in the chain. If the function returns true it is assumed that a USE action has been performed and the event will no longer be propagated.

If there is currently no highlighted item the next thing to test is if the item, selected in the inventory can be used (For example a mine) or the UsedBy function returned false, as described above, the UsedBy function is called on the selected entity instead and it will get passed in a NULL pointer.

If this UsedBy function also returns false the FrobAction function is called on the currently highlighted entity. If there is no highlighted entity the key is ignored.

Configuring an Entity for Use

In order to allow an entity to be frobbed and used several variables have to be set. The definitions of entities in the Doom 3 environment is set in a hierarchical order. You can define base classes and subsequent classes can derive from this and take all settings as they were defined in the base class, they can override the base settings, or they can introduce new settings as well. If you are familiar with an object oriented language there should be no problem understanding the concept.

The Darkmod uses the following hierarchy for frobable entities:

The name in the <> refers to the filename the entity is defined in.

darkmod_frob_entity : <darkmod_entity.def>
func_darkmod_door : <func_darkmod.def>

darkmod_item_default : <darkmod_items.def>
darkmod_item_healthpotion : <darkmod_items.def>
darkmod_item_coins_small : <darkmod_items.def>
darkmod_item_key : <darkmod_items.def>
darkmod_item_book_red1 : <darkmod_items.def>
darkmod_item_book_t1 : <darkmod_items.def>

Each key has to be set by specifing the key and the value.

Example:

"frobable" "1"

darkmod_frob_entity:

  • frobable: [1|0] This key defines if an entity is frobable. If set to 1 the item is frobable and will be highlighted when the conditions are met described above. The frobdistance which is applied to this entity will be taken from the INI <DefaultFrobDistance> setting.
  • frob_distance: INT [0...N] This key defines the frobdistance in D3 render units. If the value is set to 0 it is the same as if frobable were set to 0. If both keys are set this one takes precedence. There is no need to define both keys because if frob_distance is set to 0 it will disable frobbing on this item and if set to any non-zero value the item is frobable regardless of the frobable state. The reason for using two keys is to be able to override the default setting if need be.

Nielsen74's Cabinet Advice

Setting the frob distance short is a VERY BAD way to keep players from getting items in cabinet/chests.

Use a CLIP textured brush INSIDE the cabinet:

  • Make it a atdm_target_set_frobable_1
  • Target that FROM the door/lid TO the atdm_target_set_frobable_1
  • Set the property trigger_on_close = 1 and immune_to_target_setfrobable = 1 on the door/lid

Now all items are un-frobable when the door/lid is closed and fully frobable when the door/lid is open.

See also