Jump to content

Recommended Posts

I added the tag "notarget" to it, so other mobs won't attack it for nothing. But when my mob attacks other mobs, they will still hit my mob.

Is it possible to make them ignore my mob completely?

I tried making a combat component postinit but I have no idea of what am I doing.

Thank you!

15 minutes ago, . . . said:

you can make it that when your mob attacks a target the target loses aggro

target.components.combat:DropTarget()
target.components.combat:SetTarget(nil)

Where should I put this? I made it like this and did not work :c

This code is from frog.lua, and I made some modifications.

local RESTARGET_MUST_TAGS = {"_combat","_health"}
local function retargetfn(inst)
    if not inst.components.health:IsDead() then
        return FindEntity(inst, TUNING.FROG_TARGET_DIST, 
        function(guy)
            if not guy.components.health:IsDead() and not guy:HasTag("player") then
                guy.components.combat:DropTarget()
                guy.components.combat:SetTarget(nil)
                return true
            end
        end,
        RESTARGET_MUST_TAGS
        )
    end
end

 

you would put this code inside your entity

-- Put this above the fn thing
local function AttackEnemy(inst, data)
	if data.target ~= nil then
		data.target.components.combat:DropTarget()
		data.target.components.combat:SetTarget(nil)
	end
end

-- Put this inside its fn, where all the addcomponent and stuff liek that is (not the place where tags are added)
inst:ListenForEvent("onattackother", AttackEnemy)

 

4 minutes ago, . . . said:

you would put this code inside your entity


-- Put this above the fn thing
local function AttackEnemy(inst, data)
	if data.target ~= nil then
		data.target.components.combat:DropTarget()
		data.target.components.combat:SetTarget(nil)
	end
end

-- Put this inside its fn, where all the addcomponent and stuff liek that is (not the place where tags are added)
inst:ListenForEvent("onattackother", AttackEnemy)

 

This didn't work too. Maybe I have done something wrong...?

2 minutes ago, Schulliya said:

This didn't work too. Maybe I have done something wrong...?

it crashed the game or the enemy still attacks?

maybe it needs a taskintime for this function

local function AttackEnemy(inst, data)
	if data.target ~= nil then
		data.target:DoTaskInTime(0, function()
			data.target.components.combat:DropTarget()
			data.target.components.combat:SetTarget(nil)
			data.target.components.combat:CancelAttack()
		end)
	end
end

 

Edited by . . .
11 minutes ago, . . . said:

it crashed the game or the enemy still attacks?

maybe it needs a taskintime for this function


local function AttackEnemy(inst, data)
	if data.target ~= nil then
		data.target:DoTaskInTime(0, function()
			data.target.components.combat:DropTarget()
			data.target.components.combat:SetTarget(nil)
			data.target.components.combat:CancelAttack()
		end)
	end
end

 

no, still doesn't work. it doesn't crashes

well, it kinda works. The other mob won't attack my mob sometimes, but sometimes it will

edit: ok I am testing this for a while now, and it only failed the first times. Now it works perfectly. Thank you so much!

Edited by Schulliya

I just edited the comment above, now it works, I don't understand though... why would it not work the first time? maybe i'm just crazy, and it worked fine all time long hahahahahahaha

and thank you much!

Edited by Schulliya

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