Jump to content

[Need Help] Block Specific Item


Recommended Posts

Does anyone know how I can block my character from equipping a specific item?

It has the ability to build with half resources, but when it is equipped with the construction amulet and taken out, this ability disappears and the crafts become full resources.

If there is any way to ban the use of the construction amulet only for my character or that using it does not affect him at all when unequipping.

the code i am using is this in master_postinit()

inst.components.builder.ingredientmod = TUNING.GREENAMULET_INGREDIENTMOD

 

Link to comment
Share on other sites

There are a couple of ways to solve this problem. The simplest (though probably not best practice) is to use equipment restricted tags. Unfortunately, while you can restrict equipment to only be equippable by a certain character with a tag, you can't really do the opposite. It's sort of hacky, but you could give every other character a tag except for yours, then add this restricted tag to the construction amulet:

inst.components.equippable.restrictedtag = "YOUR TAG HERE"

There is a limit on the number of tags that you can add to a character though, and each one adds a bit of network overhead.

You could also modify the Equippable component and add your own functionality to prevent characters with certain tags from equipping certain items. It's a little more difficult but essentially the work is already done with the restrictedtag variable I mentioned before, it'd be the same thing but opposite. It would also be a good learning experience for how replicas, classifieds, and netvars work, which is some of the harder stuff to wrap your head around, and it would also be reusable.

Another relatively simple option would be to listen for the "equip" and "unequip" events on your character, check if data.item is the construction amulet, and then set the ingredient mod accordingly. With this method you could even have the bonuses stack, if you wanted.

Hope this helps.

Link to comment
Share on other sites

Hello Pal.
Thanks for answering, but it seems that I am not implementing it correctly because I get this error.

error.thumb.png.32bd2053c90db0ff333ae01edfaec072.png

I've put the code in master_postinit, I don't know if that's the right place to put it.

inst.components.equippable.restrictedtag = "greenamulet"

 

Link to comment
Share on other sites

So, a couple of things (I'm assuming you're going with the first method I listed). inst.components.equippable.restrictedtag applies to the construction amulet itself, so you don't want to put that in your character's file. As for what it does, you can imagine that it says "Ok, so I (the construction amulet) am only going to allow characters with this specific tag to equip this item. If they don't have the restricted tag, they can't equip it". You'd use it in an AddPrefabPostInit call in your modmain (the prefab in this case is "greenamulet"). You can then add said tag to all characters in an AddPlayerPostInit call in your modmain (in it, you'd include a check for your character so that you don't add the tag to them, thus they can't equip the construction amulet).

Does this make sense?

Link to comment
Share on other sites

I think one of the ways you were talking about is this. which I have already tried but I still don't understand how to modify it in the way that works to block only the construction amulet.

	
	--Can't equip armor
	local _Equip = 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 not item:HasTag("heavy")) or (item.components.equippable.equipslot == EQUIPSLOTS.HEAD and not (item.prefab == "deserthat" or item.prefab == "moonstorm_goggleshat")) then		
			self:DropItem(item)
			self:GiveItem(item)
			if inst and inst.components.talker then
				inst.components.talker:Say("It just falls right off of me!")
			end
			return
		end		
		return _Equip(self, item, old_to_active)	
	end

 

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