World Editor Plugin – Arma Reforger

From Bohemia Interactive Community
Jump to navigation Jump to search
(Page creation)
 
m (Fix link)
Line 48: Line 48:
</enforce>
</enforce>


The meat of the matter is happening in <enforce inline>WorldEditorAPI</enforce>, available through the <enforce inline>WorldEditor.GetApi()</enforce> method - see {{Link|WorldEditorAPI API|below}}.
The meat of the matter is happening in <enforce inline>WorldEditorAPI</enforce>, available through the <enforce inline>WorldEditor.GetApi()</enforce> method - see {{Link|#WorldEditorAPI API|below}}.




Line 77: Line 77:
if (!entitySource)
if (!entitySource)
continue;
continue;
 
worldEditorAPI.SetEntityVisible(entitySource, !worldEditorAPI.IsEntityVisible(entitySource), false);
worldEditorAPI.SetEntityVisible(entitySource, !worldEditorAPI.IsEntityVisible(entitySource), false);
}
}

Revision as of 09:53, 15 May 2024



This tutorial teaches how to create a World Editor-specific plugin.

Please read Workbench Plugin before following this tutorial.


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

See the WorldEditorPlugin class.

The WorldEditorPlugin class only exposes some events on which it is possible to subscribe (e.g OnGameModeEnded()).


WorldEditor Module API

See the WorldEditor class.

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

See the WorldEditorAPI class.


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


For a more advanced WorldEditorAPI usage, see World Editor Tool.