Jump to content

Recommended Posts

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

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 by RustyNayle

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.

@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 by RustyNayle

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 by Muche

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!

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 by Aquaterion
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!

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...?

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. :p

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 by Muche

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

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

56d79c360eade_wheretoplacecode.PNG.654b8

remove the start_inv here.

56d79c358508b_removethestart_inv.PNG.d2c

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 by osmRhodey

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.

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.

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...