Jump to content

Crashing When Killing Fishes


Recommended Posts

I have a vampire character that heals upon killing anything. But the game crashes if she kills a fish, I'm guessing it's because she gains 20% of the target's HP and the fishes have no HP, so the game goes belly-up. Anyway to make sure fishes aren't counted?

This is the vampire heal code:

local function vampire_heal(inst, data)
    local victim = data.victim
    if not inst.components.health:IsDead() then
        local total_health = victim.components.health:GetMaxWithPenalty()
        inst.components.health:DoDelta(total_health * .2)
    end
end

 

Link to comment
Share on other sites

It is good practice to do additional checks in your if statements to prevent unexpected errors like this. In this case check if victim.components.health is valid, its very likely the fishes don't have a health component compared to other inventory creatures. I don't have access to files and time atm to do much to help.

But basically if the victim.components.health returns false then you could just dodelta a static value instead if you want.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

On 4/19/2020 at 3:47 PM, IronHunter said:

It is good practice to do additional checks in your if statements to prevent unexpected errors like this. In this case check if victim.components.health is valid, its very likely the fishes don't have a health component compared to other inventory creatures. I don't have access to files and time atm to do much to help.

But basically if the victim.components.health returns false then you could just dodelta a static value instead if you want.

Thanks for the tip, it's all good now.

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...