Jump to content

How to reduced speed when wet? & vegetable penalty (help)


m9m3x3

Recommended Posts

I'm sorry about the frequent questions.

i only want the speed to decrease when the character wet.

 

And I want to make sure that the character can eat vegetables, but not recover sanity and health by eating them.

Thank you for your time.

Link to comment
Share on other sites

You can listen for the event of a change in moisture by listening to the "moisturechange" event on your player, and then determine a threshold for how wet the character must be in order to get the speed decrease. Something like this:

inst.hasmoisturedebuff = false
inst:ListenForEvent("moisturechange", function(inst, data)
	if inst.hasmoisturedebuff then
		if data.new <= 0 then
			inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "mymoisturedebuffmodifierkey")
		end
	else
		if data.new > 0 then
			-- Make the speed 80% of normal speed.
			inst.components.locomotor:SetExternalSpeedMultiplier(inst, "mymoisturedebuffmodifierkey", 0.80)
		end
	end
end)

 

Link to comment
Share on other sites

There is a problem with changing what a character gets from eating foods in DST. For different reasons, you cannot alter the foods at any stage before the character eats it, so you can only intercept the code just after the food benefits have been applied. So all you can do, is force a decrease equal to the amount the character was given, which is not ideal (edge cases e.g. if you have full sanity and the food adds sanity, then it won't add any, and you will then still subtract the amount) but that's the best you can do.

-- Put this line in your the master_postinit of you character LUA
inst.components.eater:SetOnEatFn(OnEat)


-- Put this function somewhere above your character's master_postinit

local function OnEat(inst, food)
	if food and food.edible then
		if food.edible.healthvalue > 0 then
			inst.components.health:DoDelta(-food.edible.healthvalue)
		end
		if food.edible.sanityvalue > 0 then
			inst.components.sanity:DoDelta(-food.edible.sanityvalue)
		end
	end
end

 

Link to comment
Share on other sites

UPDATE: Just fixed the code. I checked, and carrots and the like do not have any tags as "vegetable" or something, but their foodtype is set to "VEGGIE", so we first check for that. If you need to remove other foods which are not excluded by the "VEGGIE" check, Just add all the vegetables you want in that list of prefabs called "inedibles" you can just add all the prefabs you want in that list of prefabs called "inedibles". A left a few examples there commented out.

-- You can additionally remove foods here which do not have the VEGGIE foodtype.
local inedibles = {
	-- "carrot",
	-- "corn",
}

if inst.components.eater then
	local old_CanEat = inst.components.eater.CanEat
	inst.components.eater.CanEat = function(self, food_inst)
		if food_inst.components.edible.foodtype = "VEGGIE" then
			return false
		end
		for i, v in ipairs(inedibles) do
			if food_inst.prefab == v then
				return false
			end
		end
		if old_CanEat ~= nil then
			return old_CanEat(self, food_inst)
		end
		return true
	end
end

 

Link to comment
Share on other sites

On 2019. 9. 10. at 4:41 AM, Ultroman said:

-- Put this line in your the master_postinit of you character LUA inst.components.eater:SetOnEatFn(OnEat) -- Put this function somewhere above your character's master_postinit local function OnEat(inst, food) if food and food.edible then if food.edible.healthvalue > 0 then inst.components.health:DoDelta(-food.edible.healthvalue) end if food.edible.sanityvalue > 0 then inst.components.sanity:DoDelta(-food.edible.sanityvalue) end end end

Can I modify (food and food)?Would you like to multiply the (-food.edible.sanityvalue) and (-food.edible.sanityvalue) portions of this code by zero? If the value is zero, it is unlikely to cause any problems.

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