Create an Entity – Arma Reforger
Lou Montana (talk | contribs) m (Text replacement - "{{Link|Arma Reforger:World Editor|World Editor}}" to "{{Link|Arma Reforger:World Editor}}") |
Lou Montana (talk | contribs) m (Fix) |
||
Line 10: | Line 10: | ||
Create a new file and name it as your entity - here, we will go with {{hl|TAG_PrintPlayerPositionEntity}} so the file should be {{hl|TAG_PrintPlayerPositionEntity.c}}. | Create a new file and name it as your entity - here, we will go with {{hl|TAG_PrintPlayerPositionEntity}} so the file should be {{hl|TAG_PrintPlayerPositionEntity.c}}. | ||
{{Feature|informative|By convention, all | {{Feature|informative|By convention, all Entity classnames must end with the {{hl|Entity}} suffix, here {{hl|TAG_PrintPlayerPosition'''Entity'''}}.}} | ||
{{Feature|important|An entity script file '''must''' be created in the '''Game''' module ({{hl|scripts/Game}}), otherwise it will not be listed in the Entities list!}} | {{Feature|important|An entity script file '''must''' be created in the '''Game''' module ({{hl|scripts/Game}}), otherwise it will not be listed in the Entities list!}} | ||
Line 22: | Line 22: | ||
An Entity requires an Entity Class declaration. This allows it to be visible in {{Link|Arma Reforger:World Editor}}. | An Entity requires an Entity Class declaration. This allows it to be visible in {{Link|Arma Reforger:World Editor}}. | ||
The name must be '''exactly''' the Entity name suffixed by {{hl|Class}}, here {{hl|TAG_PrintPlayerPosition'''Class'''}}. | The name must be '''exactly''' the Entity name suffixed by {{hl|Class}}, here {{hl|TAG_PrintPlayerPosition''Entity''<nowiki/>'''Class'''}}. | ||
An Entity Class is usually placed just above the Entity definition as such: | An Entity Class is usually placed just above the Entity definition as such: | ||
<enforce> | <enforce> | ||
[EntityEditorProps(category: "Tutorial Entities", description: "Prints player's position regularly")] | [EntityEditorProps(category: "Tutorial/Entities", description: "Prints player's position regularly")] | ||
class TAG_PrintPlayerPositionEntityClass : GenericEntityClass | class TAG_PrintPlayerPositionEntityClass : GenericEntityClass | ||
{ | { | ||
Line 50: | Line 50: | ||
; visible | ; visible | ||
: have the bounding box always visible - drawn in {{hl|color}} | : have the bounding box always visible - drawn in {{hl|color}} | ||
; insertable | |||
: | |||
; configRoot | ; configRoot | ||
Line 79: | Line 82: | ||
=== Add Code === | === Add Code === | ||
Let's use the {{hl|IEntity}}'s | Let's use the {{hl|IEntity}}'s <enforce inline>OnPostInit()</enforce> method to set flags and call code. | ||
{{Feature|important|Set the entity flags in <enforce inline>OnPostInit()</enforce>, not in the constructor.}} | |||
<enforce> | <enforce> | ||
Line 113: | Line 117: | ||
m_fWaitingTime = 0; | m_fWaitingTime = 0; | ||
PrintPlayerPosition(); | PrintPlayerPosition(); | ||
} | |||
//------------------------------------------------------------------------------------------------ | |||
override void OnPostInit(IEntity owner) | |||
{ | |||
SetEventMask(GetEventMask() | EntityEvent.FRAME); // do NOT set event masks in constructor | |||
} | } | ||
Line 118: | Line 128: | ||
void TAG_PrintPlayerPositionEntity(IEntitySource src, IEntity parent) | void TAG_PrintPlayerPositionEntity(IEntitySource src, IEntity parent) | ||
{ | { | ||
// can be removed | |||
} | } | ||
} | } | ||
Line 235: | Line 244: | ||
<spoiler text="Show File Content"> | <spoiler text="Show File Content"> | ||
<enforce> | <enforce> | ||
[EntityEditorProps(category: "Tutorial Entities", description: "Prints player's position regularly", color: "0 255 0 0")] | [EntityEditorProps(category: "Tutorial/Entities", description: "Prints player's position regularly", color: "0 255 0 0")] | ||
class TAG_PrintPlayerPositionEntityClass : GenericEntityClass | class TAG_PrintPlayerPositionEntityClass : GenericEntityClass | ||
{ | { | ||
Line 251: | Line 260: | ||
protected int m_iCycleDuration; | protected int m_iCycleDuration; | ||
protected float m_fWaitingTime = float. | protected float m_fWaitingTime = float.INFINITY; // trigger Print on start | ||
protected static TAG_PrintPlayerPositionEntity s_Instance; | protected static TAG_PrintPlayerPositionEntity s_Instance; | ||
Line 282: | Line 291: | ||
m_fWaitingTime = 0; | m_fWaitingTime = 0; | ||
PrintPlayerPosition(); | PrintPlayerPosition(); | ||
} | |||
//------------------------------------------------------------------------------------------------ | |||
override void OnPostInit(IEntity owner) | |||
{ | |||
SetEventMask(GetEventMask() | EntityEvent.FRAME); | |||
} | } | ||
Line 301: | Line 316: | ||
s_Instance = this; | s_Instance = this; | ||
} | } | ||
} | } |
Revision as of 15:28, 3 May 2024
A World Editor entity is a scripted entity that can be placed from the World Editor's Create tab.
In this example, we will create an Entity that once placed in the world, will print the player's position with a certain frequency.
Declaration
Entity
Create a new file and name it as your entity - here, we will go with TAG_PrintPlayerPositionEntity so the file should be TAG_PrintPlayerPositionEntity.c.
Entity Class
An Entity requires an Entity Class declaration. This allows it to be visible in World Editor. The name must be exactly the Entity name suffixed by Class, here TAG_PrintPlayerPositionEntityClass. An Entity Class is usually placed just above the Entity definition as such:
The class is decorated using EntityEditorProps; the category is where the Entity will be found in World Editor's Create tab - see below.
EntityEditorProps
- category
- the "Create" tab's category in which the Entity can be found
- description
- unused (for now)
- color
- the bounding box's unselected line colour - useful only when visible is set to true
- visible
- have the bounding box always visible - drawn in color
- insertable
- configRoot
- unused
- icon
- unused: direct path to a png file, e.g WBData
/EntityEditorProps /entityEditor.png
- style
- can be "none", "box", "sphere", "cylinder", "capsule", "pyramid", "diamond"
- sizeMin
- bounding box's lower dimensions
- sizeMax
- bounding box's higher dimensions
- color2
- the bounding box's surface colour
- dynamicBox
- enables the entity visualiser using custom dimensions (provided by _WB_GetBoundBox())
Filling
The Entity is now visible in World Editor, the next step is to make it do something.
Add Code
Let's use the IEntity's OnPostInit() method to set flags and call code.
Make It Unique
Let's assume we do not want the Print to be displayed multiple times in the case someone placed multiple Entities in the world.
For that we will use the static keyword to keep a single reference:
Add Properties
Now, we can declare properties with the Attribute in order to be able to adjust some settings from the World Editor interface. The following code only contains the added attributes:
The following code contains code with the implemented attributes:
Now all there is to do is to place one TAG_PrintPlayerPositionEntity entity in the world and see the player's position printed in logs!
Final Code
The final file content can be found here: