halfrose Posted February 16, 2016 Share Posted February 16, 2016 (edited) I've been fiddling again with modding. The thing I am trying to do, is to make that the character, stead of losing health when freezing or overheating, they lose sanity. I've looked around the temperature.lua and spotted the 'startfreezing' and 'startoverheating', I think I could do something with a listenforevent or maybe make a component but I am not entirelly sure where to start or whether my approach is the best. help would be greatly appreciated. UPDATE: I did it, found a way to do that, it just took me a bit of stubborness. Well since it is posted, I will just drop the code here. local function ontemperaturechange(inst) if inst:HasTag("playerghost") or inst.components.health:IsDead() then return elseif inst.components.temperature.current > 2 and inst.components.temperature.current < 68 then inst.components.sanity.dapperness = nil elseif inst.components.temperature.current < 1 then inst.components.sanity.dapperness = (-TUNING.DAPPERNESS_LARGE * 40) elseif inst.components.temperature.current > 69 then inst.components.sanity.dapperness = (-TUNING.DAPPERNESS_LARGE * 40) end end and in master_postinit inst:ListenForEvent("sanitydelta", ontemperaturechange) inst.components.temperature.hurtrate = 0 Edited February 17, 2016 by halfrose Resolved it myself. Link to comment https://forums.kleientertainment.com/forums/topic/64439-a-little-modding-help-or-pointing/ Share on other sites More sharing options...
Neu7ral Posted February 17, 2016 Share Posted February 17, 2016 (edited) 3 hours ago, halfrose said: local function ontemperaturechange(inst) if inst:HasTag("playerghost") or inst.components.health:IsDead() then return elseif inst.components.temperature.current < 1 then inst.components.sanity.dapperness = (-TUNING.DAPPERNESS_LARGE * 40) elseif inst.components.temperature.current > 69 then inst.components.sanity.dapperness = (-TUNING.DAPPERNESS_LARGE * 40) end end and in master_postinit inst:ListenForEvent("sanitydelta", ontemperaturechange) inst.components.temperature.hurtrate = 0 I tried to use that code for my character (Finally I found it, thanks.), reducing the sanity penalty. And the sanity drain, didn't removed. Edited February 17, 2016 by Neutral_Steve removed the text. Link to comment https://forums.kleientertainment.com/forums/topic/64439-a-little-modding-help-or-pointing/#findComment-723493 Share on other sites More sharing options...
halfrose Posted February 17, 2016 Author Share Posted February 17, 2016 1 minute ago, Neutral_Steve said: I tried to use that code for my character (Finally I found it, thanks.), reducing the sanity penalty. And the sanity drain, didn't removed. are you sure you placed it on the right area, the local function ontemperature change is outside the master_postinit, the rest goes inside it. Also make sure you are not adding a number that is too low, literally, I had to add such an absurd number first to make sure it was working. Link to comment https://forums.kleientertainment.com/forums/topic/64439-a-little-modding-help-or-pointing/#findComment-723498 Share on other sites More sharing options...
Neu7ral Posted February 17, 2016 Share Posted February 17, 2016 6 minutes ago, halfrose said: are you sure you placed it on the right area, the local function ontemperature change is outside the master_postinit, the rest goes inside it. Also make sure you are not adding a number that is too low, literally, I had to add such an absurd number first to make sure it was working. Yep. Link to comment https://forums.kleientertainment.com/forums/topic/64439-a-little-modding-help-or-pointing/#findComment-723502 Share on other sites More sharing options...
halfrose Posted February 17, 2016 Author Share Posted February 17, 2016 15 minutes ago, Neutral_Steve said: I tried to use that code for my character (Finally I found it, thanks.), reducing the sanity penalty. And the sanity drain, didn't removed. OOPS, my bad, I realized I forgot to paste this into the coding as well elseif inst.components.temperature.current > 2 and inst.components.temperature.current < 68 then inst.components.sanity.dapperness = nil it goes into the ontemperaturechange I updated the main post. Link to comment https://forums.kleientertainment.com/forums/topic/64439-a-little-modding-help-or-pointing/#findComment-723503 Share on other sites More sharing options...
Kzisor Posted February 17, 2016 Share Posted February 17, 2016 (edited) 3 hours ago, halfrose said: UPDATE: I did it, found a way to do that, it just took me a bit of stubborness. Well since it is posted, I will just drop the code here. You're code is working in a very hackish kinda way. Try the following code. local _TemperatureUpdate = inst.components.temperature.OnUpdate function inst.components.temperature:OnUpdate( dt, applyhealthdealta ) -- Call the old function, making sure not to apply health damage. _TemperatureUpdate( self, dt, false ) -- Do sanity damage here. if self.current < 0 then self.inst.components.sanity:DoDelta(5) elseif self.current > self.overheattemp then self.inst.components.sanity:DoDelta(5) end end This code gets placed in your master_postinit and will do it in a much nicer fashion. Edited February 17, 2016 by Kzisor Fixed code, forgot a 'then' statement. Link to comment https://forums.kleientertainment.com/forums/topic/64439-a-little-modding-help-or-pointing/#findComment-723506 Share on other sites More sharing options...
Neu7ral Posted February 17, 2016 Share Posted February 17, 2016 3 minutes ago, halfrose said: OOPS, my bad, I realized I forgot to paste this into the coding as well elseif inst.components.temperature.current > 2 and inst.components.temperature.current < 68 then inst.components.sanity.dapperness = nil it goes into the ontemperaturechange I updated the main post. Ah. I will check it, Also, thanks for the code, I tried to check that when you posted, but I didn't finded an way. Link to comment https://forums.kleientertainment.com/forums/topic/64439-a-little-modding-help-or-pointing/#findComment-723508 Share on other sites More sharing options...
halfrose Posted February 17, 2016 Author Share Posted February 17, 2016 2 minutes ago, Kzisor said: You're code is working in a very hackish kinda way. Try the following code. local _TemperatureUpdate = inst.components.temperature.OnUpdate function inst.components.temperature:OnUpdate( dt, applyhealthdealta ) -- Call the old function, making sure not to apply health damage. _TemperatureUpdate( self, dt, false ) -- Do sanity damage here. if self.current < 0 then self.inst.components.sanity:DoDelta(5) elseif self.current > self.overheattemp then self.inst.components.sanity:DoDelta(5) end end This code gets placed in your master_postinit and will do it in a much nicer fashion. ohh, thanks! I tried to go around the self and dodelta but I couldn't get to work in first place. but hey, learning XD. Link to comment https://forums.kleientertainment.com/forums/topic/64439-a-little-modding-help-or-pointing/#findComment-723510 Share on other sites More sharing options...
Neu7ral Posted February 17, 2016 Share Posted February 17, 2016 43 minutes ago, halfrose said: I tried to go around the self and dodelta but I couldn't get to work in first place. but hey, learning XD. Same Link to comment https://forums.kleientertainment.com/forums/topic/64439-a-little-modding-help-or-pointing/#findComment-723527 Share on other sites More sharing options...
SenL Posted February 20, 2016 Share Posted February 20, 2016 On 2/17/2016 at 4:25 PM, Kzisor said: You're code is working in a very hackish kinda way. Try the following code. local _TemperatureUpdate = inst.components.temperature.OnUpdate function inst.components.temperature:OnUpdate( dt, applyhealthdealta ) -- Call the old function, making sure not to apply health damage. _TemperatureUpdate( self, dt, false ) -- Do sanity damage here. if self.current < 0 then self.inst.components.sanity:DoDelta(5) elseif self.current > self.overheattemp then self.inst.components.sanity:DoDelta(5) end end This code gets placed in your master_postinit and will do it in a much nicer fashion. DoDelta(5) ... won't that add sanity instead? So I copied this code but using DoDelta(-5) and then overheat myself... I ended up losing -5 sanity rapidly and then I have 0 sanity. I was expecting to lose sanity much much slower than that. I suppose I could doperiodictask instead? Link to comment https://forums.kleientertainment.com/forums/topic/64439-a-little-modding-help-or-pointing/#findComment-724935 Share on other sites More sharing options...
Muche Posted February 20, 2016 Share Posted February 20, 2016 OnUpdate receives parameter dt, which contains, I assume, time passed since last update. Looking at other places that use it you could try self.inst.components.sanity:DoDelta(5 * dt) Link to comment https://forums.kleientertainment.com/forums/topic/64439-a-little-modding-help-or-pointing/#findComment-724967 Share on other sites More sharing options...
Kzisor Posted February 20, 2016 Share Posted February 20, 2016 2 hours ago, SenL said: DoDelta(5) ... won't that add sanity instead? So I copied this code but using DoDelta(-5) and then overheat myself... I ended up losing -5 sanity rapidly and then I have 0 sanity. I was expecting to lose sanity much much slower than that. I suppose I could doperiodictask instead? A lot of the code I post is usually psuedo-code which requires equations to be changed in order to get your desired affect. Link to comment https://forums.kleientertainment.com/forums/topic/64439-a-little-modding-help-or-pointing/#findComment-724973 Share on other sites More sharing options...
SenL Posted February 20, 2016 Share Posted February 20, 2016 Thanks. I ended up doing this, is it ok? (all below is in char prefab) local function OnTemperatureTick(inst) if inst.components.temperature:IsOverheating() then inst.components.sanity:DoDelta(-3) end end local function onbecamehuman(inst) ... if inst.OnTempTick == nil then inst.OnTempTick = inst:DoPeriodicTask(3, function(inst) OnTemperatureTick(inst) end) end end local function onbecameghost(inst) ... if inst.OnTempTick ~= nil then inst.OnTempTick:Cancel() inst.OnTempTick = nil end end The code if inst.OnTempTick == nil then inst.OnTempTick = inst:DoPeriodicTask(3, function(inst) OnTemperatureTick(inst) end) end is also in onload() and common_postinit. It seems to work fine. Anything wrong? Link to comment https://forums.kleientertainment.com/forums/topic/64439-a-little-modding-help-or-pointing/#findComment-724987 Share on other sites More sharing options...
Kzisor Posted February 21, 2016 Share Posted February 21, 2016 40 minutes ago, SenL said: It seems to work fine. Anything wrong? The more tasks which are running with other mods the more performance will degrade. The reason why I always suggest people using the method I use is because performance doesn't degrade when you overwrite function like that. It's already calling the function, whether or not it continues executing depends on a small if-statement. Whereas using tasks requires the code to run a completely separate function which might not run when you want it to run. Link to comment https://forums.kleientertainment.com/forums/topic/64439-a-little-modding-help-or-pointing/#findComment-724990 Share on other sites More sharing options...
SenL Posted February 21, 2016 Share Posted February 21, 2016 Ok, multiplying by dt works. It's now rapidly draining -0.05 or so. Thanks! Link to comment https://forums.kleientertainment.com/forums/topic/64439-a-little-modding-help-or-pointing/#findComment-724997 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