Create an Entity – Arma Reforger
Lou Montana (talk | contribs) m (Text replacement - "\{\{Link\|enfusion.*\.c\|([A-Za-z0-9_]+)\}\}" to "{{Link/Enfusion|armaR|$1}}") |
Lou Montana (talk | contribs) m (Fix Wikipedia link) |
||
Line 91: | Line 91: | ||
Let's assume we do not want the {{hl|Print}} to be displayed multiple times in the case someone placed multiple Entities in the world. | Let's assume we do not want the {{hl|Print}} to be displayed multiple times in the case someone placed multiple Entities in the world. | ||
{{Feature|informative|A singleton is an entity that can only be instanciated once. See {{ | {{Feature|informative|A singleton is an entity that can only be instanciated once. See {{Link|https://en.wikipedia.org/wiki/Singleton_pattern}}.}} | ||
For that we will use the {{Link|Arma Reforger:Scripting: Keywords#static 2|static}} keyword to keep a single reference: | For that we will use the {{Link|Arma Reforger:Scripting: Keywords#static 2|static}} keyword to keep a single reference: |
Revision as of 01:14, 24 February 2023
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_PrintPlayerPositionClass. 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.
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 constructor to 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: