Jump to content

Help with rabbits


LordTS

Recommended Posts

Hi, i am very new to modding, just yesterday i got the idea to make a character mod. With the help of some guides i have succeeded to make a basic character( changed only the base status and putted she on the game).

 

The problem is, the character is supposed to be friends with the rabbits. She already have the vegetarian tag and i have removed the scaretoprey tag, but removing this tag makes any animal with the prey tag stay put without running from me.

 

So, i want to know how to make only the rabbit to not be scared.

 

 

Thank you

Obrigado

Link to comment
Share on other sites

In scripts/brains/rabbitbrain.lua function RabbitBrain:OnStart() there is the behaviour of RunAway.

 

You'd need to hook the brain's function to add the behaviour's shouldrunfunction.

 

 

I'mma see about getting that hooked.

 

Edit1:

This is a bit more involved than I initially thought, will work on it tomorrow.

Link to comment
Share on other sites

Since you presumably want the rabbits to respond to other threats while you're nearby, the only way I can imagine it working is to make a new behaviour based on RunAway. 

 

The new behaviour would have to accept a parameter to allow you to specify tags to exclude when using FindEntity.

Link to comment
Share on other sites

Since you presumably want the rabbits to respond to other threats while you're nearby, the only way I can imagine it working is to make a new behaviour based on RunAway. 

 

The new behaviour would have to accept a parameter to allow you to specify tags to exclude when using FindEntity.

There's a function you can specify in the behaviour tree node for RunAway that is a secondary check which I'm trying to get the rabbit brain to get hooked into, but the timing on getting it to hook is being a bit pushy.

 

Edit1:

local function Rabbit_Brain_ShouldRunFn(hunter)    return not hunter:HasTag("rabbitwhisperer")endlocal function PostInit_Brain_rabbitbrain(self)    local theBehaviourTreeRoot = self.bt.root    if(theBehaviourTreeRoot.children)    then        for _,v in ipairs(theBehaviourTreeRoot.children)        do            if(v.name=="RunAway")            then                -- This is where a backup of the old function should be, but I don't see how to do this.                -- Problem is that the shouldrunfn doesn't contain the caller in its arguments.                v.shouldrunfn = Rabbit_Brain_ShouldRunFn            end        end    endendAddBrainPostInit("rabbitbrain", PostInit_Brain_rabbitbrain)

You'll need to give your character the tag 'rabbitwhisperer' for rabbits to not be feared of you.

 

 

There's a small error in that it's completely wiping out the old shouldrunfn, but that function doesn't pass the caller in its arguments so I don't know how to preserve the old shouldrunfn.

Also in default code this doesn't exist for the rabbit at all, so this will only conflict with other mods.

 

@rezecib Do you happen to have any ideas for preservation and calling of the old shouldrunfn to be used in the new shouldrunfn callback?

Link to comment
Share on other sites

Is there a reason for not using AddBrainPostInit?

Yeah, because I'm not familiar with the modutil.lua's functions fully yet.

Hoping that while I attempt to help others that I help myself to knowledge on the API.

 

This Post Init cuts down the code a bit, and I'll be editing the post; thanks!

Link to comment
Share on other sites

@CarlZalph, @LordTS,

 

You'd put this in modmain.lua:

local function mod_rabbitbrain(inst)    local player = GLOBAL.GetPlayer()        for k,node in pairs(inst.bt.root.children) do        if node.name and node.name == "RunAway" then            node.shouldrunfn = function(hunter) return not hunter:HasTag("rabbitwhisperer") end        end    endendAddBrainPostInit("rabbitbrain", mod_rabbitbrain)

But I stand by my first comment in that I don't think this is quite the correct approach.  The problem is that the RunAway behaviour only checks for the closest entity.  That means that when the player is the closest thing to the rabbit, the rabbit will ignore all other sources of danger.

 

 

Edit:  damn forum never notifies me of replies in time!

Link to comment
Share on other sites

But I stand by my first comment in that I don't think this is quite the correct approach.  The problem is that the RunAway behaviour only checks for the closest entity.  That means that when the player is the closest thing to the rabbit, the rabbit will ignore all other sources of danger.

Hmm, yeah.

 

Though wouldn't having another behaviour for the rabbit make other mods that hook into the behaviour of the rabbit conflict?

Link to comment
Share on other sites

PrefabFiles = {

"wme",

}

 

Assets = {

    Asset( "IMAGE", "images/saveslot_portraits/wme.tex" ),

    Asset( "IMAGE", "images/selectscreen_portraits/wme.tex" ),

    Asset( "IMAGE", "images/selectscreen_portraits/wme_silho.tex" ),

    Asset( "IMAGE", "bigportraits/wme.tex" ),

}

 

local function mod_rabbitbrain(inst)

    local player = GLOBAL.GetPlayer()

     

    for k,node in pairs(inst.bt.root.children) do

        if node.name and node.name == "RunAway" then

            node.shouldrunfn = function(hunter) return not hunter:HasTag("rabbitwhisperer") end

        end

    end

end

 

AddBrainPostInit("rabbitbrain", mod_rabbitbrain)

 

AddModCharacter("wme")

 

 

My modmain.lua is like this, but now the game chashes when i try to activate the mod :/

(Also added the tag to the character)

Link to comment
Share on other sites

@LordTS, what is the error you're getting?  If none, check the log file.

 

 

@CarlZalph,

 

 

Conflicts are always a possibility, but if you're making a character that specifically changes how rabbits react, I think you're justified :)  As long as those conflicting mods are written well enough, they should be able to handle a conflict gracefully, anyway.

 

 

You could probably also manage to just extend the functionality of the RunAway behaviour, though that'd take a bit more work.

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...