Bloodysanta Posted October 24, 2021 Share Posted October 24, 2021 (edited) This is the first and very possibly last time I have tried making a character in dst, so excuse my complete lack of coding knowledge. Basically, I want a character to, instead of dying, get knocked out and wake up 2 days later. I decided that (after trying many failed ways) I was just going to make this happen when he reached one health. I've figured out how to make things happen at a certain amount of health (using 50% as a placeholder for easier testing), how to make him invincible, and how to keep stats up during this time, but for the life of me I can't get the knockedout event to trigger. I've done it in previous code trying to make this work, but it wont happen here, is there anything I'm doing wrong? AddPlayerPostInit(function(inst) local percent = inst.components.health:GetPercent() inst:ListenForEvent("healthdelta", function(inst, data) if data.oldpercent > data.newpercent then if data.newpercent < 0.5 then inst.components.health:SetInvincible(true) inst.components.health:SetPercent(1) inst.components.hunger:SetPercent(1) inst.components.sanity:SetPercent(1) inst.components.temperature:SetTemperature(25) inst.components.moisture:SetPercent(0) inst:AddTag("God") inst.components.grogginess:AddGrogginess(2, 0) end end end) end) (Note: I've tried adding grogginess & knockout duration) Edited October 25, 2021 by Bloodysanta Link to comment https://forums.kleientertainment.com/forums/topic/134721-help-with-character-mod-knockout-command/ Share on other sites More sharing options...
CarlZalph Posted October 29, 2021 Share Posted October 29, 2021 Ah, the issue here is that you're listening for the event of the health delta. This happens after the fact of health application. What you'll want to do is hook the health component's SetVal function that gets called. Following my structure outlined here: https://forums.kleientertainment.com/forums/topic/129557-tutorial-function-hooking-and-you/ You would place this inside your mod character's master_postinit callback function and not a general player post init. It would look like: local SetVal_old = inst.components.health.SetVal inst.components.health.SetVal = function(self, val, ...) if val < 1 then -- Do your work on 'inst' or 'self.inst' here, both should refer to the same player entity owning the component. val = 1 -- Don't forget to modify the result to be bigger than zero, in your case it'll be set to max hp (percent 1.0) from your code above. end return SetVal_old(self, val, ...) end 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/134721-help-with-character-mod-knockout-command/#findComment-1508927 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now