Jump to content

Perks Only Work When Re-Hosting World And Cannot Save Data


Recommended Posts

I created a Wolfgang mod with Warly perks and it works perfectly fine when re-hosting world, yet when Wolfgang spawns for the first time..

Only the Warly perks seem to be functioning and I can't seem to figure out why Wolfgang's perks are not functioning when he spawns, only when I re-host the world. 

My other issue is Wolfgang has Warly's perk of 1.75 day food abstinence, while it functions in-game, soon as you re-host the world, all the food he already consumed in the previous past days is suddenly forgotten.

I think the following line of code might be wrongly scripted or be causing these issues. 

 

    local function refresh_consumed_foods(inst)
	local to_remove = {}
	for k,v in pairs(inst.consumed_foods) do
		if GetTime() >= v.time_of_reset then
			table.insert(to_remove, k)
		end
	end

	for k,v in pairs(to_remove) do
		inst.consumed_foods[v] = nil
	end
end
		local function OnSave(inst, data)
	local consumed_foods = {}
	for k,v in pairs(inst.consumed_foods) do
		consumed_foods[k] = {}
		consumed_foods[k].count = v.count
		consumed_foods[k].time_of_reset = v.time_of_reset - GetTime()
	end
	data.consumed_foods = consumed_foods
end

local function onload(inst, data)

	if data and data.consumed_foods then
		inst.consumed_foods = data.consumed_foods
	end
	end

local _Eat = inst.components.eater.Eat
	inst.components.eater.Eat = function(self, food)
		OnEat(self.inst, food)
		return _Eat(self, food)
	end
	
	inst.consumed_foods = {}


local function LongUpdate(inst, dt)
	for k,v in pairs(inst.consumed_foods) do
		v.time_of_reset = v.time_of_reset - dt
	end
	refresh_consumed_foods(inst)
end

-- The upper part  is all the code I believe is related to the saving the food data consumed when rehosting the world. 

inst.OnNewSpawn = equipewarlychefpack
inst.OnLongUpdate = LongUpdate

-- The instances of spawning and preloading might be the ones breaking Wolfgang's perks line of code?

	inst.OnPreLoad = onpreload
    inst.OnLoad = onload
	
	inst:ListenForEvent("mounted", OnMounted)
    inst:ListenForEvent("dismounted", OnDismounted)

 

If someone could please figure out the reasons behind these bugs, I would appreciate it.

 

wolfgang.lua

Link to comment
Share on other sites

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
 Share

×
  • Create New...