World Editor Plugin – Arma Reforger

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "{{Feature|informative|See the {{Link/Enfusion|armaR|WorldEditorAPI}} class.}}" to "{{Feature|informative|See the {{Link/Enfusion|armaR|WorldEditorAPI}} class as well as {{Link|Arma Reforger:WorldEditorAPI Usage}}.}}")
m (Text replacement - "{{Link|OFPEC tags" to "{{Link|Scripting Tags")
 
Line 11: Line 11:


* Open Script Editor
* Open Script Editor
* In an addon, create a new script in {{hl|WorkbenchGame/WorldEditor}} - name it {{hl|{{Link|OFPEC tags|TAG_}}TutorialPlugin.c}} (must end with {{hl|Plugin}} by convention)
* In an addon, create a new script in {{hl|WorkbenchGame/WorldEditor}} - name it {{hl|{{Link|Scripting Tags|TAG_}}TutorialPlugin.c}} (must end with {{hl|Plugin}} by convention)
* Double-click the file to open it
* Double-click the file to open it
* Press {{Controls|Ctrl|T}} to use the {{Link|Arma Reforger:Script Editor: Fill From Template Plugin|Script Template plugin}}
* Press {{Controls|Ctrl|T}} to use the {{Link|Arma Reforger:Script Editor: Fill From Template Plugin|Script Template plugin}}

Latest revision as of 12:03, 2 October 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 as well as WorldEditorAPI Usage.


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.