durant313 Posted September 19, 2016 Share Posted September 19, 2016 Hello everyone. Well I want my char to gain insanity and healt when killing a monster or maybe just a rabbit.. but after killing a something he wont gain idk why. Here is my code: local function onattack(inst, data) --get health and sanity when killing enemies local victim = data.target if not inst.components.health:IsDead() and IsValidVictim(victim) then --and victim.components.health:GetPercent() <= .20 local healthdelta = 3 --(victim.components.combat.defaultdamage * .12) local sanitydelta = 4--(victim.components.combat.defaultdamage * .16) inst.components.health:DoDelta(healthdelta) inst.components.sanity:DoDelta(sanitydelta) elseif not inst.components.health:IsDead() and IsValidVictim(victim) then local healthdelta = 3--(victim.components.combat.defaultdamage * .06) local sanitydelta = 4--(victim.components.combat.defaultdamage * .1) inst.components.health:DoDelta(healthdelta) inst.components.sanity:DoDelta(sanitydelta) end end --inst:AddTag("epic") Please can someone help me ? Link to comment Share on other sites More sharing options...
Mobbstar Posted September 19, 2016 Share Posted September 19, 2016 Do you have the "IsValidVictim" function too? Without it, the game will crash. Link to comment Share on other sites More sharing options...
whismerhill Posted September 20, 2016 Share Posted September 20, 2016 you're not applying bonuses on death but on hp lower than 20% apparently, was this intended ? Suggestion for what you said you wanted : Spoiler local function awardbonuses(inst,data) local victim = data.victim ... end ... local fn = function(inst) inst.soundsname = "wendy" ... ... inst:ListenForEvent("killed",awardbonuses) ... end where ... stands for stuff you have to do or add also I would add some code sanity checks : Spoiler if victim and victim.prefab and victim.components.combat and victim.components.health then ... might be useless or not... Link to comment Share on other sites More sharing options...
durant313 Posted September 20, 2016 Author Share Posted September 20, 2016 oh sorry guys I already fixed it now I m trying to make something else. But thanks for the replies. Im trying something diffrent this time. Here is the code that made it work: I hope people can use it if they needed it. local master_postinit = function(inst) inst:ListenForEvent("killed",function(inst,data) inst.components health:DoDelta(4) inst.components.sanity:DoDelta(3) end) This is what i used and it worked fine. Well I want to ask you Im trying to make when she is under 30% sanity she gains health and sanity at the same time when killing a "something" anything. @mobbstar When she is over 30% sanity killing "something" she gain 2 health u got the code for it? Would be amazing if you guys could help out. Link to comment Share on other sites More sharing options...
Mobbstar Posted September 20, 2016 Share Posted September 20, 2016 if inst.components.sanity:GetPercent() < .3 then inst.components.health:DoDelta(2) else inst.components.health:DoDelta(4) inst.components.sanity:DoDelta(3) end This code only adds 2 health if sane, but when insane adds 4 health and 3 sanity. 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.