ModUtil

Modutil functions can only be accessed from modmain.lua and modwordgenmain.lua. Outside of them, functions got from require "modutil" are a bit different from the ones you have here. You may read InsertPostInitFunctions() for information on how the functions are wrapped.

NameArgumentsReturnsNotes
AddLevelPreInitlevelid, fn
AddLevelPreInitAnyfnAdds a preinit to all levels.
TaskPreInittaskname: string, fn
RoomPreInitroomname: string, fn
AddLevel...Wrapper for AddLevel(...) in maps/levels.
AddTaskSet...Wrapper for AddTaskSet(...) in maps/tasks.
AddTask...Wrapper for AddTask(...) in maps/tasks.
AddRoom...Wrapper for AddRoom(...) in maps/rooms.
AddGameModegame_mode, game_mode_textDEPRECATED. See the matching chapter for hints on adding a GameMode.
GetModConfigDataoptionname: string, get_local_configData, as in the config.
AddGamePostInitfn
AddSimPostInitfn
AddGlobalClassPostConstructpackage, classname, fn
AddClassPostConstructpackage, fn
__ISWORLDGENisworldgen: boolAll functions below this line are only available in Main.
AddActionid, str, fn
action: Action
action added in the table.
AddComponentActionactiontype, component, fnJust calls AddComponentAction(actiontype, component, fn, env.modname)
AddMinimapAtlasatlaspathInserts into a table. Same for below.
AddStategraphActionHandlerstategraph, handler
AddStategraphStatestategraph, state
AddStategraphEventstategraph, event
AddStategraphPostInitstategraph, fn
AddComponentPostInitcomponent, fn
AddPrefabPostInitAnyfnSee the chapter. Make sure you know what you are doing.
AddPlayerPostInitfnAn example to filter the types of AddPrefabPostInitAny. Messes up initprint due to 4-level stacktrace.
AddBrainPostInitbrain, fnIt's quite tricky to change the brain nodes so be sure to read the chapter.
AddIngredientValuesnames, tags, cancook, candryWraps AddIngredientValues() in "cooking".
AddCookerRecipecooker, recipeDitto, but adds the value into cookerrecipes[cooker].
AddModCharactername, genderCalls the local function AddModCharacter().
RemoveDefaultCharacternameDitto.
AddRecipe...Recipe(...)Wraps the Recipe() class from "recipe". Sets Mod RPC ID for the recipe.
RecipeWraps AddRecipe.
AddRecipeTabrec_str, rec_sort, rec_atlas, rec_icon, rec_owner_tag{ str = rec_str, sort = rec_sort, icon_atlas = rec_atlas, icon = rec_icon, owner_tag = rec_owner_tag }Sets CUSTOM_RECIPETABS[rec_str] to the to-be-returned table, and sets STRINGS.TABS[rec_str] = rec_str.
LoadPOFilepath, langUses the Tranlator class's LoadPOFile(). Loads translations from the PO file.
RemapSoundEventname, new_nameDoes TheSim:RemapSoundEvent(name, new_name)
AddReplicableComponentCalls local AddReplicableComponent().
AddModRPCHandlernamespace, name, fnDitto.
SendModRPCToServerid_table, ...Ditto.
SetModHUDFocusfocusid, hasfocusThePlayer.HUD:SetModFocus(env.modname, focusid, hasfocus)
AddVoteCommandcommand_name, init_options_fn, process_result_fn, vote_timeout = 15Sets env.vote_commands[command_name] = { InitOptionsFn = init_options_fn, ProcessResultFn = process_result_fn, Timeout = vote_timeout }.

GetModConfigData (string, get_local_config)

Notice that this function is called differently in modutil.lua, but used in the mods environment as seen above. It allows you to read configuration data set in modinfo.lua.

AddModCharacter (string)

This is used (in modmain.lua, mind you) to make your custom characters show up in the select screen, morgue, and generally work. Give it the mod characters name in form of a string.

PostInit functions, etc

The ModUtil gives special functions to a mods modmain.lua environment for editing scripts without overriding them. Using those functions allows several mods to edit the same things and do so with variables only available in modmain or the mod (e.g. mod config options).

AddPrefabPostInit(“prefab”, function)

AddPrefabPostInitAny

Same as AddPrefabPostInit, expect it fires for all prefabs in the loaded game (and thus doesn’t require the first argument). That’s nuts if you think about it.

AddPlayerPostInit

“An illustrative example of how to use a global prefab post init, in this case, we’re making a player prefab post init.” However, do not use the game implementation of this function, as it crashes the game if the user enabled initprint (initprint follows the stack back, but only for 3 function calls. Using this, it’d have to go 4 back.) . You can copy the “if” block though.

AddComponentPostInit

AddClassPostConstruct

This function is used to modify a generic class from widgets, screens, etc.

 AddSimPostInit

Fires after loading the world, the only argument given to it is the player character.

AddGamePostInit

Also known as “PostEnv”, this seems to fire whenever Check_Mods fires (that’s means its effects should apply pretty much always). Forum Post by simplex

AddStategraphPostInit

This is used to edit a stategraph, it recieves the stategraph as an argument.

AddStategraphState

This is used to add a State(…) to a stategraph (or overwrite one), and can be used with AddStategraphPostInit.

AddBrainPostInit

This can be used to adjust a creatures behaviour. It is very complicated. Here’s the API example: