Jump to content

Recommended Posts

Hi there! I'm making my first character mod, and he's a weird little man, so I was wondering if there was a way to code him gaining sanity by killing humanoid things like that? It's probably simple, but my brain just isn't working lately, and this is the last thing I need to do for him, coding wise.

Hey-hey!

I have a similar perk used in of my mods. It looks like this:

Spoiler

    -- Kill penalty
    local function OnKill(victim,inst)
        if victim and victim.prefab then
            if victim.prefab == "rabbit" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "butterfly" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "pigman" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "bunnyman" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "rocky" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "catcoon" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "mole" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "lightninggoat" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "deer" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "grassgekko" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "fruitdragon" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "chester" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
        end
    end
    inst:ListenForEvent( "killed", function(inst,data) OnKill(data.victim,inst) end )

Add or remove certain mobs if you want and change the TUNING.SPINELKILL to the value you want to get by the killing. This code belongs into the character's lua file, inside the master_postinit section.

Cheers!

10 hours ago, C_Thun said:

Hey-hey!

I have a similar perk used in of my mods. It looks like this:

  Hide contents

    -- Kill penalty
    local function OnKill(victim,inst)
        if victim and victim.prefab then
            if victim.prefab == "rabbit" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "butterfly" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "pigman" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "bunnyman" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "rocky" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "catcoon" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "mole" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "lightninggoat" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "deer" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "grassgekko" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "fruitdragon" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
            if victim.prefab == "chester" then
                inst.components.sanity:DoDelta(TUNING.SPINELKILL)
            end
        end
    end
    inst:ListenForEvent( "killed", function(inst,data) OnKill(data.victim,inst) end )

Add or remove certain mobs if you want and change the TUNING.SPINELKILL to the value you want to get by the killing. This code belongs into the character's lua file, inside the master_postinit section.

Cheers!

Hi! Thank you so so much! It works perfectly! You're a life saver! Seriously, thanks!

  • Like 1

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