Character mod helper

by Pi-C

If your mod lets players use a character that looks differently, you'll have to decide whether you must overwrite the default character. This mod will help you with this decision, and make it really simple to overwrite the default or update the new prototypes in a safe way.

Internal
2 months ago
1.1 - 2.0
53.7K
Character

g so if we have a bunch of new characters in one mod, what should we do with that

3 years ago

so if we have a bunch of new characters in one mod, what should we do with that

3 years ago
(updated 3 years ago)

In README/character-mods.txt you'll find the following description

In data.lua:

-- Define character properties
IROBOT = require("__CharacterModHelper__.common")("IRobot")

IROBOT.character                        = { name = "IRobot_character_skin" }
IROBOT.corpse                           = { name = IROBOT.character.name.."-corpse" }

…

-- Create character
local character = table.deepcopy(data.raw["character"]["character"])
CharModHelper.apply_properties(character, IROBOT.character)
data:extend({character})

-- Create corpse
local corpse = table.deepcopy(data.raw["character-corpse"]["character-corpse"])
CharModHelper.apply_properties(corpse, IROBOT.corpse)
data:extend({corpse})


In data-final-fixes.lua:

-- Keep or overwrite the default prototypes?                   --
CharModHelper.check_my_prototypes(IROBOT)

If you have multiple characters, the easiest way is to add more levels to the table and loop over them.

In data.lua:

-- Define character properties
IROBOT = require("__CharacterModHelper__.common")("IRobot")
IROBOT.skins = {}

IROBOT.skins.name1 = {}
IROBOT.skins.name1.character       = { name = "IRobot_character_skin" },
IROBOT.skins.name1.corpse          = { name = IROBOT.skins.name1.character.name.."-corpse" }

IROBOT.skins.name2 = {}
IROBOT.skins.name2.character       = { name = "second_character_skin" },
IROBOT.skins.name2.corpse          = { name = IROBOT.skins.name2.character.name.."-corpse" }

…

-- Create prototypes
local character, corpse

for name, prototypes in pairs(IROBOT.skins) do
  character = table.deepcopy(data.raw["character"]["character"])
  corpse = table.deepcopy(data.raw["character-corpse"]["character-corpse"])

  CharModHelper.apply_properties(character, prototypes.character)
  CharModHelper.apply_properties(character, prototypes.corpse)

  data:extend({character, corpse})
end

In data-final-fixes.lua:

-- Keep or overwrite the default prototypes?                   --
for name, prototypes in pairs(IROBOT.skins) do
  CharModHelper.check_my_prototypes(prototypes)
end
1 year, 1 month ago

а можно обьеснить для не знакомых с программированием людей?

1 year, 1 month ago

Sorry, my Russian is not good enough for this. Google translated this as "Can you be visible for people who are not familiar with people's programming?", but that doesn't really make sense. If you want a better explanation, unpack the mod and look at the files in the README folder. Does that help, or did you mean something different?

New response