Cagealicous Posted November 15, 2018 Share Posted November 15, 2018 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 More sharing options...
Ultroman Posted November 16, 2018 Share Posted November 16, 2018 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 More sharing options...
Cagealicous Posted November 17, 2018 Author Share Posted November 17, 2018 (edited) 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 November 17, 2018 by Cagealicous Link to comment Share on other sites More sharing options...
Ultroman Posted November 17, 2018 Share Posted November 17, 2018 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 More sharing options...
Cagealicous Posted November 17, 2018 Author Share Posted November 17, 2018 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 More sharing options...
Ultroman Posted November 17, 2018 Share Posted November 17, 2018 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. Link to comment Share on other sites More sharing options...
Cagealicous Posted November 17, 2018 Author Share Posted November 17, 2018 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 More sharing options...
Ultroman Posted November 17, 2018 Share Posted November 17, 2018 (edited) 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 November 17, 2018 by Ultroman Link to comment Share on other sites More sharing options...
Cagealicous Posted November 17, 2018 Author Share Posted November 17, 2018 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. Link to comment Share on other sites More sharing options...
Ultroman Posted November 17, 2018 Share Posted November 17, 2018 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 More sharing options...
Cagealicous Posted November 17, 2018 Author Share Posted November 17, 2018 Well, one is a shovel tool the character can use, the other is a boomerang that he can attack with. Both of them are craft-able and are in the starting inventory.. Also, yes they are custom prefabs. Link to comment Share on other sites More sharing options...
Ultroman Posted November 17, 2018 Share Posted November 17, 2018 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 More sharing options...
Cagealicous Posted November 17, 2018 Author Share Posted November 17, 2018 Thanks, but I think I can ask my friend for any further help. He told me he can figure it out, but thanks anyway. Link to comment Share on other sites More sharing options...
Ultroman Posted November 17, 2018 Share Posted November 17, 2018 Oh, ok. It's pretty straight-forward, though. Let me know if you run into trouble. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now