Jump to content

HELP! Item to change monster's behavior


Recommended Posts

I am making at custom hat called the "Tamer Hat" that when equipped turns all hostile creatures passive and makes animals that run away (rabbits, etc.) not flee.

 

I'm assuming the easiest way to do this would be to alter the behaviors on equip?  Possibly make them all default to "wander" while the hat is equipped?

 

The following would probably all need to be altered on equip:

chaseandattack

chaseandram

standandattack

attackwall

runaway

 

I originally thought about doing specific monsters, but figured that would require much more coding than just changing behavior files.

 

So I think this is the general idea on how to do it, but I have no idea what the code would be like.  Anyone provide some help?

Link to comment
Share on other sites

That's probably not the best approach. It'd probably be better to make the player return as an invalid target for the combat component when they're wearing the hat.

Something like this:

local Combat = require "components/combat"local Combat_CanTarget_base = Combat.CanTargetfunction Combat:CanTarget(target)	local equipped_hat = target.components.inventory and target.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD)	local is_wearing_tamer_hat = equipped_hat and equipped_hat.prefab == "tamerhat"	return not is_wearing_tamer_hat and Combat_CanTarget_base(self, target)end
see this thread for an explanation of how this works.

For rabbits fleeing, all you have to do is remove the "scarytoprey" tag from the player. In your hat prefab's fn function:

inst:AddComponent("equippable")local was_scary_to_prey = falseinst.components.equippable:SetOnEquip(function(inst, owner)	if owner:HasTag("scarytoprey") then		owner:RemoveTag("scarytoprey")		was_scary_to_prey = true	else		was_scary_to_prey = false	endend)inst.components.equippable:SetOnUnequip(function(inst, owner)	if was_scary_to_prey and not owner:HasTag("scarytoprey") then		owner:AddTag("scarytoprey")	endend)
Link to comment
Share on other sites

thanks for the response, I haven't tried out the first part, but i did get the second part of not scaring away rabbits down.

 

i tried your code, but didn't quite understand.  ended up using code from beefalo hat

 

added local functions:

local function tamerhat_equip(inst, owner)        onequip(inst, owner)        owner:RemoveTag("scarytoprey")    endlocal function tamerhat_unequip(inst, owner)        onunequip(inst, owner)        owner:AddTag("scarytoprey")    end

and then updated these lines in the prefab fn

   
  inst.components.equippable:SetOnEquip( tamerhat_equip )  inst.components.equippable:SetOnUnequip( tamerhat_unequip )

I did notice that the beefalo hat code adds "beefalo" tag to player on equip

 

Am I understanding this that it makes the beefalo think you are a beefalo?  Do you think simply adding the tag of a butterfly or some harmless creature be an easy shortcut to not being a target?

Link to comment
Share on other sites

Nevermind, the solution was much easier than we anticipated...

 

I simply added the following right below the "scarytoprey" tags

owner:AddTag("notarget")owner:RemoveTag("notarget")

I tested in game by spawning hounds, deerclops and spider dens.

 

As long as you have hat on when you encounter the creature, they will not attack.  A spider will come out of the den to investigate, but not attack.  If you remove the hat or attack the monster, den, hive, etc., the monster will attack as usual.  If you can manage to get far enough away and equip the hat and go back, they no longer are hostile again.  An added bonus was that you no longer scare birds away either.

 

It works as intended now, so just have to clean up the art and will get it up.

 

Any suggestions on crafting for this?  I currently have the recipe including beefalo wool, houndstooths and silk.  I am thinking of adding additional components (stingers, frog legs, maybe deerclops eye?) to make it more difficult to obtain...

Link to comment
Share on other sites

Nevermind, the solution was much easier than we anticipated...

 

owner:AddTag("notarget")owner:RemoveTag("notarget")
Ah, didn't realize there was a tag for that.

The reason I included the was_scary_to_prey variable is to make sure the hat didn't conflict with any custom characters that remove the "scarytoprey" tag. With your current code, if there was a custom character without the "scarytoprey" tag and they wore the tamerhat and then took it off, the "scarytoprey" tag would be added even though it wasn't there in the first place. However, what I posted won't work if you're not using anonymous functions, so here's something that should work for you:

 

local function tamerhat_equip(inst, owner)    onequip(inst, owner)    if owner:HasTag("scarytoprey") then        owner:RemoveTag("scarytoprey")        owner.tamerhat_was_scary_to_prey = true    endendlocal function tamerhat_unequip(inst, owner)    onunequip(inst, owner)    if owner.tamerhat_was_scary_to_prey then        owner:AddTag("scarytoprey")        owner.tamerhat_was_scary_to_prey = nil    endend
Link to comment
Share on other sites

Uhm, what if you wear the hat and attack someone?

 

They will attack you then.  It essentially makes monsters act like bees, they are cool with you as long as you don't hit them. 

 

I still want to test it on a tallbird and see if they attack you when you approach their nest.

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