Jump to content

Take more damage from bees - Coding help


Recommended Posts

Hello! I've been modding a character that is allergic to bees and I have set him to lose sanity around them, but I'm looking for a way that he could take WAY more damage when hit by them! Here's a thing I tried:

local function onhit(inst)
     if target:HasTag("bee") then 
	inst.components.health:SetAbsorptionAmount(-3)
         else
	inst.components.health:SetAbsorptionAmount(0.4)
end
end

I thought it'd be fairly easy, but as I am very new to coding, I don't know how to proceed for this one.  I tried to change his defense upon a hit, but I feel this is wrong as it does not work.

Does anyone have an idea how this works?

Link to comment
Share on other sites

maybe this work, put in modmain.lua

Spoiler

local Character = "YOURCHARACTERPREFABNAMEHERE"
local Damage_Mult = 2 -- double damage
AddComponentPostInit("combat",function(inst)
    if not GLOBAL.TheWorld.ismastersim then
        return
    end
    local oldbonusdamagefn = inst.bonusdamagefn
    inst.bonusdamagefn = function(attacker, target, damage, weapon)
        local bonus = 0
        if oldbonusdamagefn then
            bonus = oldbonusdamagefn(attacker, target, damage, weapon) or 0
        end
        if target.prefab == Character and (attacker:HasTag("bee")) then
            bonus = bonus - (damage + bonus) * Damage_Mult
        end
        return bonus
    end
end)

 

 

Link to comment
Share on other sites

@SuperDavid I'm actually wondering if it's possible to make my character Groggy for a set amount of time when stung by a bee. OR even better, groggy until he heals himself with a healing salve or use an adrenaline shot. Would you happen to know how? I had made a character that got groggy under 30 of hunger, with that code: 

if inst.components.hunger.current >= (0) and inst.components.hunger.current < (30) then
			if inst:HasTag("groggy") then return
		else
			inst:AddTag("groggy")
    		inst.components.locomotor:SetExternalSpeedMultiplier(inst, "grogginess", 0.6)

This could somehow be written to when the character gets stung?

Edited by Kiibie
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...