Jump to content

Immune to damage from certain prefab [solved]


Recommended Posts

Hello, I'm trying to create a creature that summons tornadoes when it attacks, however the problem is that it takes damage from those same tornadoes. I'd like to edit it to be immune to damage from that prefab, but I can't seem to get it to work. I looked at this topic

however the solution that was reached offered me absolutely no help when I used it. Any help would be greatly appreciated 

Edited by Eusong
Link to comment
Share on other sites

 

--as its own function above masterpostinit
local function tornadoimmunity(inst, amount, overtime, cause, ignore_invincible, afflicter, ignore_absorb)
    return afflicter ~= nil and afflicter.prefab == "prefabnamehere") --you can also do afflicter:HasTag("name") if you want to filter it by tags.
end

--in masterpostinit
inst.components.health.redirect = tornadoimmunity

 

Edited by DarkKingBoo
Link to comment
Share on other sites

10 minutes ago, DarkKingBoo said:

 


--as its own function above masterpostinit
local function tornadoimmunity(inst, amount, overtime, cause, ignore_invincible, afflicter, ignore_absorb)
    return afflicter ~= nil and afflicter.prefab == "prefabnamehere") --you can also do afflicter:HasTag("name") if you want to filter it by tags.
end

--in masterpostinit
inst.components.health.redirect = tornadoimmunity

 

It works! Thank you so much! However it still gets stunned by the tornado. Is there a piece of code you know that could get rid of it being stunned by it? Thanks again for the first piece. ^-^

Link to comment
Share on other sites

Hmm I was not aware that the health redirect doesn't stop stunning, my bad.

I'm assuming the tornado is staff_tornado prefab. You may need to add additional code to the tornado stategraph to specifically ignore your character in the destroystuff function. I'm sure there is some form of AddStategraphPostInit (there is another method but I need to remember how to do it), however I can't look it up today. 

Since your character is summoning tornadoes, you can take the simple way and simply make a copy of the SGtornado (and rename it to something else) and make the changes and have the tornadoes use that stategraph when summoned. I'll answer back with a "cleaner" solution when I can.

Link to comment
Share on other sites

1 hour ago, Eusong said:

Is there a piece of code you know that could get rid of it being stunned by it?

You could use the code that the tornado uses.

local tornado = SpawnPrefab("tornado")

tornado.WINDSTAFF_CASTER_ISPLAYER = true

Now the tornados won't hit players (unless PVP is enabled).

Edited by DarkXero
Link to comment
Share on other sites

3 hours ago, DarkXero said:

local tornado = SpawnPrefab("tornado")

tornado.WINDSTAFF_CASTER = inst
tornado.WINDSTAFF_CASTER_ISPLAYER = true

And make that inst be the creature.

Thank you so much! It works!!

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