Crestonia Posted May 25, 2015 Share Posted May 25, 2015 (edited) Is it possible to have Tallbirds never be aggressive to a character? Even when you steal their eggs? If so, can someone tell me what and where to input that in my character's code? Edited May 25, 2015 by Crestonia Link to comment https://forums.kleientertainment.com/forums/topic/54397-tallbirdsis-this-possible/ Share on other sites More sharing options...
Fancy_Fox_Pers Posted May 25, 2015 Share Posted May 25, 2015 (edited) @Crestonia, The way I see it, you need to tell the tallbird that it cannot attack a prefab with a certain tag. For the tag I know you have to put this in your common_postinit function (located in your character's lua) : inst:AddTag("tallbirdwhisperer") This just gives your character, say, another name. Then you'd have to use a PrefabPostInit to change the tallbird's code, specifically the functions responsible for targeting someone (so check the tallbird lua in the game's data files, there should be a Retarget function). I don't know too much about how to properly use PrefabPostInit (especially what code you use for "return not guy:HasTag("tallbirdwhisperer") which might work or might crash because the game doesn"t know what you mean) so you're going to need someone else for that if you get stuck there. Sorry. I do hope this can get you a bit further. :-/ Edited May 25, 2015 by Thibooms Link to comment https://forums.kleientertainment.com/forums/topic/54397-tallbirdsis-this-possible/#findComment-640461 Share on other sites More sharing options...
Crestonia Posted May 25, 2015 Author Share Posted May 25, 2015 @Thibooms Thanks! Link to comment https://forums.kleientertainment.com/forums/topic/54397-tallbirdsis-this-possible/#findComment-640466 Share on other sites More sharing options...
Seiai Posted May 26, 2015 Share Posted May 26, 2015 (edited) @Crestonia,this should work in your modmain(didn't clean it of possible synthaxerrors yet though):AddPrefabPostInit("tallbird",function(inst)inst.components.combat:SetRetargetFunction(3,function(inst) local function IsValidTarget(guy) return not guy.components.health:IsDead() and inst.components.combat:CanTarget(guy) --smallbirds that aren't companions are parented --to other tallbirds, so don't target them! and (not inst:HasTag("smallbird") or inst:HasTag("companion")) and not inst:HasTag("player") end return --Threat to nest inst.components.homeseeker ~= nil and inst.components.homeseeker:HasHome() and FindEntity( inst.components.homeseeker.home, SpringCombatMod(TUNING.TALLBIRD_DEFEND_DIST), IsValidTarget, { "_combat", "_health" }, { "tallbird" }, { "character", "animal", "monster" }) or --Nearby pigman (Why the hatred for pigs? It's expensive!) FindEntity( inst, SpringCombatMod(TUNING.TALLBIRD_TARGET_DIST), IsValidTarget, { "pig", "_combat", "_health" }, { "werepig" }) or --Nearby character or monster FindEntity( inst, SpringCombatMod(TUNING.TALLBIRD_TARGET_DIST), IsValidTarget, { "_combat", "_health" }, { "tallbird" }, { "character", "monster" })end)end)AddPrefabPostInit("tallbirdnest",function(inst)inst.components.pickable:SetOnPickedFn(function(inst, picker) inst.thief = picker inst.AnimState:PlayAnimation("nest") inst.components.childspawner.noregen = true if inst.components.childspawner and picker not picker:HasTag("player") then for k,v in pairs(inst.components.childspawner.childrenoutside) do if v.components.combat then v.components.combat:SuggestTarget(picker) end end end inst:DoTaskInTime(0, StartNesting)end)end) Edited May 26, 2015 by Seiai Link to comment https://forums.kleientertainment.com/forums/topic/54397-tallbirdsis-this-possible/#findComment-640842 Share on other sites More sharing options...
Seiai Posted May 26, 2015 Share Posted May 26, 2015 (edited) if u wouldn't want it to fight players at all, even if u attack it, u would have to change the KeepTarget function of the tallbird instead. if u want it to be specific to a certain character instead of all player, u would have to replace :HasTag("player") either with .prefab=="yourcharactersprefabname" or as @Thibooms suggested, add a new tag to your Character and use :HasTag("yourtag") Edited May 26, 2015 by Seiai Link to comment https://forums.kleientertainment.com/forums/topic/54397-tallbirdsis-this-possible/#findComment-640845 Share on other sites More sharing options...
Crestonia Posted May 26, 2015 Author Share Posted May 26, 2015 (edited) @SeiaiThank you for the help, but I don't understand why it crashed. It says there needs to be an expected "then" by "near" or something like that, I think. I looked at the code but I saw both... Can you help my with the issue? Here's the screenshot. Also I replaced the HasTag "player" with a tag I made my current character have. Edited May 26, 2015 by Crestonia Link to comment https://forums.kleientertainment.com/forums/topic/54397-tallbirdsis-this-possible/#findComment-640969 Share on other sites More sharing options...
Seiai Posted May 26, 2015 Share Posted May 26, 2015 (edited) It says there needs to be an expected "then" by "near" or something like that, I think.replaceif inst.components.childspawner and picker not picker:HasTag("player") thenwithif inst.components.childspawner and picker and not picker:HasTag("player") then"'then' expected near 'not'" means that it expected the 'then' instead/before the 'not', because the 'and' was missing. Edited May 26, 2015 by Seiai Link to comment https://forums.kleientertainment.com/forums/topic/54397-tallbirdsis-this-possible/#findComment-640980 Share on other sites More sharing options...
Seiai Posted May 27, 2015 Share Posted May 27, 2015 (edited) oh yeah, and u will probably have to slap GLOBAL. in front of some things like FindEntity and TUNING, because the modmain is not in the same context as prefabs(where the functions are from). Edited May 27, 2015 by Seiai Link to comment https://forums.kleientertainment.com/forums/topic/54397-tallbirdsis-this-possible/#findComment-640992 Share on other sites More sharing options...
Crestonia Posted May 27, 2015 Author Share Posted May 27, 2015 (edited) @SeiaiIt didn't crash at first, but when I got near the biome where tallbirds are, it crashed. I don't know very much about global things or the modmain in general xD Edited May 27, 2015 by Crestonia Link to comment https://forums.kleientertainment.com/forums/topic/54397-tallbirdsis-this-possible/#findComment-641081 Share on other sites More sharing options...
DarkXero Posted May 27, 2015 Share Posted May 27, 2015 Another way to do this is by usingAddPrefabPostInit("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) endend)this in modmain. And havinginst:AddTag("tallbird")in the character's prefab. The tallbird tag makes you not a target during retargeting.The tallbird tag also makes you not a menace when the tallbird checks for threats for the nest.So you get the tallbird acting chill, as if you are not there. Now, when you steal the egg, the nest suggests you as a target.In that case we can edit the nest function, or put a condition in the suggestion of the tallbird.We add that if a target suggested:- is a target, and that it has the tallbird tag, then we check- if the combat target of the entity with the tallbird tag is the tallbirdThis means that if you hit the tallbird, you will have it as target and it will get pissed off. Link to comment https://forums.kleientertainment.com/forums/topic/54397-tallbirdsis-this-possible/#findComment-641090 Share on other sites More sharing options...
Crestonia Posted May 27, 2015 Author Share Posted May 27, 2015 @DarkXero How do we edit the nest function? I don't know the lua language very well. Link to comment https://forums.kleientertainment.com/forums/topic/54397-tallbirdsis-this-possible/#findComment-641099 Share on other sites More sharing options...
DarkXero Posted May 27, 2015 Share Posted May 27, 2015 @Crestonia, what I posted should do the trick to make tallbirds not attack you (unless you hit them) AND let you steal their eggs. The first snippet would go in modmain, and the second snippet (a line) would go in your character's prefab file. It would avoid editing the nest, by modifying the result of interacting with the nest. If you want to work with what Seiai posted, it would end up like this:local FindEntity = GLOBAL.FindEntitylocal SpringCombatMod = GLOBAL.SpringCombatModAddPrefabPostInit("tallbird", function(inst) inst.components.combat:SetRetargetFunction(3, function(inst) local function IsValidTarget(guy) return not guy.components.health:IsDead() and inst.components.combat:CanTarget(guy) --smallbirds that aren't companions are parented --to other tallbirds, so don't target them! and (not inst:HasTag("smallbird") or inst:HasTag("companion")) and not guy:HasTag("tallbirdwhisperer") end return --Threat to nest inst.components.homeseeker ~= nil and inst.components.homeseeker:HasHome() and FindEntity(inst.components.homeseeker.home, SpringCombatMod(TUNING.TALLBIRD_DEFEND_DIST), IsValidTarget, { "_combat", "_health" }, { "tallbird" }, { "character", "animal", "monster" }) or --Nearby pigman (Why the hatred for pigs? It's expensive!) FindEntity(inst, SpringCombatMod(TUNING.TALLBIRD_TARGET_DIST), IsValidTarget, { "pig", "_combat", "_health" }, { "werepig" }) or --Nearby character or monster FindEntity(inst, SpringCombatMod(TUNING.TALLBIRD_TARGET_DIST), IsValidTarget, { "_combat", "_health" }, { "tallbird" }, { "character", "monster" }) end)end)local TUNING = GLOBAL.TUNINGlocal NEST_TIME = 35 * TUNING.SEG_TIMElocal TALLBIRD_LAY_DIST = 16local function StopNesting(inst) if inst.nesttask then inst.nesttask:Cancel() inst.nesttask = nil end inst.nesttime = nilendlocal Vector3 = GLOBAL.Vector3local function ForceLay(inst) if inst.components.childspawner and inst.components.pickable then for k, v in pairs(inst.components.childspawner.childrenoutside) do if distsq(Vector3(v.Transform:GetWorldPosition()), Vector3(inst.Transform:GetWorldPosition()) ) < TALLBIRD_LAY_DIST * TALLBIRD_LAY_DIST then inst.components.pickable:Regen() break end end endendlocal function DoNesting(inst) StopNesting(inst) if inst.components.pickable and not inst.components.pickable:CanBePicked() then inst.readytolay = true if inst:IsAsleep() then ForceLay(inst) end endendlocal function StartNesting(inst, time) StopNesting(inst) time = time or (NEST_TIME + math.random()) inst.nesttime = GetTime() + time inst.nesttask = inst:DoTaskInTime(time, DoNesting)endlocal function onpicked(inst, picker) inst.thief = picker inst.AnimState:PlayAnimation("nest") inst.components.childspawner.noregen = true if inst.components.childspawner and picker and not picker:HasTag("tallbirdwhisperer") then for k,v in pairs(inst.components.childspawner.childrenoutside) do if v.components.combat then v.components.combat:SuggestTarget(picker) end end end inst:DoTaskInTime(0, StartNesting)endAddPrefabPostInit("tallbirdnest",function(inst) inst.components.pickable:SetOnPickedFn(onpicked)end)You would have to copy paste all the code needed by onpicked.And the code needed by the code needed by onpicked. Then put inst:AddTag("tallbirdwhisperer") in your character's prefab. Because if you check for the HasTag("player"), you will make tallbirds ignore everybody.Also, in IsValidTarget, instead of INST in seiai's code, it should be GUY, because GUY is the presumed target. Link to comment https://forums.kleientertainment.com/forums/topic/54397-tallbirdsis-this-possible/#findComment-641107 Share on other sites More sharing options...
Crestonia Posted May 27, 2015 Author Share Posted May 27, 2015 Thanks so much guys! I got it working thanks to all of your help Link to comment https://forums.kleientertainment.com/forums/topic/54397-tallbirdsis-this-possible/#findComment-641116 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