World Editor Plugin – Arma Reforger
Jump to navigation
Jump to search
Lou Montana (talk | contribs) (Page creation) |
Lou Montana (talk | contribs) m (Text replacement - "{{Link|OFPEC tags" to "{{Link|Scripting Tags") |
||
(2 intermediate revisions by the same user not shown) | |||
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| | * 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}} | ||
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}}. | ||
== WorldEditorAPI API == | == WorldEditorAPI API == | ||
{{Feature|informative|See the {{Link/Enfusion|armaR|WorldEditorAPI}} class.}} | {{Feature|informative|See the {{Link/Enfusion|armaR|WorldEditorAPI}} class as well as {{Link|Arma Reforger:WorldEditorAPI Usage}}.}} | ||
Line 77: | Line 77: | ||
if (!entitySource) | if (!entitySource) | ||
continue; | continue; | ||
worldEditorAPI.SetEntityVisible(entitySource, !worldEditorAPI.IsEntityVisible(entitySource), false); | worldEditorAPI.SetEntityVisible(entitySource, !worldEditorAPI.IsEntityVisible(entitySource), false); | ||
} | } |
Latest revision as of 12:03, 2 October 2024
ⓘ 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