[0.8.9][NK] ModScriptClass

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

ModScriptClass

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.

Usage

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")
end

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

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")
end

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"
end
Initialize is called by the engine when the world is initialized.
Usage:
register commands
register crafting recipes
register callbacks
create GUIs etc...
function ExampleMod:Initialize()
-- ...
end
Enter is called by the engine when the game enter new game mode.
Usage:
create input context (keybinds)
enable (show) GUI elements
function ExampleMod:Enter()
-- ...
end
Leave is called by the engine when the game leaves it current mode.
Usage:
remove input context (keybinds)
disable (hide) GUI elements
function ExampleMod:Leave()
-- ...
end

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
end
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
end

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.
EntityFramework:RegisterModScript(ExampleMod)
My Blog
jc.png
  yt.png  t.png  
Sign In or Register to comment.