Jump to content

Need help editing equippable:GetDapperness


Recommended Posts

Hello, so I need help cause I don't really understand what I'm doing :wilson_ecstatic:!

So, basically I want when a character equips something with a dapperness value if the equip has a certain value and the character which equipped it has a certain value I want the character to receive no dapperness from that item. (basically I want to give nightmare items a inst.value then the character with the specific inst.value gets no sanity drain from them)

Spoiler

AddComponentPostInit("equippable", function(self)
	if not G.TheWorld.ismastersim then return end
	local GetDapperness_old = self.GetDapperness
	self.GetDapperness = function(self, owner, ...)
		if self.inst.nightmaremagic == true and owner.nightmaremagic_immune == true then
			return
		else
			return GetDapperness_old(self, owner, ...)
		end
	end
end)

--Obviously the code doesn't work lol

 

Thanks for any help and your time, have a great day :D!!

Link to comment
Share on other sites

I tried setting the item's dapperness to 0 by adding a ListenForEvent("equip") to the character, but the problem is the ListenForEvent("unequip") doesn't seem to have a way to call the item you unequipped so I can't revert the item's dapperness back to normal again for when other characters equip it which is why I thought just editing the dapperness function in equippable component would be better (and more proper way to do it), though I don't know how to do it myself :wilson_facepalm:..

Edited by Warbucks
Link to comment
Share on other sites

local function onequip(inst, owner) 
    owner.AnimState:OverrideSymbol("swap_body", "armor_sanity", "swap_body")
    inst:ListenForEvent("blocked", OnBlocked, owner)
    if owner:HasTag("shadowmagic") then  --- so that the sanity drain changes too 0 ---
    inst.components.equippable.dapperness = 0
	
end
end

local function onunequip(inst, owner) 
    owner.AnimState:ClearOverrideSymbol("swap_body")
    inst:RemoveEventCallback("blocked", OnBlocked, owner)
    inst.components.equippable.dapperness = TUNING.CRAZINESS_SMALL --- so that when un equiped it reverts back---
end

so basically the tag shadowmagic is just a example but basically you can replace this with whatever you want for whatever character, e.g for wes you would add mime inside the box. you can replace the functions with these 2 or you could just use these codes:

 

    if owner:HasTag("shadowmagic") then  --- so that the sanity drain changes too 0 --- (for when equiped)
    inst.components.equippable.dapperness = 0

    inst.components.equippable.dapperness = TUNING.CRAZINESS_SMALL --- so that when un equiped it reverts back--- (for when un equiped)

if you have an questions you can ask me anytime

Link to comment
Share on other sites

Yeah, I can change the dapperness of the equip when it's equipped/unequipped in the equip's prefab.

The problem is I want to edit existing items like the purple amulet, skeleton hat, dark sword, ect. and I would prefer not to copypaste their prefab files and overwrite them all to do that :(.

Link to comment
Share on other sites

try this code.
I'm busy right now so I'll explain later.
 

local function DappernessTweak(inst)
	if not (inst.nightmaremagic and inst.nightmaremagic_immune) then return end

	local _Recalc = inst.components.sanity.Recalc
	function inst.components.sanity.Recalc(self, dt)
		local NegativeNegater = 0
		for k, v in pairs(self.inst.components.inventory.equipslots) do
			if (v:HasTag("tag") 
			or v:HasTag("ttag") 
			or v.prefab == "prefab"
			or v.prefab == "prefab2") and -- add the tag or prefab you want to filter
			v.components.equippable ~= nil then 
				local itemdap = v.components.equippable:GetDapperness(self.inst) -- Get each dapperness of items
				NegativeNegater = itemdap < 0 and NegativeNegater - itemdap or NegativeNegater -- Negate the 'negative' dapperness by subtracting the amount of dapperness.
			end
		end
		self.dapperness = NegativeNegater ~= 0 and NegativeNegater or 0
		return _Recalc(self, dt)
	end
end

 

Link to comment
Share on other sites

@YakumoYukari Hey, thanks for always helping out with these complicated codes :wilson_laugh:!!

The code seems to work perfectly, thank you :D!

Now the only thing is if you can help modify it that would be great :)!

Basically, instead of removing the sanity drain if char has a specific value, I'd like to multiply the dapperness of the equip(s) against a value containing a number the char would have. Like "self.inst.darkmagicres" would multiply against the dapperness then char can either have more/less sanity loss, sanity gain, or immunity.

This is the code so far (basically unchanged lol), but can't figure out how to edit it myself to work like that :wilson_ecstatic:

Spoiler

function G.Nightmareitem_Dapperness(inst)
	local _Recalc = inst.components.sanity.Recalc
	
	function inst.components.sanity.Recalc(self, dt)
	
		local NegativeNegate = 0
		for k, v in pairs(self.inst.components.inventory.equipslots) do
		
			if v.nightmareitem and v.components.equippable then
				local dapper = v.components.equippable:GetDapperness(self.inst) -- Get dapperness of equips
				NegativeNegate = dapper < 0 and NegativeNegate - dapper or NegativeNegate -- Negate the 'negative' dapperness by subtracting the amount of dapperness
			end
			
		end
		
		self.dapperness = NegativeNegate ~= 0 and NegativeNegate or 0
		return _Recalc(self, dt)
	end
end

 

and thanks for all your help with all the codes you made :wilson_laugh:!!

Link to comment
Share on other sites

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
 Share

×
  • Create New...