Jump to content

Recommended Posts

I've been trying to work on getting this mod revamped/changed but I can't get the stay/come mechanic to work properly on the brain I have. It always fails on line 26, would someone have a way to make it so that either the leader can only interact or any player can? I'm not too picky either way.  

hellhoundbrain.lua

Hello. Could you please share with your error? It looks like in context that you're having problems with components.follower.leader. But the error itself quite important. With all information I was given I had came up with something like that:
 

require "behaviours/follow"
require "behaviours/wander"
require "behaviours/standstill"
require "behaviours/chaseandattack"
require "behaviours/doaction"
require "behaviours/faceentity"
require "behaviours/minperiod"

local hellhoundbrain = Class(Brain, function(self, inst)
    Brain._ctor(self, inst)
end)

-- Don't know if you have one in modmain.lua or elsewhere
local SIT_BOY_DIST = 10000
local MIN_FOLLOW_LEADER = 1
local MAX_FOLLOW_LEADER = 8
local TARGET_FOLLOW_LEADER = 5

local function GetLeader(inst)
    return inst.components.follower ~= nil and inst.components.follower.leader or nil
end

-- Allow any player to interact if desired
local function GetInteracterFn(inst)
    local leader = inst.components.follower.leader
    -- Option 1: Leader only
    if inst.components.houndherded:IsTryingToInteractWithMe(leader) then
        return leader
    end
    
    -- Option 2: Any player 
    --for _, v in ipairs(AllPlayers) do
    --    if inst.components.houndherded:IsTryingToInteractWithMe(v) then
    --        return v
    --    end
    --end
    
    return nil
end

-- Work with either leader-only or any-player interaction
local function KeepInteracterFn(inst, target)
    -- Option 1: Leader only
    return target == inst.components.follower.leader and inst.components.houndherded:IsTryingToInteractWithMe(target)
    
    -- Option 2: Any player
    --return inst.components.houndherded:IsTryingToInteractWithMe(target)
end

local function ShouldStandStill(inst)
    return inst.toldtostay == true and inst.components.follower:IsNearLeader(SIT_BOY_DIST)
end

local function StayPut(inst)
    inst.components.locomotor:Stop()
end

local function StayCheck(inst)
    if not inst.components.follower:IsNearLeader(SIT_BOY_DIST) then
        inst.toldtostay = nil
        inst:RemoveTag("staying")
    end
end

local function CanCombat(inst)
    local target = FindEntity(inst, TARGET_FOLLOW_LEADER, function(target) return target.prefab == "hound" end)
    return (not ShouldStandStill(inst)) or target ~= nil
end

local function ShouldFollow(inst)
    return not ShouldStandStill(inst) and 
           not (inst.components.combat.target and inst.components.combat.target.prefab == "hound")
end

function hellhoundbrain:OnStart()
    local root = PriorityNode(
    {    
        WhileNode(function() return ShouldFollow(self.inst) end, "ShouldFollow", 
            Follow(self.inst, GetLeader, MIN_FOLLOW_LEADER, TARGET_FOLLOW_LEADER, MAX_FOLLOW_LEADER)),
        
        WhileNode(function() return CanCombat(self.inst) end, "CanCombat", 
            ChaseAndAttack(self.inst, MAX_FOLLOW_LEADER)),
        
        FaceEntity(self.inst, GetInteracterFn, KeepInteracterFn),
        
        WhileNode(function() return not ShouldStandStill(self.inst) end, "MaybeFollow", 
            DoAction(self.inst, StayCheck)),
        
        WhileNode(function() return ShouldStandStill(self.inst) end, "ShouldStay", 
            DoAction(self.inst, StayPut)),
        
        Wander(self.inst),
    }, .5)

    self.bt = BT(self.inst, root)
end

return hellhoundbrain

If it's won't work or you meant something else please share the error, maybe some more code if you think it's important.

20 hours ago, Meepenator said:

Oh mb, I should probably share the component as well then, it's still giving a nil for both, added most of the files I think may have issues. Ty for any help you can give.

Screenshot_367.png

houndherded.lua 579 B · 0 downloads modmain.lua 16.85 kB · 0 downloads dramoshellhound.lua 8.99 kB · 0 downloads

Hello again, sorry for not answearing yesterday, could you please in future like quote my messages so klei forums give me notification? Thank you for the information you provided, I'm sorry but I couldn't fix the problem today, it's 31 of December so everyone is busy :), I'll help you later. From what I seen in your files I have a few questions for you, for example in modmain.lua for some reason you're using G as a GLOBAL, not _G, it's okey, your choise. 

local G = GLOBAL
local Action = G.Action
local ACTIONS = G.ACTIONS
local ActionHandler = G.ActionHandler

But later on you're using GLOBAL anyway, like, why??
 

local require = GLOBAL.require
local STRINGS = GLOBAL.STRINGS

local resolvefilepath = GLOBAL.resolvefilepath

local Ingredient = GLOBAL.Ingredient
local RECIPETABS = GLOBAL.RECIPETABS
local Recipe = GLOBAL.Recipe
local TECH = GLOBAL.TECH

GLOBAL.FOODTYPE.BLOODFRUIT = "BLOODFRUIT"

And here you declared Ingridient so you don't need to do it further, but still
 

-- Here you don't use GLOBAL.Ingridient which is cool because you already declared it
local traininglance = Ingredient( "training_weapon", 1)
traininglance.atlas = "images/inventoryimages/training_weapon.xml"

-- But here you're using GLOBAL.Ingridient, it's like 5 line's after you did everything alright!
local bloodfruit_recipe = AddRecipe("bloodfruit",
	{ GLOBAL.Ingredient("pomegranate", 1), GLOBAL.Ingredient("redgem", 1), GLOBAL.Ingredient("nightmarefuel", 5) },
	RECIPETABS.FARM, TECH.NONE,
	nil, nil, nil, nil,
	nil, "images/inventoryimages/bloodfruit.xml", "bloodfruit.tex")
bloodfruit_recipe.tagneeded = false
bloodfruit_recipe.builder_tag ="demondramos"
bloodfruit_recipe.atlas = resolvefilepath("images/inventoryimages/bloodfruit.xml")

local hat_bloodcrown_recipe = AddRecipe("hat_bloodcrown",
	{ GLOBAL.Ingredient("marble", 12), GLOBAL.Ingredient("redgem", 3), GLOBAL.Ingredient("nightmarefuel", 10) },
	RECIPETABS.WAR, TECH.NONE,
	nil, nil, nil, nil,
	nil, "images/inventoryimages/hat_bloodcrown.xml", "hat_bloodcrown.tex")

And I got it, it's not making you're code don't work, but it's make it unreadable and hard to work with. I understand that you're taking some part of code from other mod but what you should understand is what does that code mean. Maybe you're not interested in being criticized like that and you just wanna funny mod to play with your friends and forget about Lua forever and ever after. I promise to you that at this point I will help you, not today but later on. Just use _G instead of G and use _G instead of GLOBAL and sometimes don't use GLOBAL meaning you'll be fine. Also, dramoshellhound.lua, I understand that problem in brains so for now it don't matter but this line, this line is kinda sus

					if fruitspawn ~= nil then       
						fruitspawn.Transform:SetPosition(victim.Transform:GetWorldPosition())
						end

Also, before I forgot, make sure that you'll save the leader OnSave and load it OnLoad. Again, sorry for not helping you out today, yesterday will be the day, just telling you the global problems of your code. See you tommorow.

    inst.entity:AddNetwork()

		inst.DynamicShadow:SetSize(2.5, 1.5)
    inst.Transform:SetFourFaced()
On 12/31/2024 at 3:44 AM, Mr.CrazyPotato said:

Hello again, sorry for not answearing yesterday, could you please in future like quote my messages so klei forums give me notification? Thank you for the information you provided, I'm sorry but I couldn't fix the problem today, it's 31 of December so everyone is busy :), I'll help you later. From what I seen in your files I have a few questions for you, for example in modmain.lua for some reason you're using G as a GLOBAL, not _G, it's okey, your choise. 

local G = GLOBAL
local Action = G.Action
local ACTIONS = G.ACTIONS
local ActionHandler = G.ActionHandler

But later on you're using GLOBAL anyway, like, why??
 

local require = GLOBAL.require
local STRINGS = GLOBAL.STRINGS

local resolvefilepath = GLOBAL.resolvefilepath

local Ingredient = GLOBAL.Ingredient
local RECIPETABS = GLOBAL.RECIPETABS
local Recipe = GLOBAL.Recipe
local TECH = GLOBAL.TECH

GLOBAL.FOODTYPE.BLOODFRUIT = "BLOODFRUIT"

And here you declared Ingridient so you don't need to do it further, but still
 

-- Here you don't use GLOBAL.Ingridient which is cool because you already declared it
local traininglance = Ingredient( "training_weapon", 1)
traininglance.atlas = "images/inventoryimages/training_weapon.xml"

-- But here you're using GLOBAL.Ingridient, it's like 5 line's after you did everything alright!
local bloodfruit_recipe = AddRecipe("bloodfruit",
	{ GLOBAL.Ingredient("pomegranate", 1), GLOBAL.Ingredient("redgem", 1), GLOBAL.Ingredient("nightmarefuel", 5) },
	RECIPETABS.FARM, TECH.NONE,
	nil, nil, nil, nil,
	nil, "images/inventoryimages/bloodfruit.xml", "bloodfruit.tex")
bloodfruit_recipe.tagneeded = false
bloodfruit_recipe.builder_tag ="demondramos"
bloodfruit_recipe.atlas = resolvefilepath("images/inventoryimages/bloodfruit.xml")

local hat_bloodcrown_recipe = AddRecipe("hat_bloodcrown",
	{ GLOBAL.Ingredient("marble", 12), GLOBAL.Ingredient("redgem", 3), GLOBAL.Ingredient("nightmarefuel", 10) },
	RECIPETABS.WAR, TECH.NONE,
	nil, nil, nil, nil,
	nil, "images/inventoryimages/hat_bloodcrown.xml", "hat_bloodcrown.tex")

And I got it, it's not making you're code don't work, but it's make it unreadable and hard to work with. I understand that you're taking some part of code from other mod but what you should understand is what does that code mean. Maybe you're not interested in being criticized like that and you just wanna funny mod to play with your friends and forget about Lua forever and ever after. I promise to you that at this point I will help you, not today but later on. Just use _G instead of G and use _G instead of GLOBAL and sometimes don't use GLOBAL meaning you'll be fine. Also, dramoshellhound.lua, I understand that problem in brains so for now it don't matter but this line, this line is kinda sus

					if fruitspawn ~= nil then       
						fruitspawn.Transform:SetPosition(victim.Transform:GetWorldPosition())
						end

Also, before I forgot, make sure that you'll save the leader OnSave and load it OnLoad. Again, sorry for not helping you out today, yesterday will be the day, just telling you the global problems of your code. See you tommorow.

    inst.entity:AddNetwork()

		inst.DynamicShadow:SetSize(2.5, 1.5)
    inst.Transform:SetFourFaced()

Apologies the holidays and work kept me so much more busy than I would like. I won't lie this mod is something I work on every year or so, so the whole mix of Global was probably after I made an update or 2 to the character so I kinda forgot what happened and had to learn from scratch. The fruitspawn is how you spawn in the familiar, taken from old abigail/wendy, using a the "bloodfruit" item.

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