Toggle search
Search
Toggle menu
Toggle personal menu
Editing
Modding/Templates/Component
From Desynced Wiki
Read
Edit
Edit source
View history
Page
Discussion
More actions
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
__FORCETOC__ This mod template adds a new custom component. == Code == === def.json === Content<syntaxhighlight lang="json"> { "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" } } } </syntaxhighlight> === data.lua === Content<syntaxhighlight lang="lua"> local package = ... -- files loaded when mod is initializing package.includes = { "components.lua", } -- called when mod is initializing function package:init() end </syntaxhighlight> === components.lua === Content<syntaxhighlight lang="lua"> -- 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 </syntaxhighlight> {{ModdingNav}}
Summary:
Please note that all contributions to Desynced Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Desynced Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:ModdingNav
(
edit
)
Template:Navbox
(
edit
)