Jump to content

Recommended Posts

Hi! One of the downsides of a mod character I'm working on is that they can't equip things to the chest slot. Backpacks, armor, stuff like that.

But I realized that suspicious marbles are equipped to the same slot, and I wanna adjust the code so it doesn't cause any issues.

Problem is, I'm not sure what I'm doing with this that isn't working.

	-- Force unequip.
	    inst:ListenForEvent("equip", function(inst, data)
		  			local chestarmor = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)
					if chestarmor ~= nil then
					inst.components.inventory:DropItem(chestarmor)
					end
					end)

^ This was the original code before I realized this issue.

						    inst:ListenForEvent("equip", function(inst, data)
		  			local chestarmor = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)
					if chestarmor ~= nil then
						if chestarmor == "sculpture_rooknose" then
							inst.components.health:SetAbsorptionAmount(inst.components.hunger.current/300-0.2)
							else
						if chestarmor == "sculpture_knighthead" then
							inst.components.health:SetAbsorptionAmount(inst.components.hunger.current/300-0.2)
							else
						if chestarmor == "sculpture_bishophead" then
							inst.components.health:SetAbsorptionAmount(inst.components.hunger.current/300-0.2)
							else
					inst.components.inventory:DropItem(chestarmor)
					end
						end
						end
					end
		end)

^ This was my redo of the code.

It seems to still just unequip everything equipped to the body slot, rather than failing to do so when its a suspicious marble.

Also, the SetAbsorptionAmount thing is just a temporary thing pasted in there while I  tried getting the code working. The absorption change happens every time hunger changes so I figured just repeating something that already happens wouldn't mess things up.

You're on the right track here. Thankfully a simple enough fix; since you already have a nil check for chestarmor, you can test chestarmor.prefab == "thing" instead of chestarmor alone. This will be very useful later on if you do want specific prefabs to do specific things; all entities have .prefab attached to them, methinks. Try printing ThePlayer.prefab in the console!

Thank you! Changing it to 

						    inst:ListenForEvent("equip", function(inst, data)
		  			local chestarmor = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)
					if chestarmor ~= nil then
						if chestarmor.prefab == "sculpture_rooknose" then
							inst.components.health:SetAbsorptionAmount(inst.components.hunger.current/300-0.2)
							else
						if chestarmor.prefab == "sculpture_knighthead" then
							inst.components.health:SetAbsorptionAmount(inst.components.hunger.current/300-0.2)
							else
						if chestarmor.prefab == "sculpture_bishophead" then
							inst.components.health:SetAbsorptionAmount(inst.components.hunger.current/300-0.2)
							else
					inst.components.inventory:DropItem(chestarmor)
					end
						end
						end
					end
		end)

seems to do the trick. Can pick up the marbles but can't equip other things to the slot.

  • Health 1
16 hours ago, FerniFrenito said:
-- in master_postinit of the character
-- Can only equip his bag
local OldEquip = inst.components.inventory.Equip
inst.components.inventory.Equip = function(self, item, old_to_active)
  if not item or not item.components.equippable or not item:IsValid() then
    return
  end
  if
    (item.components.equippable.equipslot == EQUIPSLOTS.BODY and -- So that the prefab used in the body is only the one you want
    not (item.prefab == "prefab_name")) or
    item.components.equippable.equipslot == EQUIPSLOTS.HEAD -- so that nothing that goes on the head can be equipped
  then
    -- When the prefab is not what you need
    return -- we finished the function
  end
  return OldEquip(self, item, old_to_active) -- If the prefab is the one we are looking for, then we execute the function we overwrote to equip it
end

 

I think this result will be useful to you. It only requires a few modifications to solve your problem. Do you need me to modify it? It simply consists of adding "if" clauses, verifying if "prefab" is a suspicious marbles, if not then return nothing, if yes then execute OldEquip()

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