Jump to content

Recommended Posts

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

your code is quite correct, but I spot two possible problems:

  1. 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
  2. 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
  • Like 1

@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

image.thumb.png.767b5b8df35e74ebe62133b947ad09f2.png

You said I need to localize the table though, right?  What do you mean?

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 by Bad Willow
  • Like 1

@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 by FurryEskimo

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

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.

  • Like 1

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

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
×
  • Create New...