This mod template adds a new custom component.
Code[edit | edit source]
def.json[edit | edit source]
Content
{
"id": "ModTemplateComponent",
"name": "Mod Template Component",
"version_name": "1.0",
"version_code": 1,
"author": "The Desynced Team",
"homepage": "https://www.desyncedgame.com/",
"description": "Mod Template Component",
"packages": {
"Data": {
"name": "Data",
"entry": "data.lua",
"dependencies": [ "Main/Data" ],
"type": "Addon"
}
}
}
data.lua[edit | edit source]
Content
local package = ...
-- files loaded when mod is initializing
package.includes = {
"components.lua",
}
-- called when mod is initializing
function package:init()
end
components.lua[edit | edit source]
Content
-- define and register a custom component, the ID needs to be unique
local c_mod_self_teleport = Comp:RegisterComponent("c_mod_self_teleport", {
name = "Magical Self Teleporter",
desc = "Teleport unit to location specified in register",
texture = "Main/textures/icons/components/Component_UnitTeleporter_01_L.png",
slot_type = "storage",
attachment_size = "Internal",
visual = "v_generic_i",
activation = "OnFirstRegisterChange",
registers = { { tip = "Coordinate" } },
})
-- callback called when the component is activated
function c_mod_self_teleport:on_update(comp)
local coord = comp:GetRegisterCoord(1)
if coord then
-- have a coordinate, teleport the owner there
Map.Defer(function() comp.owner:Place(coord.x, coord.y) end)
end
end
Modding | |
Templates |