m9m3x3 Posted September 9, 2019 Share Posted September 9, 2019 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 More sharing options...
Ultroman Posted September 9, 2019 Share Posted September 9, 2019 Hello. Your previous post was on the DST forum, and this one is on the DS forum. Are you making a mod for DS or DST? There are many differences between the two games, so it's really important that you start the thread in the correct sub-forum. Link to comment Share on other sites More sharing options...
m9m3x3 Posted September 9, 2019 Author Share Posted September 9, 2019 The forum was selected incorrectly. I'm sorry. T.T I'm working on DST. Link to comment Share on other sites More sharing options...
Ultroman Posted September 9, 2019 Share Posted September 9, 2019 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 More sharing options...
Ultroman Posted September 9, 2019 Share Posted September 9, 2019 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 More sharing options...
m9m3x3 Posted September 10, 2019 Author Share Posted September 10, 2019 Thank you! By any chance, what can I do to prevent my character from eating vegetables at all? Link to comment Share on other sites More sharing options...
Ultroman Posted September 11, 2019 Share Posted September 11, 2019 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 More sharing options...
m9m3x3 Posted September 11, 2019 Author Share Posted September 11, 2019 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 More sharing options...
Ultroman Posted September 11, 2019 Share Posted September 11, 2019 I have no idea what you just said. I have found a better way to do this, though. Check out my new Fun With Food tutorial, specifically the part about "Changing Food Values Based On Foodtype (CHARACTER)". Link to comment Share on other sites More sharing options...
m9m3x3 Posted September 11, 2019 Author Share Posted September 11, 2019 Thank you! That was very helpful to me. Link to comment Share on other sites More sharing options...
Recommended Posts
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.