World Editor Plugin – Arma Reforger
Jump to navigation
Jump to search
ⓘ Not to be confused with World Editor Tool.
This tutorial teaches how to create a World Editor-specific plugin.
Setup
- Open Script Editor
- In an addon, create a new script in WorkbenchGame
/WorldEditor - name it TAG_TutorialPlugin.c (must end with Plugin by convention) - Double-click the file to open it
- Press Ctrl + T to use the Script Template plugin
- In its window, select "Class Type: WorkbenchPlugin", leave the other fields blank/default
- A Workbench plugin skeleton is inserted.
- In the WorkbenchPluginAttribute, replace wbModules: { "ResourceManager" } by wbModules: { "WorldEditor" }
- Make the plugin inherit from WorldEditorPlugin instead of WorkbenchPlugin
- In the Run() method, write Print("It works!"); and save the file
- Unlike other plugins, Rebuild Scripts using the ⇧ Shift + F7 default shortcut
- Reload Workbench scripts via Reload Scripts option located in Plugins → Settings (default shortcut: Ctrl + ⇧ Shift + R)
- The TAG_TutorialPlugin plugin should appear in the World Editor's Plugins list, available in the top bar - click on the plugin entry
- "It works!" gets printed in the output console.
WorldEditorPlugin API
The WorldEditorPlugin class only exposes some events on which it is possible to subscribe (e.g OnGameModeEnded()).
WorldEditor Module API
The WorldEditor module allows to do some minor operations (e.g get Resource Browser's selection, get current world's boundaries).
vector min, max;
WorldEditor worldEditor = Workbench.GetModule(WorldEditor);
if (!worldEditor)
return;
worldEditor.GetWorldBounds(min, max);
Print("Min = " + min);
Print("Max = " + max);
The meat of the matter is happening in WorldEditorAPI, available through the WorldEditor.GetApi() method - see below.
WorldEditorAPI API
Example
In this example, we will use WorldEditorAPI methods to hide/show all selected entities (it will hide a shown entity and vice versa):
#ifdef WORKBENCH
[WorkbenchPluginAttribute(name: "Tutorial Plugin", shortcut: "Ctrl+Shift+H", wbModules: { "WorldEditor" }, awesomeFontCode: 0xF188)]
class TAG_TutorialPlugin : WorldEditorPlugin
{
override void Run()
{
WorldEditor worldEditor = Workbench.GetModule(WorldEditor);
if (!worldEditor)
return;
WorldEditorAPI worldEditorAPI = worldEditor.GetApi();
IEntitySource entitySource;
for (int i = worldEditorAPI.GetSelectedEntitiesCount() - 1; i >= 0; --i)
{
entitySource = worldEditorAPI.GetSelectedEntity(i);
if (!entitySource)
continue;
worldEditorAPI.SetEntityVisible(entitySource, !worldEditorAPI.IsEntityVisible(entitySource), false);
}
}
}
#endif