Jump to content

Can a Character Specific item be unable to pick up? (Not once picked up, then dropped.)


Recommended Posts

I need to know if I can make other characters unable to pick up my weapon; when I mean pick up, I don't mean once in inventory it gets dropped.

 local function onputininventory(inst, owner)
    if owner:HasTag("player") and not owner:HasTag("ethan") then
        inst:DoTaskInTime(0.01, function()
            owner.components.inventory:DropItem(inst, false, true)
            owner.components.talker:Say(GetActionFailString(inst, "CAGESHOVELPICKUP", "GENERIC"))
        end)
    end
end


 

I would like to change the "owner.components.inventory:DropItem(inst, false, true)" line to some bit of code that would make the item not even able to enter the inventory period. 

Anyone have any ideas? 

Link to comment
Share on other sites

Something along the lines of this:

AddComponentPostInit("inventoryitem", function(self)
	local oldOnPickup = self.OnPickup
	function self:OnPickup(pickupguy)
		if not self.inst:HasTag("issoulbound") or pickupguy == self.inst.itemowner then
			oldOnPickup(self, pickupguy)
		end
	end
end)

You'd need to at some point set the itemowner variable on the item inst to be your character. Whether that be when it's dropped or when it's first equipped, that's your choice, depending on what you want to do. You also need to add the tag "issoulbound" to it.

I could be more helpful, if you could tell me in more detail what you want. Is it a specific items for a character mod? Is it supposed to make ANY inventory-capable item souldbound to the person who dropped it? Which items are we talking about?

Link to comment
Share on other sites

21 hours ago, Ultroman said:

Something along the lines of this:


AddComponentPostInit("inventoryitem", function(self)
	local oldOnPickup = self.OnPickup
	function self:OnPickup(pickupguy)
		if not self.inst:HasTag("issoulbound") or pickupguy == self.inst.itemowner then
			oldOnPickup(self, pickupguy)
		end
	end
end)

You'd need to at some point set the itemowner variable on the item inst to be your character. Whether that be when it's dropped or when it's first equipped, that's your choice, depending on what you want to do. You also need to add the tag "issoulbound" to it.

I could be more helpful, if you could tell me in more detail what you want. Is it a specific items for a character mod? Is it supposed to make ANY inventory-capable item souldbound to the person who dropped it? Which items are we talking about?

Well, what I am trying to do is to make a tool only go into my character's inventory, but when it gets picked up by another character, I don't want it to be dropped once it goes into their inventory. I would rather be unable to pick up and a character to say an ACTIONFAIL string.

Edited by Cagealicous
Link to comment
Share on other sites

Just to be clear, you essentially want to make it like Thor's hammer, Mjolnir, which no one can pick up except Thor i.e. your specific character. If so, then the code I posted should do that. Just give it the tag "issoulbound", and when you add it to your character's inventory, set the itemowner variable to be your character's inst.

Link to comment
Share on other sites

4 minutes ago, Ultroman said:

Just to be clear, you essentially want to make it like Thor's hammer, Mjolnir, which no one can pick up except Thor i.e. your specific character. If so, then the code I posted should do that. Just give it the tag "issoulbound", and when you add it to your character's inventory, set the itemowner variable to be your character's inst.

How would I add dialogue for when the character tries to pick it up?

Link to comment
Share on other sites

Just now, Ultroman said:

Where you do that, depends on whether your character starts with the tool, or he needs to craft it or it can be found in the world.

Ok. I don't think I'm asking correctly. Sorry. What I mean to say is when another character tries picks it up, such as Wolfgang, they say a line of dialogue such as, "This tool is too mighty for Wolfgang!" How would I go about doing that?

Link to comment
Share on other sites

AddComponentPostInit("inventoryitem", function(self)
	local oldOnPickup = self.OnPickup
	function self:OnPickup(pickupguy)
		if not self.inst:HasTag("issoulbound") or pickupguy == self.inst.itemowner then
			oldOnPickup(self, pickupguy)
		elseif pickupguy.components.talker then
			pickupguy.components.talker:Say("That item is too mighty for me to wield.")
		end
	end
end)

 

You should probably have an extra safeguard:

AddComponentPostInit("inventoryitem", function(self)
	local oldOnPickup = self.OnPickup
	function self:OnPickup(pickupguy)
		if not self.inst:HasTag("issoulbound") or (self.inst.itemowner and pickupguy and pickupguy == self.inst.itemowner) then
			oldOnPickup(self, pickupguy)
		elseif pickupguy.components.talker then
			pickupguy.components.talker:Say("That item is too mighty for me to wield.")
		end
	end
end)

 

If it's just one or a few specific prefabs you want to do this for, then there's a better way. Is it just one prefab (tool)?

Edited by Ultroman
Link to comment
Share on other sites

12 minutes ago, Ultroman said:

AddComponentPostInit("inventoryitem", function(self)
	local oldOnPickup = self.OnPickup
	function self:OnPickup(pickupguy)
		if not self.inst:HasTag("issoulbound") or pickupguy == self.inst.itemowner then
			oldOnPickup(self, pickupguy)
		elseif pickupguy.components.talker then
			pickupguy.components.talker:Say("That item is too mighty for me to wield.")
		end
	end
end)

 

You should probably have an extra safeguard:


AddComponentPostInit("inventoryitem", function(self)
	local oldOnPickup = self.OnPickup
	function self:OnPickup(pickupguy)
		if not self.inst:HasTag("issoulbound") or (self.inst.itemowner and pickupguy and pickupguy == self.inst.itemowner) then
			oldOnPickup(self, pickupguy)
		elseif pickupguy.components.talker then
			pickupguy.components.talker:Say("That item is too mighty for me to wield.")
		end
	end
end)

 

If it's just one or a few specific prefabs you want to do this for, then there's a better way. Is it just one prefab (tool)?

Well, it's only two prefabs, also I seem to have run into a problem. image.thumb.png.e3556659ca358d8fb0f32c07fc6cbfd2.png

Link to comment
Share on other sites

You seem to be trying to run AddComponentPostInit from within a function. You can't do that. It has to be called directly in your modmain.lua. That aside, if it's just two prefabs, then there's a better way to do this.

Are those two prefabs both custom prefabs from your mod?

And how does your character obtain the prefabs? Does the character spawn with them? Does it have to craft them?

Link to comment
Share on other sites

That's different, then. The code we have right now, is essentially applied to ALL things that can be equipped. That's bad. We want to be as unintrusive as possible. This is also easier, then.

Please give me a zip of your mod. That'll make this easier.

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