Jump to content

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

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 :)

@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
Edited by Blueberrys

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