Jump to content

[Perk Coding Help!] Sanity drain while attacking?


Recommended Posts

Hi guys! Not to be another clueless person asking for coding help.. but, well, here I am! I'm new to DST, and even more new to modding, and need a bit of help with perk coding. 

I'm hoping to do something where my character will lose sanity the longer he attacks (or for coding's sake, I'm assuming the more hits he makes). If draining sanity per one hit is just way easier to do, that's an option, too.

I've poked around these forums, steam, and google to try out various things, but I'm afraid I'm just way too new to piece together my own codes quite yet. All I know is that it probably has something to do with listening for the "onattackother" event, but then I don't know what to do from there, lol.

Any help is appreciated, sorry for the trouble!

Link to comment
Share on other sites

Here:

local function IsValidVictim(victim) --exclude these as enemies
    return victim ~= nil
        and not (victim:HasTag("veggie") or
                victim:HasTag("structure") or
                victim:HasTag("wall"))
        and victim.components.health ~= nil
        and victim.components.combat ~= nil
end

local function combatdrain(inst, data) --if you hit your enemy
local victim = data.victim
    if not IsValidVictim(victim) then
    inst.components.sanity:DoDelta(-1)
    end
end

local function onkilled(inst, data)--if you kill your enemy
    local victim = data.victim
    if IsValidVictim(victim) then
    if victim:HasTag("epic") then --boss killed
    inst.components.sanity:DoDelta(-50)
    elseif victim:HasTag("largecreature") and not victim:HasTag("epic") then --beefalo killed
    inst.components.sanity:DoDelta(-10)
    elseif victim:HasTag("smallcreature") then --rabbits, frogs and such killed
    inst.components.sanity:DoDelta(-2)
    else
    inst.components.sanity:DoDelta(-5) --everything else
    end
 end
end

local master_postinit = function(inst) --reference on where the code goes

inst:ListenForEvent("killed", onkilled) --lose sanity on killing

inst:ListenForEvent("onattackother", combatdrain) --lose sanity on hitting your enemy

Read the notes and make the necessary edits to what you see as fit. I added some extra code for killing things as well but if your not interested ignore the onkilled function and isvalidvictim function.

Link to comment
Share on other sites

34 minutes ago, K1NGT1GER609 said:

-length snip-

Read the notes and make the necessary edits to what you see as fit. I added some extra code for killing things as well but if your not interested ignore the onkilled function and isvalidvictim function.

Thank you so much! Super excited to give this a try out later! Can't thank you enough :D

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