Jump to content

Recommended Posts

@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 by Thibooms

@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 by Seiai

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 by Seiai

@Seiai

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

post-545334-0-64605300-1432681226_thumb.

Edited by Crestonia

It says there needs to be an expected "then" by "near" or something like that, I think.

replace

if inst.components.childspawner and picker not picker:HasTag("player") then
with

if 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 by Seiai

Another way to do this is by using

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)	endend)

this in modmain.

 

And having

inst: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 tallbird

This means that if you hit the tallbird, you will have it as target and it will get pissed off.

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

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
×
  • Create New...