Jump to content

question about woby item saving mechanics


Recommended Posts

I'm trying to add woby to wendy and it worked ( just for solo playing) but unlike walter's woby wendy's woby just lose all item when i disconnect and reconnect. I tried to paste walter lua into wendy and change all walter name into wendy and it doesn;t work, did the same for SGwobysmall changed all walter into wendy, he still lose items. If any developer read this can you please tell me where I need to fix in order for woby to not lose item when disconnected? TY!

Link to comment
Share on other sites

Sounds like you're modding the game, so I'd recommend a post like this be posted in The Mods and Tools subforum.

https://forums.kleientertainment.com/forums/forum/79-dont-starve-together-mods-and-tools/


As for having Woby keep her items, that's handled in Walter's OnSave and OnLoad functions:

Spoiler

prefabs/walter.lua


local function OnSave(inst, data)
	data.woby = inst.woby ~= nil and inst.woby:GetSaveRecord() or nil
end

local function OnLoad(inst, data)
	if data ~= nil and data.woby ~= nil then
		inst._woby_spawntask:Cancel()
		inst._woby_spawntask = nil

		local woby = SpawnSaveRecord(data.woby)
		inst.woby = woby
		if woby ~= nil then
			if inst.migrationpets ~= nil then
				table.insert(inst.migrationpets, woby)
			end
			woby:LinkToPlayer(inst)

	        woby.AnimState:SetMultColour(0,0,0,1)
            woby.components.colourtweener:StartTween({1,1,1,1}, 19*FRAMES)
			local fx = SpawnPrefab(woby.spawnfx)
			fx.entity:SetParent(woby.entity)

			inst:ListenForEvent("onremove", inst._woby_onremove, woby)
		end
	end
end

 

 

 

You'll need to combine the OnSave and OnLoad functions from both Walter and Wendy. The easiest way would be by just copy-pasting their contents together, so they look something like this:

Spoiler

prefabs/wendy.lua


local function OnSave(inst, data)
	data.woby = inst.woby ~= nil and inst.woby:GetSaveRecord() or nil
    if inst.questghost ~= nil then
        data.questghost = inst.questghost:GetSaveRecord()
    end
end

local function OnLoad(inst, data)
	if data ~= nil and data.woby ~= nil then
		inst._woby_spawntask:Cancel()
		inst._woby_spawntask = nil

		local woby = SpawnSaveRecord(data.woby)
		inst.woby = woby
		if woby ~= nil then
			if inst.migrationpets ~= nil then
				table.insert(inst.migrationpets, woby)
			end
			woby:LinkToPlayer(inst)

	        woby.AnimState:SetMultColour(0,0,0,1)
            woby.components.colourtweener:StartTween({1,1,1,1}, 19*FRAMES)
			local fx = SpawnPrefab(woby.spawnfx)
			fx.entity:SetParent(woby.entity)

			inst:ListenForEvent("onremove", inst._woby_onremove, woby)
		end
	end
    if data ~= nil then
		if data.abigail ~= nil then -- retrofitting
			inst.components.inventory:GiveItem(SpawnPrefab("abigail_flower"))
		end

        if data.questghost ~= nil and inst.questghost == nil then
            local questghost = SpawnSaveRecord(data.questghost)
            if questghost ~= nil then
                if inst.migrationpets ~= nil then
                    table.insert(inst.migrationpets, questghost)
                end
                questghost.SoundEmitter:PlaySound("dontstarve/common/ghost_spawn")
                questghost:LinkToPlayer(inst)
            end
        end
    end
end

 

 

 

This kind of approach may break if Klei ever updates the save/load functions of these characters, though, so you'll need to re-do it if that ever happens.

Link to comment
Share on other sites

omg thank yoiu so much for immediate response yes i'm a noob here and i'm actually tweaking it in my data file i have no idea how to make mods which would be safer, instead i tweak directly at the databundle script files the main one. I'll give that a try and see if i can get it to work thank you so much!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
×
  • Create New...