ViridianCrown Posted September 12, 2023 Share Posted September 12, 2023 I know this'll probably be really simple but I'm trying to check if a player's character is wearing armor/clothing with the "backpack" tag on it, but I can't find the exact phrase in order to check if someone has a backpack equipped. Does it have something to do with EQUIPSLOT_BODY, or adding a GLOBAL. tag in modmain? Link to comment https://forums.kleientertainment.com/forums/topic/150928-how-to-check-if-someones-wearing-a-backpack/ Share on other sites More sharing options...
Haruhi Kawaii Posted September 13, 2023 Share Posted September 13, 2023 5 hours ago, ViridianCrown said: I know this'll probably be really simple but I'm trying to check if a player's character is wearing armor/clothing with the "backpack" tag on it, but I can't find the exact phrase in order to check if someone has a backpack equipped. Does it have something to do with EQUIPSLOT_BODY, or adding a GLOBAL. tag in modmain? local checkbackpack = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BACK) or inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY) if checkbackpack and checkbackpack:HasTag("backpack") then print("backpack is here") end Should also use EQUIPSLOTS.BACK because they may use some mods like Extra Equip Slots to check EQUIPSLOTS.BODY which may give incorrect results. Link to comment https://forums.kleientertainment.com/forums/topic/150928-how-to-check-if-someones-wearing-a-backpack/#findComment-1664839 Share on other sites More sharing options...
Rickzzs Posted September 13, 2023 Share Posted September 13, 2023 inst.components.inventory:GetOverflowContainer() Link to comment https://forums.kleientertainment.com/forums/topic/150928-how-to-check-if-someones-wearing-a-backpack/#findComment-1664844 Share on other sites More sharing options...
ViridianCrown Posted September 13, 2023 Author Share Posted September 13, 2023 I'm terribly sorry, but I can't seem to get either solution to work. It would probably be helpful if I explained what I was trying to actually do and paste some code. The following code I am attempting to edit is in the modmain.lua file. Spoiler AddComponentPostInit("playeractionpicker", function(self) if self.inst:HasTag("PLACEHOLDER_NAME") then local LEAPACTION = GLOBAL.ACTIONS.LEAP local _GetRightClickActions = self.GetRightClickActions self.GetRightClickActions = function(self, position, target) local actions = _GetRightClickActions(self, position, target) if #actions == 0 then local ishungry = self.inst.replica.hunger:GetCurrent() < 10 local ispassable = self.map:IsPassableAtPoint(position:Get()) if ispassable and not ishungry then actions = self:SortActionList({LEAPACTION}, position) end end return actions end end end) Basically what I wish to do is allow a character to leap with the help of a worn item (using a backpack as a placeholder). However, in its current state, the character is allowed to leap regardless of if they have anything equipped. I attempted to use Harumi's code to make it so giving the character a backpack would add the character tag "hasbackpack", and make it so the code would both check for the self.inst:HasTag("PLACEHOLDER_NAME") and a hypothetical inst:HasTag("hasbackpack"), but it would either force an error not allowing the server to start, or would connect but push me back into the character select screen with the custom character missing. Older versions of the code checked for a walking cane in the character's hand using this code: Spoiler AddComponentAction("POINT", "leapstaff", function(inst, doer, pos, actions, right) if right and doer:HasTag("PLACEHOLDER_NAME") and doer.components.hunger.current >= 10 and GLOBAL.TheWorld.Map:IsPassableAtPoint(pos:Get()) then table.insert(actions, ACTIONS.LEAP) elseif doer.components.hunger.current <= 9.99 then return end end) --This code replaces the current code's AddComponentPostInit example I used above. AddPrefabPostInit("cane", function(inst) inst:AddComponent("reticule") inst.components.reticule.targetfn = ReticuleTargetFn inst.components.reticule.ease = true if GLOBAL.TheWorld.ismastersim then inst:AddComponent("leapstaff") end end) However, I could not find a way to make the code check for worn items, only items in hand such as a pickaxe or hammer. I'm really sorry if I'm missing anything, but I'm relatively new to coding in LUA and have mostly lurked on the forum to find answers before posting. Link to comment https://forums.kleientertainment.com/forums/topic/150928-how-to-check-if-someones-wearing-a-backpack/#findComment-1664886 Share on other sites More sharing options...
Sneaky Axolxtl Posted September 15, 2023 Share Posted September 15, 2023 (edited) Im not smart but you could probably listen for the equip/unequip event with Quote inst:ListenForEvent("equip", function(inst, data) if data.eslot == EQUIPSLOTS.BODY and data.item.components.container then inst.backpackequipped = true end end) inst:ListenForEvent("unequip", function(inst, data) if data.eslot == EQUIPSLOTS.BODY and data.item.components.container then inst.backpackequipped = false end end) --replace "data.item.components.container" with "data.item.prefab == "backpack" if you dont want to target all containers (like the candy sack, pig backpack, etc) and have a variable tied to the character like "inst.backpackequipped" and then have your function check if inst.backpackequipped == true im no smartie tho, this may cause issues? dunno Edited September 15, 2023 by Sneaky Axolxtl minor spelling mistake i win Link to comment https://forums.kleientertainment.com/forums/topic/150928-how-to-check-if-someones-wearing-a-backpack/#findComment-1665188 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