quadgamer Posted September 15, 2016 Share Posted September 15, 2016 My hard drive failed and I had to replace it. I didn't add my sample codes to my backup. I had a few ways to reduce damage but I can't find any. I appreciate the help. Link to comment https://forums.kleientertainment.com/forums/topic/70170-absorb-damage-or-damage-reduction/ Share on other sites More sharing options...
Serpens Posted September 15, 2016 Share Posted September 15, 2016 It depends if you want to change the values during a running game, or just give your modcharacter a default damage. If you want to change it during running game, read this and the following posts. You can also take a look how I did it in moy "Home Base Bonus" mod. It is not perfect, but much better than just set a new value Link to comment https://forums.kleientertainment.com/forums/topic/70170-absorb-damage-or-damage-reduction/#findComment-814048 Share on other sites More sharing options...
quadgamer Posted September 15, 2016 Author Share Posted September 15, 2016 12 minutes ago, Serpens said: It depends if you want to change the values during a running game, or just give your modcharacter a default damage. If you want to change it during running game, read this and the following posts. You can also take a look how I did it in moy "Home Base Bonus" mod. It is not perfect, but much better than just set a new value Thanks. Those are good to know. But I was looking for protection. Like armor. I checked a couple other mods I have and found different ways. This is what I was kinda looking for. inst.components.health:SetAbsorptionAmount(0.10) Link to comment https://forums.kleientertainment.com/forums/topic/70170-absorb-damage-or-damage-reduction/#findComment-814054 Share on other sites More sharing options...
Serpens Posted September 15, 2016 Share Posted September 15, 2016 (edited) it is the simular for absorption, except you have the function you mentioned and it is not a multiplier. If you use this function during a running game, this will lead to problems with other mods that also do change it during running game. In my home base bnous mod I used the following code (I'm sure someone could simplify it, but it works) Spoiler -- Armor Bonus if GetModConfigData("absorb_carpet")~=0 or GetModConfigData("absorb_checker")~=0 or GetModConfigData("absorb_wooden")~=0 then AddComponentPostInit("health", function(self) if self.inst:HasTag("player") then self.AbsorbHomeBonus = nil self.UpdateAbsorptionHomeBase = function(inst) if self.absorb~= nil then -- at beginning it is sometimes nil, so wait until it is not local cachedinst = UpdateorGet(inst,"rain")-- str does not matter here -- returns a table like this {["base"]={false,0},["heat"]={0,0},["coordinates"]={{nil,nil,nil,nil},0}} local tile = cachedinst["coordinates"][1][4] local isbase = cachedinst["base"][1] local before = 0 if not (tile == GLOBAL.GROUND.CARPET or tile == GLOBAL.GROUND.WOODFLOOR or tile == GLOBAL.GROUND.CHECKER) then -- if not on a floor, hide the base icon OnBaseBonus(inst,false) end if (tile == GLOBAL.GROUND.CARPET and GetModConfigData("absorb_carpet")~=0) or (tile == GLOBAL.GROUND.WOODFLOOR and GetModConfigData("absorb_wooden")~=0) or (tile == GLOBAL.GROUND.CHECKER and GetModConfigData("absorb_checker")~=0) then if GetModConfigData("base_required_absorb")==0 or isbase then -- give bonus if no base is required or if there is a base if tile == GLOBAL.GROUND.CARPET then if self.AbsorbHomeBonus == nil then before = self.absorb self.absorb = mymathclamp(self.absorb + GetModConfigData("absorb_carpet"),0,1) self.AbsorbHomeBonus = {mymathabs(before - self.absorb),"absorb_carpet"} -- can't be higher than 1, so if absorb is 0.6 before our change, we can olny add 0.4, and this is also what we have to remove after our bonus is gone elseif self.AbsorbHomeBonus[2]~="absorb_carpet" then self.absorb = self.absorb - self.AbsorbHomeBonus[1] -- undo before = self.absorb self.absorb = mymathclamp(self.absorb + GetModConfigData("absorb_carpet"),0,1) self.AbsorbHomeBonus = {mymathabs(before - self.absorb),"absorb_carpet"} end elseif tile == GLOBAL.GROUND.WOODFLOOR then if self.AbsorbHomeBonus == nil then before = self.absorb self.absorb = mymathclamp(self.absorb + GetModConfigData("absorb_wooden"),0,1) self.AbsorbHomeBonus = {mymathabs(before - self.absorb),"absorb_wooden"} elseif self.AbsorbHomeBonus[2]~="absorb_wooden" then self.absorb = self.absorb - self.AbsorbHomeBonus[1] -- undo before = self.absorb self.absorb = mymathclamp(self.absorb + GetModConfigData("absorb_wooden"),0,1) self.AbsorbHomeBonus = {mymathabs(before - self.absorb),"absorb_wooden"} end elseif tile == GLOBAL.GROUND.CHECKER then if self.AbsorbHomeBonus == nil then before = self.absorb self.absorb = mymathclamp(self.absorb + GetModConfigData("absorb_checker"),0,1) self.AbsorbHomeBonus = {mymathabs(before - self.absorb),"absorb_checker"} elseif self.AbsorbHomeBonus[2]~="absorb_checker" then self.absorb = self.absorb - self.AbsorbHomeBonus[1] -- undo before = self.absorb self.absorb = mymathclamp(self.absorb + GetModConfigData("absorb_checker"),0,1) self.AbsorbHomeBonus = {mymathabs(before - self.absorb),"absorb_checker"} end else if self.AbsorbHomeBonus ~= nil then self.absorb = mymathclamp(self.absorb - self.AbsorbHomeBonus[1],0,1) self.AbsorbHomeBonus = nil end end else if self.AbsorbHomeBonus ~= nil then self.absorb = mymathclamp(self.absorb - self.AbsorbHomeBonus[1],0,1) self.AbsorbHomeBonus = nil end end else if self.AbsorbHomeBonus ~= nil then self.absorb = mymathclamp(self.absorb - self.AbsorbHomeBonus[1],0,1) self.AbsorbHomeBonus = nil end end end inst:DoTaskInTime(updatePlayer,self.UpdateAbsorptionHomeBase) end local _SetAbsorptionAmount = self.SetAbsorptionAmount -- modify this function to make game uses of this function compatible to this mod changes self.SetAbsorptionAmount = function(inst,amount) -- if amount==0 then -- inst:DoTaskInTime(10,self.SetAbsorptionAmount,0.4) -- simulate some game changes -- else -- inst:DoTaskInTime(10,self.SetAbsorptionAmount,0) -- end if self.AbsorbHomeBonus == nil then -- no bonus from this mod, just return normal stuff -- print("set armor to: "..amount) return _SetAbsorptionAmount(self,amount) else local before = self.absorb self.absorb = mymathclamp(amount + GetModConfigData(self.AbsorbHomeBonus[2]),0,1) self.AbsorbHomeBonus = {mymathmin(self.AbsorbHomeBonus[1],mymathabs((amount+GetModConfigData(self.AbsorbHomeBonus[2]))-1)),self.AbsorbHomeBonus[2]} -- print("set armor with MOD to: "..self.absorb.." value: "..self.AbsorbHomeBonus[1]) end end self.inst:DoTaskInTime(updatePlayer,self.UpdateAbsorptionHomeBase) -- self.inst:DoTaskInTime(10,self.SetAbsorptionAmount,0.4) -- simulate some game changes end end) end this code adds armor to players on floor if it is set in the mod settings. Edited September 15, 2016 by Serpens Link to comment https://forums.kleientertainment.com/forums/topic/70170-absorb-damage-or-damage-reduction/#findComment-814061 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