erdmanski1341 Posted March 5, 2014 Share Posted March 5, 2014 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:chaseandattackchaseandramstandandattackattackwallrunaway 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 https://forums.kleientertainment.com/forums/topic/32347-help-item-to-change-monsters-behavior/ Share on other sites More sharing options...
squeek Posted March 6, 2014 Share Posted March 6, 2014 (edited) 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)endsee 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) Edited March 6, 2014 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/32347-help-item-to-change-monsters-behavior/#findComment-424892 Share on other sites More sharing options...
erdmanski1341 Posted March 6, 2014 Author Share Posted March 6, 2014 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") endand 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 https://forums.kleientertainment.com/forums/topic/32347-help-item-to-change-monsters-behavior/#findComment-424950 Share on other sites More sharing options...
erdmanski1341 Posted March 6, 2014 Author Share Posted March 6, 2014 Nevermind, the solution was much easier than we anticipated... I simply added the following right below the "scarytoprey" tagsowner: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 https://forums.kleientertainment.com/forums/topic/32347-help-item-to-change-monsters-behavior/#findComment-424975 Share on other sites More sharing options...
Heavenfall Posted March 6, 2014 Share Posted March 6, 2014 Uhm, what if you wear the hat and attack someone? Link to comment https://forums.kleientertainment.com/forums/topic/32347-help-item-to-change-monsters-behavior/#findComment-425010 Share on other sites More sharing options...
squeek Posted March 6, 2014 Share Posted March 6, 2014 (edited) 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 Edited March 6, 2014 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/32347-help-item-to-change-monsters-behavior/#findComment-425011 Share on other sites More sharing options...
erdmanski1341 Posted March 6, 2014 Author Share Posted March 6, 2014 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 https://forums.kleientertainment.com/forums/topic/32347-help-item-to-change-monsters-behavior/#findComment-425328 Share on other sites More sharing options...
erdmanski1341 Posted March 8, 2014 Author Share Posted March 8, 2014 just wanted to update. almost finished, just gotta figure out how to take care of chester. they won't attack me, but he gets hit by monsters. Link to comment https://forums.kleientertainment.com/forums/topic/32347-help-item-to-change-monsters-behavior/#findComment-426792 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now