Jump to content

Recommended Posts

So I searched the forums, found some nice threads with similiar topics, but overall I couldn't quite understand, even though I caught up to the point that it has something to do with targeting and recognizing the character as ie. a monster in case of Webber and spiders. So here's the question: Is it possible to make eyeplants neutral/friendly to your character, so the character won't be attacked by the eyeplants?



local function PlantsPostinit(inst)
    return FindEntity(inst, targetDist,
        function(guy)
            if inst.components.combat:CanTarget(guy) then
                return (guy:HasTag("character") and not guy:HasTag("monster"))
            end
    end)
end

local plants = {"eyeplant"}

for k,v in pairs(plants) do AddPrefabPostInit(v, PlantsPostInit) end

That's what I got so far since the morning. Tried to look into other mods that used similiar coding and I understood one thing - tagging is way too hard for me to imply them. I know that I had to write a code for retargeting like spiders used to have, but I couldn't make it to work as intended. So instead I started substract some code lines and add other ones, just to see if it starts working. In addition, from what I saw in many, many, MANY various threads - coding looked absolutely similiar, yet different. Tried to merge few lines, added my own coding and - what you can see above - I aoimn-\[ctually got a code that doesn't pop up an error, but also doesn't work at all.

Any ideas on what am I missing in here? Yes, I did add the "plantlike" tag to the character's modinfo.lua. I didn't mention I'm using DST Extended Sample Character. Is there any difference with what I want to achieve?

I also found this code in eyeplant.lua:

 

local function retargetfn(inst)

	    return FindEntity(inst, TUNING.EYEPLANT_ATTACK_DIST, function(guy)

	        if not guy.components.health:IsDead() then

	            return not checkmaster(guy, inst)

	        end

	    end,

	    {"_combat","_health"}, -- see entityreplica.lua

	    nil,

	    {"character","monster","animal","prey","eyeplant","lureplant"}

	    )

	end
 

Should I try to recode it to modmain.lua somehow or leave it in peace?

Edited by Isasinian
AddPrefabPostInit("eyeplant", function(inst)
    if GLOBAL.TheWorld.ismastersim then
        local OldRetarget = inst.components.combat.targetfn
        inst.components.combat:SetRetargetFunction(0.2, function()
            return OldRetarget and FindEntity(inst, GLOBAL.TUNING.EYEPLANT_ATTACK_DIST, function(guy) if guy:HasTag("eyeplantimmune") then return true end end)
        end)
    end
end)



Add the above to your modmain and add "eyeplantimmune" tag to your character's clientfn.
Didn't test it so I'm not sure if it'll work or not.

Edited by Fidooop

I can't seem to understand why, but there's a problem with this line:

function(guy) if guy:HasTag("eyeplantimmune") then return true end)

 

Especially the ")" sign after the "end". It's the line 81 in my coding. I checked all these signs and they look like they're not missing any.

Here's the screen: GaMgHdP.png

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