RevelHalcyon Posted July 31, 2019 Share Posted July 31, 2019 I'm working on a patch for my Bird character Wren, and decided to attempt a more aesthetic addition to her mechanics. She behaves mostly like a caged bird in her ability to produce seeds and eggs, as well as guano; however it always bothered me that birds produce something named so specifically as bat poo. I noticed in the single player Hamlet DLC that you can modify an item instance quite extensively upon creation, changing its name, inventory icon, scale and all such things; but I'm having some troubles replicating this effect Quote local assets= { Asset("ANIM", "anim/bat_leather.zip"), Asset("INV_IMAGE", "bat_leather"), } local function fn(Sim) local inst = CreateEntity() local newinst = SpawnPrefab("pigskin") newinst.name = STRINGS.NAMES.BAT_HIDE newinst.components.inventoryitem:ChangeImageName("bat_leather") newinst.AnimState:SetBank("bat_leather") newinst.AnimState:SetBuild("bat_leather") newinst.imagenameoverride = "bat_leather" newinst.animbankoverride = "bat_leather" newinst.animbuildoverride = "bat_leather" newinst.nameoverride = "BAT_HIDE" inst:Remove() return newinst end return Prefab( "common/inventory/bat_hide", fn, assets) Here's the bat_hide.lua prefab for reference. I don't wish to change the icon or general appearance of the guano, so I simply ignored the AnimState and animbuild overrides. I set the name literally to "Processed Seeds" as a way to avoid including a modded version of strings.lua in my character mod. Whatever I do, the name always reverts back to Guano upon relogging (even renaming it to "egg" just as a test by setting its instance.name to STRINGS.NAMES.BIRD_EGG and the nameoverride to BIRD_EGG still reverts it to Guano upon saving and reloading the game.) I'm lost as to why this is happening, so any help would be appreciated. The desired effect is to simply permanently rename her spawned instances of guano to "processed seeds" as is achieved with bat hide in hamlet. Link to comment https://forums.kleientertainment.com/forums/topic/109796-disguising-one-item-as-another-bat_hide-from-hamlet/ Share on other sites More sharing options...
. . . Posted July 31, 2019 Share Posted July 31, 2019 Just add this to the poop which spawns inst:AddComponent("named") inst.components.named.possiblenames = {"Bird Manure"} inst.components.named:PickNewName() though the name will likely turn to guano if you merge it with guano or vice-versa Link to comment https://forums.kleientertainment.com/forums/topic/109796-disguising-one-item-as-another-bat_hide-from-hamlet/#findComment-1236966 Share on other sites More sharing options...
RevelHalcyon Posted July 31, 2019 Author Share Posted July 31, 2019 Interesting solution. I really should just look through the entire components directory to see what kinds of things exist. Unfortunately it has the same problem as my previous bat_hide-based solution. It reverts to guano when the game is reloaded Link to comment https://forums.kleientertainment.com/forums/topic/109796-disguising-one-item-as-another-bat_hide-from-hamlet/#findComment-1236973 Share on other sites More sharing options...
Thomas_klei Posted July 31, 2019 Share Posted July 31, 2019 (edited) i think that you could still use warbucks' code but simply add a function that just knows when the world is reloaded then repeats the process i can give a basic example that might not work local function onload(inst) if inst:hastagg("frombird") inst:AddComponent("named") inst.components.named.possiblenames = {"Bird Manure"} inst.components.named:PickNewName() end inst.OnLoad = onload i hope this helps, the idea is that you could add a function that gives it a tagg that could be used to identify it as a different object, this could be used later for more perks. you could do this, or just use a periodic task which basically continuously updates it Edited July 31, 2019 by thomas4845 Link to comment https://forums.kleientertainment.com/forums/topic/109796-disguising-one-item-as-another-bat_hide-from-hamlet/#findComment-1236987 Share on other sites More sharing options...
IronHunter Posted July 31, 2019 Share Posted July 31, 2019 Quano is also the term used for seabird poop which is loaded with nutrients for plants. Which is probably why it fertilizes them more efficiently than regular poop. They probably just lumped all birds excrement together for simplicity. As most people probably wouldn't know the difference for a game. It seems you got your answers so I figure this was just fun trivia. 1 Link to comment https://forums.kleientertainment.com/forums/topic/109796-disguising-one-item-as-another-bat_hide-from-hamlet/#findComment-1236998 Share on other sites More sharing options...
RevelHalcyon Posted July 31, 2019 Author Share Posted July 31, 2019 Alright. I had a look around the named.lua component and it seems like the solution Warbucks suggested SHOULD be working. It seems to contain logic for saving and loading the stored name in itself. I still tried to do as thomas4845 suggested and that did the exact same thing. Worked initially, reverted to guano upon reloading. Just for the sake of testing, I just rewrote her to drop eggs instead of guano, and attempted to turn that egg into guano (so this way I'm using pre-existing assets and just testing the functionality of these functions themselves.) I did it the exact same way bat_hide does, and it still yielded the same results. It changed initially, works perfectly, but upon reloading the game it reverts to its default state based on the prefab it actually is. I'm beginning to think there's some fundamental difference between DS and DST here that may be contributing to my problem. Link to comment https://forums.kleientertainment.com/forums/topic/109796-disguising-one-item-as-another-bat_hide-from-hamlet/#findComment-1237026 Share on other sites More sharing options...
Thomas_klei Posted August 1, 2019 Share Posted August 1, 2019 (edited) in don't starve singleplayer it seems to create a whole new file then change the existing file, bat_hide is basically a reskin of pigskin so it keeps the properties i think as seen with 13 hours ago, RevelHalcyon said: local newinst = SpawnPrefab("pigskin") i think your trying to alter the file itself instead of trying to do local function fn(Sim) local inst = CreateEntity() local newinst = SpawnPrefab("guano") newinst.name = "processed seeds" newinst.nameoverride = "processed_seeds" inst:Remove() return newinst end return Prefab( "common/inventory/processed_seeds", fn, assets) this is basically a whole new file that can be used Edited August 1, 2019 by thomas4845 Link to comment https://forums.kleientertainment.com/forums/topic/109796-disguising-one-item-as-another-bat_hide-from-hamlet/#findComment-1237308 Share on other sites More sharing options...
RevelHalcyon Posted August 1, 2019 Author Share Posted August 1, 2019 Bah. I created a new prefab for it, in the exact style of bat_hide and it does the exact same thing. It works initially then reverts to guano upon reloading the world. I think DST just isn't saving the same kind of item information as DS or something. I'm about to give up on this idea and just leave it called guano. Link to comment https://forums.kleientertainment.com/forums/topic/109796-disguising-one-item-as-another-bat_hide-from-hamlet/#findComment-1237708 Share on other sites More sharing options...
Serpens Posted August 2, 2019 Share Posted August 2, 2019 (edited) Can you show us your code where you change the name? I mean what event or function do you use for it, to differentiate between bat guano and bird poo? (just want to know to test it myself) after some testing... it seems that the save/load from the named component is sufficient, so all I had to do was adding the named component and ingame I named it via console and the SetName function to sth. after loading the same name was still active. Of course you have to add the named component during AddPrefabPostInit. Edited August 2, 2019 by Serpens Link to comment https://forums.kleientertainment.com/forums/topic/109796-disguising-one-item-as-another-bat_hide-from-hamlet/#findComment-1237914 Share on other sites More sharing options...
RevelHalcyon Posted August 2, 2019 Author Share Posted August 2, 2019 (edited) Alright. Originally I was doing it right where the instance was created; that is inside the character prefab itself as a on-chance response to eating seeds as seen here: my first attempt was to simply emulate what the bat_hide did and use the commands to change the objects name. if food.components.edible.foodtype == FOODTYPE.SEEDS then --Spawn a poop if math.random() < 0.5 then local loot = inst.components.lootdropper:SpawnLootPrefab("guano") loot.Transform:SetScale(.5, .5, .5) loot.name = "Processed Seeds" loot.nameoverride = "PROCESSED_SEEDS" end My second attempt was to use Warbuck's suggestion and attempt to add the named component and utilize that instead as seen here: if food.components.edible.foodtype == FOODTYPE.SEEDS then --Spawn a poop if math.random() < 0.5 then local loot = inst.components.lootdropper:SpawnLootPrefab("guano") loot.Transform:SetScale(.5, .5, .5) loot:AddComponent("named") loot.components.named.possiblenames = {"Processed Seeds"} loot.components.named:PickNewName() loot.components.named:SetName("Processed Seeds") end I also tried a variation of this where I attempted thomas4845's first suggestion to add a tag to the loot instance "frombird" and included a modified guano.lua which checks itself for the tag and renames itself on creation. At this point I attempted to just emulate what bat_hide does; that is I created a new prefab called processed_seeds.lua and included it as an asset to the mod and my character so she can spawn them in the same way. So rather than SpawnLootPrefab("guano") she does SpawnLootPrefab("processed_seeds") here's that prefab. local assets= { } local function fn(Sim) local inst = CreateEntity() local newinst = SpawnPrefab("guano") newinst.nameoverride = "PROCESSED_SEEDS" newinst.Transform:SetScale(.5, .5, .5) newinst:AddComponent("named") newinst.components.named.possiblenames = {"Processed Seeds"} newinst.components.named:PickNewName() newinst.components.named:SetName("Processed Seeds") inst:Remove() return newinst end return Prefab( "common/inventory/processed_seeds", fn, assets) This too underwent two versions. One where it does literally what bat_hide.lua does, and this one where I tried Warbuck's named component solution again. Absolutely all of the above solutions and variations ended with the same result; it successfully spawns an item that is guano but called "processed seeds" that reverts to calling itself "guano" upon reloading the game. At this moment I'm considering that since Guano is used for nothing but fertilizer and fire fuel, I could just create a new item, called what I want, that is just a modified Guano. I just wanted to get that extra functionality bat hide has where it can stack with pig skin and be used in recipes wherever pigskin can. I'd hoped to future-proof my mod this way, that is to say if any official content or other mods use guano in new recipes, her poop would work. Alternatively I can just continue to make her poop guano and call it a day. Edited August 2, 2019 by RevelHalcyon Link to comment https://forums.kleientertainment.com/forums/topic/109796-disguising-one-item-as-another-bat_hide-from-hamlet/#findComment-1237932 Share on other sites More sharing options...
Serpens Posted August 2, 2019 Share Posted August 2, 2019 (edited) your second code is already the solution, when you add to modmain: AddPrefabPostInit("guano",function(inst) inst:AddComponent("named") end This is because when loading a game, all components are removed and must be added again. With your current code you never add named after loading the game. and you can remove in your second code the lines: loot:AddComponent("named") loot.components.named.possiblenames = {"Processed Seeds"} loot.components.named:PickNewName() because SetName is enough (possiblenames and picknewname are only needed if you want randomly choose a name of a list of names) Edited August 2, 2019 by Serpens Link to comment https://forums.kleientertainment.com/forums/topic/109796-disguising-one-item-as-another-bat_hide-from-hamlet/#findComment-1237971 Share on other sites More sharing options...
RevelHalcyon Posted August 2, 2019 Author Share Posted August 2, 2019 Aha! I had no idea that tags and components added post-launch weren't saved. I suppose that makes a lot of sense, otherwise literally everything would need to check to see if it was modified when saving the game. I got it working now, thanks a lot dude! Link to comment https://forums.kleientertainment.com/forums/topic/109796-disguising-one-item-as-another-bat_hide-from-hamlet/#findComment-1238100 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