Spoderthewhiteknight Posted August 4, 2016 Share Posted August 4, 2016 I was wondering if anyone could help me here. I wanted to know if there was a way to make my character be able to spawn with a Dark Sword by toggling it on in the mod menu. and have the option to leave it and have him spawn sword-less Link to comment Share on other sites More sharing options...
PanAzej Posted August 4, 2016 Share Posted August 4, 2016 --- in master_postinit --- inst.OnNewSpawn = function (inst) if some value then local sword = SpawnPrefab("nightsword") inst.components.inventory:GiveItem(sword) end end Something like that? Link to comment Share on other sites More sharing options...
Spoderthewhiteknight Posted August 4, 2016 Author Share Posted August 4, 2016 (edited) I keep putting it in Master_postinit but the the configuration doesn't show up when enabling the mod. and if i host a game with it the game crashes. I get the error msg 'then' expected near 'value' Edited August 4, 2016 by Spoderthewhiteknight Link to comment Share on other sites More sharing options...
DarkXero Posted August 4, 2016 Share Posted August 4, 2016 To make something configurable, you add an option in configuration_options in modinfo. Example: configuration_options = { { name = "start_dark_sword", label = "Start With Dark Sword", options = { {description = "Yes", data = true}, {description = "No", data = false} }, default = true, }, } Now we retrieve in modmain, the value of the configuration: GLOBAL.TUNING.WAFFLES_START_WITH_DARK_SWORD = GetModConfigData("start_dark_sword") and we store it in the tuning table of the game with a unique identifier. Now in our character prefab we have access to that value in the tuning table. For example, my character starts with two meat, and one optional dark sword: local start_inv = { "meat", "meat", } if TUNING.WAFFLES_START_WITH_DARK_SWORD then table.insert(start_inv, "nightsword") end If the value stored is true, then we get a sword in our starting inventory. start_inv is a parameter of the MakePlayerCharacter function at the end of our character prefab file. return MakePlayerCharacter("waffles", prefabs, assets, common_postinit, master_postinit, start_inv) Link to comment Share on other sites More sharing options...
Spoderthewhiteknight Posted August 4, 2016 Author Share Posted August 4, 2016 Thank you both alot for the help. Its working now. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now