[0.8.9][NK] ModScriptClass

johnycilohoklajohnycilohokla REGISTERED Posts: 283 Developer
edited December 2015 in Modding Tutorials


ModScriptClass is used to define the entry script for mod.
ModScriptClass is not required.
Most mods will need at least a very basic ModScriptClass to add recipes and archetypes.


Adding recipes/archetypes
Registering chat command
Registering keybindings
Defining callbacks & overriding functions
Creating GUI elements

Basic ModScriptClass

if MyModName == nil then
MyModName = EternusEngine.ModScriptClass.Subclass("MyModName")

function MyModName:Initialize()
Eternus.CraftingSystem:ParseRecipeFile("Data/Crafting/GroupName_crafting.txt", "GroupName")

Creating ModScriptClass

[Required] First you will need to create a subclass of ModScriptClass, this part is required for any mod that wants to have a custom entry Lua script.
if ExampleMod == nil then
ExampleMod = EternusEngine.ModScriptClass.Subclass("ExampleMod")

Initializing ModScriptClass

Constructor is called when the mod is created, inside of the constructor you should initialize all of the variables you will access while the mod is running.
function ExampleMod:Constructor(  )
-- ...
-- Example: self.testVariable = "testing"
Initialize is called by the engine when the world is initialized.
register commands
register crafting recipes
register callbacks
create GUIs etc...
function ExampleMod:Initialize()
-- ...
Enter is called by the engine when the game enter new game mode.
create input context (keybinds)
enable (show) GUI elements
function ExampleMod:Enter()
-- ...
Leave is called by the engine when the game leaves it current mode.
remove input context (keybinds)
disable (hide) GUI elements
function ExampleMod:Leave()
-- ...

Saving&Restoring ModScriptClass data

Save System Tutorial

Save is called by the engine every 5 minutes (configurable), the function provides a outData table that can be used to save variables across sessions.
function ExampleMod:Save(outData)
-- Example: outData.variable = self.variable
Restore is called by the engine when loading the world, it provides inData table that contains data from previous session saved by Save function.
function ExampleMod:Restore(inData, version)
-- Example: self.variable = inData.variable

Network Events

Network Events Tutorial

Mods can define network event, exactly the same way game objects can.

Data Serialization

NetStream Tutorial

Mods can define NetSerializeConstruction, NetDeserializeConstruction, NetSerialize, NetDeserialize, exactly the same way game objects can.

Registering ModScriptClass

[Required] Last thing you will need to do is register your ModScriptClass with the EntityFramework.
My Blog
  yt.png  t.png  
Sign In or Register to comment.