Jump to content

Character perk help


Recommended Posts

I'm making a sort of test character that has a perk where she won't get attack by monsters however have an idea of how to code that into my character so i was wondering if anyone would like to give me a simple code to make monsters avoid my character.

 

Another thing that i would love to be added but doesn't have to be is the monsters afraid animation is played when my character gets close.

 

It would mean a lot if someone helped me with this :3

Link to comment
Share on other sites

You can use something like this:
 
AddBrainPostInit(monster_prefab, function(self)
     GLOBAL.table.insert(self.bt.root.children, NUM, GLOBAL.RunAway(self.inst, tag, SEE_PLAYER_DIST, STOP_RUN_DIST))
end)
 
monster_prefab is the prefab name of monster.
NUM is the position in the table where you insert this flee behaviour. This number also decides the priority.
tag is a unique tag you attach to your character using inst:AddTag( ).

 

Some mobs don't have a flee animation, forcing them to flee will result in weird/broken animation.

Link to comment
Share on other sites

@codelyoko373

In your character's prefab, put inst:AddTag("tallbird") under the local common_postinit. In your character's modmain, put

AddPrefabPostInit("tallbird", function(inst)

    local old_sfn = inst.components.combat.SuggestTarget
    inst.components.combat.SuggestTarget = function(self, target)
        if target and target:HasTag("tallbird") then
            if target.components.combat.target ~= self.inst then
                return
            end
        end
        return old_sfn(self, target)
    end
end)
I put that under everything else in the modmain and it worked for me. I hope I helped!
Link to comment
Share on other sites

 

You can use something like this:
 
AddBrainPostInit(monster_prefab, function(self)
     GLOBAL.table.insert(self.bt.root.children, NUM, GLOBAL.RunAway(self.inst, tag, SEE_PLAYER_DIST, STOP_RUN_DIST))
end)
 
monster_prefab is the prefab name of monster.
NUM is the position in the table where you insert this flee behaviour. This number also decides the priority.
tag is a unique tag you attach to your character using inst:AddTag( ).

 

Some mobs don't have a flee animation, forcing them to flee will result in weird/broken animation.

 

Would this code still be active if the character attacked the monster told to not attack. Since what i would like is the monster not to attack at first sight but if the character attacks then the monster will

Link to comment
Share on other sites

I have not tried that before, but what you should do probably is inserting the RunAway node after the ChaseAndAttack node, using an appropriate NUM value. Have a look at koalefant brain file to see how it's structured.

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