Jump to content

Recommended Posts

RUSSIAN

Есть персонаж. Нужно сделать так, что бы Pig Guards нападали на персонажа только тогда, когда он атакует тотемы. В обычном случае выводили пользовательские сообщения (в смысле заданные мною) при нахождении рядом с ними.

Начал копать в сторону свинных мозгов (pigguardbrain.lua) и добавил туда строчки:

local function ThisIsMyCharacter(inst)    local busy = inst.sg:HasStateTag("sleeping") or inst.sg:HasStateTag("busy") --or inst.sg:HasStateTag("flight")    if not busy then          local threat = FindEntity(inst, KEEP_FACE_DIST, nil, nil, {'notarget'}, {'mycharacter'})        return threat ~= nil or TheWorld.state.isnight    endend

Для определения своего персонажа и модифицировал поведение так:

...IfNode(function() return not ThisIsMyCharacter(self.inst) end, "Threat Near",  ChattyNode(self.inst, STRINGS.PIG_GUARD_TALK_LOOKATWILSON,    FaceEntity(self.inst, GetFaceTargetFn, KeepFaceTargetFn))),IfNode(function() return ThisIsMyCharacter(self.inst) end,  ChattyNode(self.inst, STRINGS.PIG_GUARD_TALK_LOOKATMYCHARACTER)),...

В правильном ли я направлении двигаюсь? И как мне заставить свинных защитников вести себя так как я хочу?

 

ENGLISH

I made a character. Now I want Pig Guards to attack the character only if the character attack totems. If the character does not touch the totems, Pig Guards greet the character in some way (for example: "You are welcome here").

I have started from pigs brain (pigguardbrain.lua) and added to file these:

local function ThisIsMyCharacter(inst)    local busy = inst.sg:HasStateTag("sleeping") or inst.sg:HasStateTag("busy") --or inst.sg:HasStateTag("flight")    if not busy then          local threat = FindEntity(inst, KEEP_FACE_DIST, nil, nil, {'notarget'}, {'mycharacter'})        return threat ~= nil or TheWorld.state.isnight    endend

for opportunity to get the character as target and modify these:

...IfNode(function() return not ThisIsMyCharacter(self.inst) end, "Threat Near",  ChattyNode(self.inst, STRINGS.PIG_GUARD_TALK_LOOKATWILSON,    FaceEntity(self.inst, GetFaceTargetFn, KeepFaceTargetFn))),IfNode(function() return ThisIsMyCharacter(self.inst) end,  ChattyNode(self.inst, STRINGS.PIG_GUARD_TALK_LOOKATMYCHARACTER)),...

Am I take a right direction? And how can I get it work?
(Sorry for my bad english)

In the threat search "ThisIsMyCharacter", shouldn't you put the 'mycharacter' tag with the 'notarget' tag? Also, did you make sure your character has the 'mycharacter' tag? Im not sure what you're trying to achieve.

 

Look at this to learn more about brains. (not Klei website)

In the threat search "ThisIsMyCharacter", shouldn't you put the 'mycharacter' tag with the 'notarget' tag? Also, did you make sure your character has the 'mycharacter' tag? Im not sure what you're trying to achieve.

 

Look at this to learn more about brains. (not Klei website)

 

Maybe, but it works with frog's brains.

If these add tag to the character:

local common_postinit = function(inst)  inst:RemoveTag("scarytoprey")  inst:AddTag("mycharacter")end

Then yes, my character has the 'mycharacter' tag.

Im trying to establish peace with Pig Guards even when I come too close to their totems.

 

Btw, thank you for fast reply.

Hm. Seems like I test it wrong... Until I find some evidence that my code is working (pigs guards spawn very rarely and I dont quite sure that console commands spawn it right), I wouldnt mark this topic as SOLVED.

 

But here my solution:

local function TorchAttacked(inst)    local home = inst.components.homeseeker ~= nil and inst.components.homeseeker.home or nil    local character = FindClosestPlayerToInst(inst, START_FACE_DIST, true)    if character.components.combat.target == home then return attacker end    return nilendlocal function ThisIsMyCharacter(inst)    local busy = inst.sg:HasStateTag("sleeping") or inst.sg:HasStateTag("busy") --or inst.sg:HasStateTag("flight")    if not busy then         local threat = FindEntity(inst, KEEP_FACE_DIST, nil, nil, {'notarget', 'mycharacter'}, NO_TAGS)  -- or local threat = FindEntity(inst, KEEP_FACE_DIST, nil, nil, {'notarget'}, {'mycharacter'})        -- need to test it        return threat ~= nil or TheWorld.state.isnight    endend

and modifyed befavior node:

{ --TorchAttacked(self.inst) or        WhileNode(function() return self.inst.components.hauntable ~= nil and self.inst.components.hauntable.panic end, "PanicHaunted", Panic(self.inst)),        WhileNode(function() return self.inst.components.health.takingfiredamage end, "OnFire", Panic(self.inst)),        IfNode(function() return TorchAttacked(self.inst) ~= nil or not ThisIsMyCharacter(self.inst) end, "Threat Near",           ChattyNode(self.inst, STRINGS.PIG_GUARD_TALK_FIGHT,            WhileNode(function() return self.inst.components.combat.target == nil or not self.inst.components.combat:InCooldown() end, "AttackMomentarily",              ChaseAndAttack(self.inst, SpringCombatMod(MAX_CHASE_TIME), SpringCombatMod(MAX_CHASE_DIST)))),          ChattyNode(self.inst, STRINGS.PIG_GUARD_TALK_FIGHT,            WhileNode(function() return self.inst.components.combat.target ~= nil and self.inst.components.combat:InCooldown() end, "Dodge",              RunAway(self.inst, function() return self.inst.components.combat.target end, RUN_AWAY_DIST, STOP_RUN_AWAY_DIST)))),        WhileNode(function() return ShouldGoHome(self.inst) end, "ShouldGoHome",        ChattyNode(self.inst, STRINGS.PIG_GUARD_TALK_GOHOME,            DoAction(self.inst, GoHomeAction, "Go Home", true))),        ChattyNode(self.inst, STRINGS.PIG_TALK_FIND_MEAT,            DoAction(self.inst, function() return FindFoodAction(self.inst) end)),        ChattyNode(self.inst, STRINGS.PIG_GUARD_TALK_TORCH,            DoAction(self.inst, AddFuelAction, "Add Fuel", true)),        IfNode(function() return not ThisIsMyCharacter(self.inst) end, "Threat Near",          ChattyNode(self.inst, STRINGS.PIG_GUARD_TALK_LOOKATWILSON,            FaceEntity(self.inst, GetFaceTargetFn, KeepFaceTargetFn))),        IfNode(function() return ThisIsMyCharacter(self.inst) end,          ChattyNode(self.inst, STRINGS.PIG_GUARD_TALK_LOOKATSLAVYA            FaceEntity(self.inst, GetFaceTargetFnSlavya, KeepFaceTargetFnSlavya))),        Wander(self.inst, function() return self.inst.components.knownlocations:GetLocation("home") end, MAX_WANDER_DIST)    }, .25)

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