Jump to content

Trouble implementing a damage boost after going below 50% sanity


Recommended Posts

I've been having trouble implementing this function in my code. 
I'm kind of a novice when it come to programming so I don't know in what part of the code to pu it.

Here's the function and the code itself.

   inst:ListenForEvent("sanitydelta", function(inst, data)
    if inst.components.sanity.current >= 100 then
       inst.components.combat.damagemultiplier = 1.5
    elseif inst.components.sanity.current <= 100 then
       inst.components.combat.damagemultiplier = 2.5
    end
    )
    end
end

 

custom character.txt

Link to comment
Share on other sites

First of all, you gotta put this anywhere inside the "master_postinit" function:

inst:ListenForEvent("sanitydelta", OnSanityDelta)

It can be anywhere, but I suggest putting it above the "inst.OnLoad" variable.

Then you put this anywhere above the "master_postinit", outside of it.
 

local function OnSanityDelta(inst, data)
	if inst.components.sanity:GetPercent() > 0.5 then
       inst.components.combat.damagemultiplier = 1.5
    elseif inst.components.sanity:GetPercent() <= 0.5 then
       inst.components.combat.damagemultiplier = 2.5
    end
end

 

Edited by HarryPPP
  • Thanks 1
Link to comment
Share on other sites

5 hours ago, HarryPPP said:

First of all, you gotta put this anywhere inside the "master_postinit" function:


inst:ListenForEvent("sanitydelta", OnSanityDelta)

It can be anywhere, but I suggest putting it above the "inst.OnLoad" variable.

Then you put this anywhere above the "master_postinit", outside of it.
 


local function OnSanityDelta(inst, data)
	if inst.components.sanity:GetPercent() > 0.5 then
       inst.components.combat.damagemultiplier = 1.5
    elseif inst.components.sanity:GetPercent() <= 0.5 then
       inst.components.combat.damagemultiplier = 2.5
    end
end

 

does this work for vanilla survivors?

Link to comment
Share on other sites

Just now, AngryBeeQueen said:

does this work for vanilla survivors?

AddPrefabPostInit + TheWorld.ismastersim check + this ListenForEvent will.  Listening for an event doesn't is a non-blocking operation and is more of a notification listener rather than an event chain resolver.

  • Like 1
Link to comment
Share on other sites

3 minutes ago, CarlZalph said:

AddPrefabPostInit + TheWorld.ismastersim check + this ListenForEvent will.  Listening for an event doesn't is a non-blocking operation and is more of a notification listener rather than an event chain resolver.

can you explain like im five ._.

Link to comment
Share on other sites

16 minutes ago, AngryBeeQueen said:

can you explain like im five ._.

No but I can write up an example, it'd be quicker.

local function someeventcallback(inst, data)
    -- Do stuff.
end
local function OnPostInit_wilson(inst)
    if not GLOBAL.TheWorld.ismastersim
    then
        return
    end
    inst:ListenForEvent("someevent", someeventcallback)
end
AddPrefabPostInit("wilson", OnPostInit_wilson)

 

  • Like 1
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...