Jump to content

Help with an item trait that triggers changes in enemies?


Recommended Posts

Looking for some help to make an item that will alter the behavior of enemies when it's worn by the player (namely pacifying them or altering the range at which they see the player), and I simply don't know how to do that in particular. I dunno if this is something that can be accomplished through multiple means, but any ideas or information would be appreciated :>

Link to comment
Share on other sites

I'm no modder but from what I know I think you could start looking at how the Spider Hat works, code-wise....and sadly, that's all the help I can give you. Hope that points you towards the right direction nonetheless.

 

Thank you kindly, I'll give it a look and see if I can achieve the effect I'm looking for :)

Link to comment
Share on other sites

@Cowboypunkcolt

 

Example on how to change the target range of spiders.

Note: This will affect spiders targeting any entity, even if it's not the player.

_G = GLOBALTUNING = _G.TUNINGFindEntity = _G.FindEntitylocal short_target_dist = 2local short_investigate_dist = 4local function spider_postinit(inst)	-- Should probably preserve the functionality of this to improve compatibility..	local old_NormalRetarget = inst.components.combat.targetfn	-- Copied from spider.lua	local function NormalRetarget(inst)		local targetDist = short_target_dist		if inst.components.knownlocations:GetLocation("investigate") then			targetDist = short_investigate_dist		end		local function enitity_search(guy)			if inst.components.combat:CanTarget(guy)				and not (inst.components.follower and inst.components.follower.leader == guy)			then				return guy:HasTag("character")			end		end		return FindEntity(inst, targetDist, enitity_search)	end	inst.components.combat:SetRetargetFunction(1, NormalRetarget)endAddPrefabPostInit(spider_postinit)

You should also be able to pacify the spiders in the enitity_search function by checking for the player's hat (or other equipment), then not returning the player if you find it.

local function enitity_search(guy)	if inst.components.combat:CanTarget(guy)		and not (inst.components.follower and inst.components.follower.leader == guy) then		if guy:HasTag("player") then			local hat = guy.components.inventory.equipslots.HEAD and guy.components.inventory.equipslots.HEAD.prefab			-- You can use another equip slot for other items			if hat.prefab ~= "your_hat_prefab" then				return guy:HasTag("character")			end		else			return guy:HasTag("character")		end	endend
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...