Jump to content

Help with making hostile things neutral to a certain character?


Recommended Posts

I have a character I'm making, and I want to make a certain hostile animal, like a killer bee, a tall bird, or a beefalo in heat, not attack my character. I know might need to say something along the lines of

"If my character attacks a Beefalo, then the beefalo should target my character, or else if the beefalo is targeting my character, then stop targeting."

But I don't quite know how to say that in lua code. I know the syntax would probably work, I'm just in the dark on what to put in between all the ifs and thens.

Link to comment
Share on other sites

@Dudeguy, Hmm, well, for beefalo you could use the same construct as the beefalo hat, inst:AddTag("beefalo")-- although you'll have to re-add it when unequipping the beefalo hat, since it removes it. Like this in the modmain:

AddPrefabPostInit("beefalohat", function(inst)    if GLOBAL.TheWorld.ismastersim then        local old_unequip = inst.components.equippable.onunequipfn        inst.components.equippable.onunequipfn = function(inst, owner)            old_unequip(inst, owner)            if owner.prefab == "mycharacter" then                inst:AddTag("beefalo")            end        end    endend)

From tallbirdbrain, it looks like you can use the same approach-- inst:AddTag("tallbird"). There are no tallbird hats, so you shouldn't have to worry about catching any special cases.

 

The analogous thing for killer bees looks to be inst:AddTag("insect"), but that may have some unintended consequences (mosquitos maybe?). You could also overwrite the killer bee's retarget function to exclude a tag that you give your character, for example:

local function KillerRetarget(inst)    return FindEntity(inst, 8, function(guy)        return inst.components.combat:CanTarget(guy)    end,    nil,    {"insect", "my_character_tag"},    {"character","animal","monster"}    )endAddPrefabPostInit("killerbee", function(inst)    if GLOBAL.TheWorld.ismastersim then        inst.components.combat:SetRetargetFunction(2, KillerRetarget)    endend)
Edited by rezecib
Link to comment
Share on other sites

Cool info.

A question on this: "inst.components.combat:SetRetargetFunction(2, KillerRetarget)"

 

The 2 here is also in bee.lua. Is there a way to not hardcode it on the character lua?

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