Jump to content

Recommended Posts

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 ? 

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... :)

Edited by whismerhill

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 healtharrow-10x10.png: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 healtharrow-10x10.png and sanity at the same time when killing a "something" anything. @mobbstar

 

When she is over 30% sanity killing "something" she gain 2 healtharrow-10x10.png u got the code for it?

Would be amazing if you guys could help out. 

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...