Jump to content

Recommended Posts

Hey folks

I developed a building mod to attract monsters's aggro.

During the test, I found it can't attract the aggro of shadow creature.

 

related code

local AGGRO_CANT_TAGS = { "INLIMBO", "player", "eyeturret", "engineering" }
local function AttractAggro(inst)
    local x, y, z = inst.Transform:GetWorldPosition()
    local range = PAINMAGNET_RANGE or 15

    local ents = TheSim:FindEntities(x, y, z, range, nil, AGGRO_CANT_TAGS)
    -- shadow creature
    for i, v in ipairs(ents) do
        if v:IsValid() and v:HasTag("shadowcreature") then
            print("found Shadow creature ",v.prefab)
        end
    end
    -- other monsters
    for i, v in ipairs(ents) do
        if v:IsValid() and v.components.combat and inst.components.combat:CanTarget(v) then
            if v:HasTag("_combat") then
                print("found target ",v.prefab)
                v.components.combat:GiveUp()
                v.components.combat:SetTarget(inst)
                -- v.components.health:DoDelta(-PAINMAGNET_DAMAGE, nil, "painmagnet")
            end
        end
    end

end

The key code don’t work.

There is no record in the server logs.

    local ents = TheSim:FindEntities(x, y, z, range, nil, AGGRO_CANT_TAGS)
    -- shadow creature
    for i, v in ipairs(ents) do
        if v:IsValid() and v:HasTag("shadowcreature") then
            print("found Shadow creature ",v.prefab)
        end
    end

 

Q1 how to find the shadow creature?

Q2 how to change the shadow creature's attack target to buildings?

 

The full mod source code is available in this repo:  https://github.com/yanghao5/painmagnet/tree/dev

 

Edited by hall123

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