TequilaSeLai Posted July 27, 2021 Share Posted July 27, 2021 Hey guys, I've made a few very minor mods in the past, but I'm working on something out of my wheelhouse now and finding myself completely clueless - both on how to implement and whether it's even allowed. I wanted a clone of the basic wooden chest that behaves a just little differently. Easy enough; I grabbed a couple mods that introduced larger chests and linked chests and worked out what I needed and what I didn't to create my basic mod. But now my question is: is it possible/allowed to set up a modded item to allow players to use their skins when constructing it, exactly as if they were building a standard wooden chest? If so, where would I start looking for guidance (whether a tutorial, another thread, or another mod that already does this)? I have exhausted my google-fu and made no progress. Right now I have a functional mod, but every chest just looks exactly like the plain wooden chest that every camp already has a half a million of, and it'd be nice to have a visual indicator that "this is your special chest." I recognize that I could just make all my regular chests look different when I'm building them, but if it's possible to make a more robust mod, then I'd rather do that. And obviously (I hope) I'm only asking about using the chest skins players already own; I'm not trying to make every skin available to everyone or anything stupid. Link to comment https://forums.kleientertainment.com/forums/topic/132190-using-base-game-skins-on-a-modded-item/ Share on other sites More sharing options...
Monti18 Posted July 27, 2021 Share Posted July 27, 2021 I don't know if you are allowed to use official skins for your items, even if you let the player only use the skins they have. You could probably make it somehow with this. but I'm not sure if this will work. A better alternative that should also be allowed would be to add your changes to the treasurechest prefab with a AddPrefabPostInit, add a new recipe for the treasurechest with the costs that you want for your chest and then use AddPlayerPostInit to add a ListenForEvent function that listens for "buildstructure". self.inst:PushEvent("buildstructure", { item = prod, recipe = recipe, skin = skin }) This is the line in builder.lua that pushes the event as you can see, where also the item is transmitted with the data. In your ListenForEvent, you then activate the changes that you made to the chest and make sure to save them so that they are still there when you reload the world. Small example of what I mean: Spoiler --Modmain --adding a new recipe for the new chest local AllRecipes = GLOBAL.AllRecipes local RECIPETABS = GLOBAL.RECIPETABS local STRINGS = GLOBAL.STRINGS local TECH = GLOBAL.TECH local treasurechest_sortkey = AllRecipes["treasurechest"]["sortkey"] local treasurechest2 = AddRecipe("treasurechest2", {Ingredient("twigs", 10)}, RECIPETABS.TOWN, TECH.NONE) treasurechest2.product = "treasurechest" treasurechest2.image = "treasurechest.tex" treasurechest2.sortkey = treasurechest_sortkey + 0.1 treasurechest2.numtogive = 1 STRINGS.NAMES.TREASURECHEST2 = "Another treasurechest" STRINGS.RECIPE_DESC.TREASURECHEST2 = "Seriously." --changing the chest to what you want local function ChangingProperties(inst) --your code for the changes inst.newchest = true end AddPrefabPostInit("treasurechest",function(inst) inst.newchest_code = ChangingProperties(inst) if not GLOBAL.TheWorld.ismastersim then return inst end inst.newchest = false local old_onsave = inst.OnSave inst.OnSave = function(inst,data) if inst.newchest == true then data.newchest== true end if old_onsave ~= nil then return old_onsave end end local old_onload = inst.OnLoad inst.OnLoad = function(inst,data) if data.newchest == true then inst.newchest_code(inst) end if old_onload ~= nil then return old_onload end end end) --adding a listener to change the chest if it should be your version local function ChangeChest(inst,data) if data then if data.item and data.item == "treasurechest" then if data.recipe and data.recipe.name == "treasurechest2" then data.item.newchest_code(inst) end end end end AddPlayerPostInit(function(inst) if not GLOBAL.TheWorld.ismastersim then return inst end inst:ListenForEvent("buildstructure",ChangeChest) end) This is not tested, so there could be some errors in there, but in theory it should work 2 Link to comment https://forums.kleientertainment.com/forums/topic/132190-using-base-game-skins-on-a-modded-item/#findComment-1482151 Share on other sites More sharing options...
TequilaSeLai Posted July 27, 2021 Author Share Posted July 27, 2021 5 hours ago, Monti18 said: A better alternative that should also be allowed would be to add your changes to the treasurechest prefab with a AddPrefabPostInit, add a new recipe for the treasurechest with the costs that you want for your chest and then use AddPlayerPostInit to add a ListenForEvent function that listens for "buildstructure". Awesome thought, hadn't even occurred to me. That should be enough to get me going, thank you so much! Link to comment https://forums.kleientertainment.com/forums/topic/132190-using-base-game-skins-on-a-modded-item/#findComment-1482248 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