RustyNayle Posted March 1, 2016 Share Posted March 1, 2016 (edited) Hi guys, Wanda beta is doing well on Steam, Spoiler Link up the top of her Klei page, But now my daughter wanted me to make a mod character for her, "Wilma the Milkmaid." I have an artist friend that might just re-skin Wigfrid for me to give the traditional Swiss dress look, and the rest of the character is quite a simple concept: generous custom stats, starting inventory, tech tree, and a special recipe. However, I am stuck trying to get her to spawn with an Insulated Pack in her chest slot at the start of the game. It's easy enough for me to type c_give("icepack") for her each time she loads a new server, but I would rather just get it to work. Do I have to clone the Insulated Pack and have the clone look and function the same way, or is there a simpler way to get this to work? I tried adding local prefabs = {"icepack"}, as well as local start_inv = {"icepack"} since the start_inv by itself didn't work, but not working? Also, how do I incorporate another mod into Wilma, such as Beefalo Milk and Cheese? Spoiler https://steamcommunity.com/sharedfiles/filedetails/?id=250583758 ) I tried adding the line modimport("scripts/beefalo_milk_and_cheese.lua") to Wilma's modmain.lua , and copying that file across into the scripts subfolder, not sure if it's that simple? Edited March 1, 2016 by RustyNayle Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/ Share on other sites More sharing options...
osmRhodey Posted March 2, 2016 Share Posted March 2, 2016 There in lies the issue because it's a starting_inv This item isn't spawning as backpacks cannot be held in the inventory, at all. The only way to get it to work would be going around the issue and telling the program to start the game with X item in the chest slot. That or force giving the object upon creation. Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729090 Share on other sites More sharing options...
PanAzej Posted March 2, 2016 Share Posted March 2, 2016 (edited) inst.OnNewSpawn = function(inst) local pack = SpawnPrefab("icepack") inst.components.inventory:Equip(pack) end Put this into your character's master_postinit. Edited March 2, 2016 by PanAzej Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729094 Share on other sites More sharing options...
SenL Posted March 2, 2016 Share Posted March 2, 2016 Awesome. Can you spawn with something already built? Example firesuppressor (so prototyped and built) Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729122 Share on other sites More sharing options...
Muche Posted March 2, 2016 Share Posted March 2, 2016 Try inst.components.builder:UnlockRecipe('firesuppressor') inst.components.builder.buffered_builds['firesuppressor'] = 0 inst.replica.builder:SetIsBuildBuffered('firesuppressor', true) Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729174 Share on other sites More sharing options...
RustyNayle Posted March 2, 2016 Author Share Posted March 2, 2016 (edited) @SenL, if you want to ask your own question about spawning an Ice Flingomatic at the start of the game, then start your own post man, don't spam mine! @PanAzej, are those lines in the master_postinit the only things I need at all, or do I also still need the local start_inv = {"icepack"} and/or local prefabs = {"icepack"}? It still doesn't look like it's working either way. Edited March 2, 2016 by RustyNayle Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729213 Share on other sites More sharing options...
RustyNayle Posted March 2, 2016 Author Share Posted March 2, 2016 @osmRhodey, I have seen some code about chest item slots, which is different to what PanAzej just supplied, so what would said code look like, then? Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729216 Share on other sites More sharing options...
Muche Posted March 2, 2016 Share Posted March 2, 2016 (edited) IMHO, @SenL's question was on topic ("How to spawn with X"). local start_inv = { "icepack" } does nothing by itself at all. It just sets a variable with a value. It has to be used to have an effect. Usually it is used in return MakePlayerCharacter("charactername", prefabs, assets, common_postinit, master_postinit, start_inv) MakePlayerCharacter function is defined in prefabs/player_common.lua, where that start_inv is used in (simplified) inst.OnNewSpawn = function() for i, v in ipairs(start_inv) do inst.components.inventory:GiveItem(SpawnPrefab(v)) end end Thus, the only effective difference from @PanAzej's code is different inventory function used. (And the fact that starting inventory parameter is standardized, thus more commonplace). Edited March 2, 2016 by Muche Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729219 Share on other sites More sharing options...
osmRhodey Posted March 2, 2016 Share Posted March 2, 2016 Yeah like it's being stated above, you can make it possible to spawn with the insulated pack but overall it will make you lose the function of the start_inv. I tried finding a way around this spawning an axe and such but all it does is duplicate. What I wound up with (which you have to remove start_inv from the bottom return section or else it freezes) This goes under the master_postinit section --Starts your spawned inventory with the insulated pack. --This comes at the cost of losing the start_inv function. inst._OnNewSpawn = inst.OnNewSpawn inst.OnNewSpawn = function() local start_inv ={"icepack"} for i, v in ipairs(start_inv) do inst.components.inventory:GiveItem(SpawnPrefab(v)) inst.components.inventory:Equip(SpawnPrefab(v)) end if inst._OnNewSpawn ~= nil then inst:_OnNewSpawn() inst._OnNewSpawn = nil end end Good luck I hope you get it working! Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729239 Share on other sites More sharing options...
Aquaterion Posted March 3, 2016 Share Posted March 3, 2016 (edited) 28 minutes ago, osmRhodey said: Yeah like it's being stated above, you can make it possible to spawn with the insulated pack but overall it will make you lose the function of the start_inv. I tried finding a way around this spawning an axe and such but all it does is duplicate. What I wound up with (which you have to remove start_inv from the bottom return section or else it freezes) This goes under the master_postinit section --Starts your spawned inventory with the insulated pack. --This comes at the cost of losing the start_inv function. inst._OnNewSpawn = inst.OnNewSpawn inst.OnNewSpawn = function() local start_inv ={"icepack"} for i, v in ipairs(start_inv) do inst.components.inventory:GiveItem(SpawnPrefab(v)) inst.components.inventory:Equip(SpawnPrefab(v)) end if inst._OnNewSpawn ~= nil then inst:_OnNewSpawn() inst._OnNewSpawn = nil end end Good luck I hope you get it working! I never done character stuff but can't you do: local item = inst.components.inventory:GiveItem(SpawnPrefab(v)) if item.components.equipable then inst.components.inventory:Equip(item) end in the for loop? not sure what the _OnNewSpawn is for tho.. Edited March 3, 2016 by Aquaterion Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729241 Share on other sites More sharing options...
osmRhodey Posted March 3, 2016 Share Posted March 3, 2016 Just now, Aquaterion said: I never done character stuff but can't you do: local item = inst.components.inventory:GiveItem(SpawnPrefab(v)) if item.components.equippable:IsEquipped() then inst.components.inventory:Equip(item) end in the for loop? not sure what the _OnNewSpawn is for tho.. It was in the coding and otherwise was not working for me if left out. It's just set for when your character spawns in. Good luck though! Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729247 Share on other sites More sharing options...
RustyNayle Posted March 3, 2016 Author Share Posted March 3, 2016 Aargh, still can't get it to work! Thanks so much for your suggestions so far, but do you guys test your code before posting it? So many ways to try and tell the engine to do the same thing, yet not one of them has yet to get it to work...? Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729252 Share on other sites More sharing options...
osmRhodey Posted March 3, 2016 Share Posted March 3, 2016 20 minutes ago, RustyNayle said: Aargh, still can't get it to work! Thanks so much for your suggestions so far, but do you guys test your code before posting it? So many ways to try and tell the engine to do the same thing, yet not one of them has yet to get it to work...? I did multiple times. Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729260 Share on other sites More sharing options...
Muche Posted March 3, 2016 Share Posted March 3, 2016 (edited) 1 hour ago, osmRhodey said: What I wound up with (which you have to remove start_inv from the bottom return section or else it freezes) This goes under the master_postinit section --Starts your spawned inventory with the insulated pack. --This comes at the cost of losing the start_inv function. inst._OnNewSpawn = inst.OnNewSpawn inst.OnNewSpawn = function() local start_inv ={"icepack"} for i, v in ipairs(start_inv) do inst.components.inventory:GiveItem(SpawnPrefab(v)) inst.components.inventory:Equip(SpawnPrefab(v)) end if inst._OnNewSpawn ~= nil then inst:_OnNewSpawn() inst._OnNewSpawn = nil end end If start_inv is set and is passed to MakePlayerCharacter this freezes, because MakePlayerCharacter does the same, i.e. stores your OnNewSpawn function into _OnNewSpawn field, which your function calls and gets into infinite loop. 1 hour ago, Aquaterion said: I never done character stuff but can't you do: local item = inst.components.inventory:GiveItem(SpawnPrefab(v)) if item.components.equipable then inst.components.inventory:Equip(item) end in the for loop? not sure what the _OnNewSpawn is for tho.. It's the standard practice when injecting your code into existing function; you store original function and replace it with your own, which as part of its code calls the original one: object = {} function object.func(params) -- does something end local old_func = object.func function new_func(params) -- do something yours if old_func ~= nil then old_func(params) end end object.func = new_func If you store the old_func in the object itself you can refer to it in other places as well; but if something else uses the same technique and overwrites old_func with new value, the overall result will be incorrect. object = {} function object:func(params) -- does something end local object.old_func = object.func function object:func(params) -- do something yours if self.old_func ~= nil then self:old_func(params) end end Edited March 3, 2016 by Muche Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729277 Share on other sites More sharing options...
RustyNayle Posted March 3, 2016 Author Share Posted March 3, 2016 I tried copying this one from the Elli character ( http://steamcommunity.com/sharedfiles/filedetails/?id=359649743 ), still to no avail... local fn = function(inst) --start inventory inst._OnNewSpawn = inst.OnNewSpawn inst.OnNewSpawn = function() local start_inv ={"icepack"} for i, v in ipairs(start_inv) do inst.components.inventory:GiveItem(SpawnPrefab(v)) inst.components.inventory:Equip(SpawnPrefab(v)) end if inst._OnNewSpawn ~= nil then inst:_OnNewSpawn() inst._OnNewSpawn = nil end end end Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729283 Share on other sites More sharing options...
osmRhodey Posted March 3, 2016 Share Posted March 3, 2016 (edited) 7 minutes ago, RustyNayle said: I tried copying this one from the Elli character ( http://steamcommunity.com/sharedfiles/filedetails/?id=359649743 ), still to no avail... [code i posted earlier] Same one I was referencing actually. Like I said if you want that one to work you need to remove the start_inv return and post it(without the function) under the master_postinit. Spoiler remove the start_inv here. I haven't tested Muches but for the most part their coding can be reliable. But if you just want to have it working for the moment then here. EDIT: also remove the inst.OnNewSpawn = onload Edited March 3, 2016 by osmRhodey Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729286 Share on other sites More sharing options...
RustyNayle Posted March 3, 2016 Author Share Posted March 3, 2016 Ah, finally! Removing the inst.OnNewSpawn = onload line finally got it working. Thanks @osmRhodey! Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729292 Share on other sites More sharing options...
RustyNayle Posted March 3, 2016 Author Share Posted March 3, 2016 Okay, so how do I have Wilma spawn with the icepack using this code, but also have her spawn with a catcoonhat and 4 goatmilk (which used to be in the old start_inv, but have now been cancelled out)? Simply adding the list into the new local start_inv ={ } line doesn't work. Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729295 Share on other sites More sharing options...
Muche Posted March 3, 2016 Share Posted March 3, 2016 local start_inv = { "catcoonhat", "goatmilk", "goatmilk", "goatmilk", "goatmilk" } local function master_postinit(inst) ... inst.OnNewSpawn = function(inst) local pack = SpawnPrefab("icepack") inst.components.inventory:Equip(pack) end end return MakePlayerCharacter("wilma", prefabs, assets, common_postinit, master_postinit, start_inv) should work. Also, where is that inst.OnNewSpawn = onload line you keep mentioning coming from? It seems to give you guys hard times, but it doesn't seem to be mentioned earlier. IMHO, what the main issue here seems to be is, that there are suggested pieces of code, but they are being put together willy-nilly. Posting the whole prefab file could get everybody on the same page. Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729298 Share on other sites More sharing options...
osmRhodey Posted March 3, 2016 Share Posted March 3, 2016 Just now, Muche said: [clean code good code happy code] should work. Also, where is that inst.OnNewSpawn = onload line you keep mentioning coming from? It seems to give you guys hard times, but it doesn't seem to be mentioned earlier. IMHO, what the main issue here seems to be is, that there are suggested pieces of code, but they are being put together willy-nilly. Posting the whole prefab file could get everybody on the same page. the one I was simply basing off of was from a mod the op referred to earlier, Ellie. it wasn't mentioned earlier simply because I forgot about it. The coding isn't really my work I was just trying to get something that could work to help out while I continue faffing around with my own. :'D sorry about that. Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729299 Share on other sites More sharing options...
RustyNayle Posted March 3, 2016 Author Share Posted March 3, 2016 Thanks @Muche, you're a champ! Coding is simple, succint, and it works. Cheers! Link to comment https://forums.kleientertainment.com/forums/topic/65011-how-to-spawn-with-insulated-pack/#findComment-729369 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