FurryEskimo Posted November 11, 2021 Share Posted November 11, 2021 I've been trying to get this working, but so far I've just had a lot of 'almosts' and decided to ask. Is there a simple way to check if an item is in the equipment body slot? I know I can check for armor, and I think I may be able to check for properties about items in the body slot, but it's still giving me some trouble.. eg. I thought this would work, but I guess not.. local body_data = self.inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY) if body_data.eslot == nil then if body_data.eslot == EQUIPSLOTS.BODY then if body_data.item.prefab ~= nil then body_data = true else body_data = false end end body_data = false end Basically the goal is to make a sprite appear on the player when they're not wearing clothes on their torso, but it screws up what the armor looks like, so I'm trying to fix it.. Link to comment https://forums.kleientertainment.com/forums/topic/135245-detecting-if-an-item-is-on-the-players-body/ Share on other sites More sharing options...
skittles sour Posted November 11, 2021 Share Posted November 11, 2021 your code is quite correct, but I spot two possible problems: that the EQUIPSLOTS table is a global table, which you would need to access either by localizing it first or by calling it from the global table that the body_data should return the item itself, so after the first line, you can simply do if body_data then GiveSprite(self.inst) else RemoveSprite(self.inst) end 1 Link to comment https://forums.kleientertainment.com/forums/topic/135245-detecting-if-an-item-is-on-the-players-body/#findComment-1512347 Share on other sites More sharing options...
FurryEskimo Posted November 11, 2021 Author Share Posted November 11, 2021 @Bad Willow Thanks, I’ll give that a try. I also had a hunch it needed to be Global, but I’ve just tried so many options already.. Link to comment https://forums.kleientertainment.com/forums/topic/135245-detecting-if-an-item-is-on-the-players-body/#findComment-1512363 Share on other sites More sharing options...
skittles sour Posted November 11, 2021 Share Posted November 11, 2021 what exactly is the crash at the moment? Link to comment https://forums.kleientertainment.com/forums/topic/135245-detecting-if-an-item-is-on-the-players-body/#findComment-1512370 Share on other sites More sharing options...
FurryEskimo Posted November 12, 2021 Author Share Posted November 12, 2021 @Bad Willow At this time, this is the error I'm getting. server_log_2021-11-11-19-22-03.txt [string "../mods/workshop-2238207705/skin_edits.lua"]:241: attempt to index local 'body_data' (a nil value) LUA ERROR stack traceback: ../mods/workshop-2238207705/skin_edits.lua:241 in (method) SetSkinMode (Lua) <140-284> self = SetSkinMode = function - ../mods/workshop-2238207705/skin_edits.lua:140 You said I need to localize the table though, right? What do you mean? Link to comment https://forums.kleientertainment.com/forums/topic/135245-detecting-if-an-item-is-on-the-players-body/#findComment-1512377 Share on other sites More sharing options...
skittles sour Posted November 12, 2021 Share Posted November 12, 2021 (edited) ohhh that was just a very inaccurate way to say you can do " local EQUIPSLOTS = GLOBAL.EQUIPSLOTS ". the error is that you are supposing, at line # 241, that type(body_data) == "table", yet, at the time the function is ran, body_data is nil, probably because the character isn't wearing anything, and despite this your code is forcing lua to find a certain value as if it is a table. you should change line # 241 to something like " if body_data and body_data.eslot == nil then -- etc" Edited November 12, 2021 by Bad Willow 1 Link to comment https://forums.kleientertainment.com/forums/topic/135245-detecting-if-an-item-is-on-the-players-body/#findComment-1512378 Share on other sites More sharing options...
FurryEskimo Posted November 12, 2021 Author Share Posted November 12, 2021 (edited) @Bad Willow Well that did succeed that preventing the error! Thanks! I'm back to square one though.. The armor disappears when the game is loaded, or the character jumps, and the torso sprite is being displayed even when clothes are worn, which shouldn't be the case.. I feel like something is screwy here, something about how the game works maybe? print("Clothing Test: 0") local body_data = self.inst.components.inventory:GetEquippedItem(GLOBAL.EQUIPSLOTS.BODY) if body_data and body_data.eslot == nil then --Error here. if body_data.eslot == EQUIPSLOTS.BODY then if body_data.item.prefab ~= nil then body_data = true else body_data = false end end body_data = false end if body_data then print("Clothing Test: Armored") --Do nothing, armor must be seen. elseif overridestorso and not body_data then print("Clothing Test: Clothing but no armor") --Make the _____ invisible. self.inst.AnimState:OverrideSymbol("swap_body", "____[name]____", "none") elseif not overridestorso and not body_data then print("Clothing Test: No clothes and no armor") --Show _____, if there's nothing on the torso. self.inst.AnimState:ClearOverrideSymbol("swap_body") end skin_edits.lua If I comment out all of this code, the only error is that the sprite added to the torso is displayed when they're wearing clothing, which shouldn't be the case. Seems simple, but fixing this has been such a bother. (I fixed that originally, but later realized it messed with the body slot visuals for equipment, and trying to fix that caused all this trouble.) Edited November 12, 2021 by FurryEskimo Link to comment https://forums.kleientertainment.com/forums/topic/135245-detecting-if-an-item-is-on-the-players-body/#findComment-1512380 Share on other sites More sharing options...
FurryEskimo Posted November 14, 2021 Author Share Posted November 14, 2021 Yeah, I'm not really having any luck with this. I have a sneaking suspicion that the game is updating my character's visuals when I change clothes, hop, enter the game, and when I put armor on, but not when I take armor off. I could be wrong, but the bugs I'm getting are just too weird.. Link to comment https://forums.kleientertainment.com/forums/topic/135245-detecting-if-an-item-is-on-the-players-body/#findComment-1512985 Share on other sites More sharing options...
IronHunter Posted November 14, 2021 Share Posted November 14, 2021 I am trying to understand what you want. It seems you want to override the swap_body symbol when not wearing a item that overrides it correct? If so why not just add the symbol to your spriter file and that way it'll always be visible by default until its overridden by equipment. Equipment generally clears the overridden symbol when unequipped so this saves you needing to add code for equip and unequip events and checking which slot its in. 1 Link to comment https://forums.kleientertainment.com/forums/topic/135245-detecting-if-an-item-is-on-the-players-body/#findComment-1513123 Share on other sites More sharing options...
FurryEskimo Posted November 15, 2021 Author Share Posted November 15, 2021 @IronHunter Basically there's an item on the character's swap_body sprite, and it behaves as expected when wearing armor, but I need it to disappear when wearing clothes that affect the torso. I already have this code and it seemed to work, but I realized it caused some errors with armor, so I tried to fix that, and then the whole thing just kind of blew up in my face. Link to comment https://forums.kleientertainment.com/forums/topic/135245-detecting-if-an-item-is-on-the-players-body/#findComment-1513186 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