ID:1847526
 
(See the best response by Lummox JR.)
Code:
    proc/InvLayer()
usr.overlays += shoulderpiece
usr.overlays += mainhandpiece
usr.overlays += offhandpiece
usr.overlays += backpiece
usr.overlays += legspiece
usr.overlays += feetpiece
usr.overlays += chestpiece
usr.overlays += glovepiece
usr.overlays += facepiece
usr.overlays += headpiece
Inventory()


Problem description:

What it should do: When the proc is called (whenever an items equipped) it -should- layer everything in that order from top to bottom, then run the Inventory proc to refresh the inventory list.

What it does: It does the Inventory proc no problem. HOWEVER it seems to want to layer the cloths in order of when they were equipped, rather than the above order.

I can't seem to recreate your problem. However, I may suggest that you define the layer var for each type of armor so that they stack correctly regardless of the order added.

E.g.
obj
Armor
Legs
layer = MOB_LAYER + 1
Chest
layer = MOB_LAYER + 2
mob
verb
testEquipping()
overlays += /obj/Armor/Chest
overlays += /obj/Armor/Legs // It doesn't matter that these were added second; they will still be beneath the chest armor.
Is there any way of doing that without going through each individual item and putting in MOB_LAYER? In the code I posted, the 'shoulderpiece, backpiece' etc are all variables. I can post the whole code

mob
var
bagopened = 1
verb/bagopen()
if(bagopened==1)
bagopened = 0
winshow(src,"inventory",1) //Show the inventory window!
else if(bagopened==0)
bagopened = 1
winshow(src, "inventory",0)
else
src<<"Unknown bag opening error bagopen !=1/0"


mob
var
chest //Chest item variable
legs
shoulder
face
feet
head
back
mainhand
offhand
glove



list/hiddenlist = list()

Entered(obj/Armor/A) // If an item or anything else sucessfully enters the mob's contents
..() // Checks to see if there's anything else to be called (in case).
if(istype(A))
var/obj/Armor/X=locate(A.type) in src.contents-A //Checks if there's an item with the same type already.
if(X) // If there's an item that exists with the same path
A.amount+=X.amount // Adds the amount of the item found
del X // Deletes that item found.
Inventory() // Calls the Inventory() prcoedure.

Exited()
..()
Inventory()

proc/Inventory()
var/i=1 // Current position (#) of contents
winset(src,"inventory.invent",{"cells="2x[contents.len+1]""}) // Sets column = 2, row = contents.len+1
src<<output("<b>Item</b>","inventory.invent:1,1") // Displays "Items" in the current cell, which is column 1, row 1
src<<output("<b>Amount</b>","inventory.invent:2,1") // Displays "Amount" in column 2, row 2
for(var/obj/Armor/I in contents) // Searches through the contents list
src<<output(I,"inventory.invent:1,[++i]") // Outputs to the cell: column=1, row = ++i (++i means (i+1) returned immediately. i++ means (i+1) but first returns the value of i).; this Sets the item (I) in to the current cell
src<<output(I.amount,"inventory.invent:2,[i]") // Displays the amount the item (I) has in to the cell: column=2, row = i (i is already now i+1 from the previous output())

atom/proc/Bumped(atom/A) return 1 // And here is where we define the default for Bumped().. Note it is under /atom not /atom/movable. /atom children are /area, /turf and /movable [hence atom/movable]. The bumped() object does not necessarily have to be just an /obj or /mob right?

obj/Armor // A datum named Item for items (obviously).

proc
chestlayer()
layer = MOB_LAYER + 1
backlayer()
layer = MOB_LAYER + 2


var/equipped=0 //To know if its equipped or not

parent_type = /obj // /Item's parent (which can be checked via atom.parent_type) is now set to /obj, meaning that /Item contains all traits of /obj which contains it from /atom/movable which contains it from /atom (modified along the way of course).
density = 1 // Makes the item dense (unable to walk through)
var/amount = 1 // Stacking system!
Bumped(mob/M) // If something Bump()s into it, this is called.
if(!ismob(M)) return 0 // If M (the argument sent) is not a mob, the rest is stopped from happening
if(!M.client) return 0 // If M is not a client (human player), the rest of the procedure does not happen.
Pickup_proc(M) // Calls the procedure Pickup_proc.

verb/Pickup()
set src in oview(1) // Makes the verb available if the user if within 1 tile from the source.
Pickup_proc(usr) // You know what this does.

// verb/Drop() // All /Item have this verb as well.

// set src in usr // Verb is available if the item is in the contents.
/// set category = "Items" // The verb's category is set as Items
// var/amt=max(0,min(99,input("How many [name] do you wish to drop? Maximum amount: [min(99,amount)]","Armor drop",1) as num|null))
// if(!(src in usr)||!amt) return 0 // Safety checking if the item is actually in the usr's contents.
// var/turf/XX = get_step(usr,turn(usr.dir,180))
// if(!XX)XX=usr.loc
// if(amt>=amount).=Move(XX) // Tries to moves the item to one step behind the user.
// else
// var/obj/Armor/X = type
// X = new X(XX)
// X.amount = amt
// amount-=amt
// .=1
// usr.Inventory()
// usr << "[(.)?"\green":"\red"] You[(.)?"":" did not"] drop [amt] [src.name]\s." // Checks if the item was dropped sucessfully. (x)?y:z is a mini-if() statement: if(x){ y } else { z }

proc/Pickup_proc(mob/M) // Reason why I defined this instead of just having the verb is so I can pick up /Item's by bumping into them. Sure I could call the verb through Bumped() but than the usr would be someone else.
if(!(M in oview(1,src))) return // Checks if M is within 1 tile. If it isn't, the procedure stops.
.=Move(M) // Tries to moves the item to one step behind the user.
M << "[(.)?"\green":"\red"] You[(.)?"":" did not"] pick up [src.name]." // Checks if the item was picked up sucessfully. (x)?y:z is a mini-if() statement: if(x){ y } else { z }
//Rearranging Inventory?

MouseDrag(src_object,over_object,src_location,over_location,src_control,over_control,params)// When we drag it...
if(!(src in usr.contents)) return // If its not in our inventory...just cancel ...


// var/icon/I = new(src.icon,src.icon_state)//this is so the cursor icon transforms into the item itself...cool little effect.
// mouse_drag_pointer = I // now lets set the mouse cursor to that.

MouseDrop(over_object=src,src_location,over_location,src_control,over_control,params) //When we drop it
if(src in usr.contents)
if(src_control == "inventory.invent")
if(over_control == "inventory.chestslot") //If its inside the inventory window.
if(equiptype == "chest") //If you're equipping a 'chest' type
if(!usr.chest) //And the chest slot is empty
usr << "Equipped [src.name]"
usr.chest=src
src.loc = usr.hiddenlist
equipped = 1
usr << output(usr.chest, "inventory.chestslot")
chestpiece = icon
InvLayer()
else
usr << output(null,"inventory.about")
usr << output("Need to unequip first!","inventory.about")
else
usr << output(null,"inventory.about")
usr << output("That doesn't go there/isn't an equippable item!","inventory.about")

if(over_control == "inventory.head") //If its inside the inventory window.
if(equiptype == "head") //If you're equipping a 'chest' type
if(!usr.head) //And the chest slot is empty
usr << "Equipped [src.name]"
usr.head=src
src.loc = usr.hiddenlist
equipped = 1
usr << output(usr.head, "inventory.head")
headpiece = icon
InvLayer()
else
usr << output(null,"inventory.about")
usr << output("Need to unequip first!","inventory.about")
else
usr << output(null,"inventory.about")
usr << output("That doesn't go there/isn't an equippable item!","inventory.about")

if(over_control == "inventory.face") //If its inside the inventory window.
if(equiptype == "face") //If you're equipping a 'chest' type
if(!usr.face) //And the chest slot is empty
usr << "Equipped [src.name]"
usr.face=src
src.loc = usr.hiddenlist
equipped = 1
usr << output(usr.face, "inventory.face")
facepiece = icon
InvLayer()
else
usr << output(null,"inventory.about")
usr << output("Need to unequip first!","inventory.about")
else
usr << output(null,"inventory.about")
usr << output("That doesn't go there/isn't an equippable item!","inventory.about")

if(over_control == "inventory.shoulder") //If its inside the inventory window.
if(equiptype == "shoulder") //If you're equipping a 'chest' type
if(!usr.shoulder) //And the chest slot is empty
usr << "Equipped [src.name]"
usr.shoulder=src
src.loc = usr.hiddenlist
equipped = 1
usr << output(usr.shoulder, "inventory.shoulder")
shoulderpiece = icon
InvLayer()
else
usr << output(null,"inventory.about")
usr << output("Need to unequip first!","inventory.about")
else
usr << output(null,"inventory.about")
usr << output("That doesn't go there/isn't an equippable item!","inventory.about")

if(over_control == "inventory.back") //If its inside the inventory window.
if(equiptype == "back") //If you're equipping a 'chest' type
if(!usr.back) //And the chest slot is empty
usr << "Equipped [src.name]"
usr.back=src
src.loc = usr.hiddenlist
equipped = 1
usr << output(usr.back, "inventory.back")
backpiece = icon
InvLayer()
else
usr << output(null,"inventory.about")
usr << output("Need to unequip first!","inventory.about")
else
usr << output(null,"inventory.about")
usr << output("That doesn't go there/isn't an equippable item!","inventory.about")

if(over_control == "inventory.legs") //If its inside the inventory window.
if(equiptype == "legs") //If you're equipping a 'chest' type
if(!usr.legs) //And the chest slot is empty
usr << "Equipped [src.name]"
usr.legs=src
src.loc = usr.hiddenlist
equipped = 1
usr << output(usr.legs, "inventory.legs")
legspiece = icon
InvLayer()
else
usr << output(null,"inventory.about")
usr << output("Need to unequip first!","inventory.about")
else
usr << output(null,"inventory.about")
usr << output("That doesn't go there/isn't an equippable item!","inventory.about")

if(over_control == "inventory.feet") //If its inside the inventory window.
if(equiptype == "feet") //If you're equipping a 'chest' type
if(!usr.feet) //And the chest slot is empty
usr << "Equipped [src.name]"
usr.feet=src
src.loc = usr.hiddenlist
equipped = 1
usr << output(usr.feet, "inventory.feet")
feetpiece = icon
InvLayer()
else
usr << output(null,"inventory.about")
usr << output("Need to unequip first!","inventory.about")
else
usr << output(null,"inventory.about")
usr << output("That doesn't go there/isn't an equippable item!","inventory.about")

if(over_control == "inventory.glove") //If its inside the inventory window.
if(equiptype == "glove") //If you're equipping a 'chest' type
if(!usr.glove) //And the chest slot is empty
usr << "Equipped [src.name]"
usr.glove=src
src.loc = usr.hiddenlist
equipped = 1
usr << output(usr.glove, "inventory.glove")
glovepiece = icon
InvLayer()
else
usr << output(null,"inventory.about")
usr << output("Need to unequip first!","inventory.about")
else
usr << output(null,"inventory.about")
usr << output("That doesn't go there/isn't an equippable item!","inventory.about")



else
return

else
if(src_control == "inventory.chestslot")
if(usr.chest==src)
if(equipped)
usr.overlays -= chestpiece
usr.chest=null
equipped=0
src.loc=usr
usr << output(usr.chest, "inventory.chestslot")
usr.Inventory()
var
chestpiece
legspiece
headpiece
facepiece
shoulderpiece
backpiece
feetpiece
glovepiece
mainhandpiece
offhandpiece
equiptype

proc/InvLayer()
usr.overlays += shoulderpiece
usr.overlays += mainhandpiece
usr.overlays += offhandpiece
usr.overlays += backpiece
usr.overlays += legspiece
usr.overlays += feetpiece
usr.overlays += chestpiece
usr.overlays += glovepiece
usr.overlays += facepiece
usr.overlays += headpiece
usr.Inventory()

//Armors list




KasablancRobeMale
icon = 'Kasablanc Robe Male.dmi'
icon_state = ""
name = "Kasablanc Robe (M)"
equiptype = "chest"
KasablancRobeFemale
icon = 'Kasablanc Robe female.dmi'
icon_state = ""
name = "Kasablanc Robe (F)"
equiptype = "chest"
KasablancPants
icon = 'Kasablanc pants.dmi'
icon_state = ""
name = "Kasablanc Pants"
equiptype = "legs"
KasablancCloak
icon = 'Kasablanc Cloak.dmi'
icon_state = ""
name = "Kasablanc Cloak"
equiptype = "back"
KreptkinPantsMale
icon = 'Kreptkin Pants Male.dmi'
icon_state = ""
name = "Kreptkin Pants"
equiptype = "legs"
KreptkinShirtFemale
icon = 'Kreptkin shirt female.dmi'
icon_state = ""
name = "Kreptkin Blouse (F)"
equiptype = "chest"
KreptkinSkirt
icon = 'Kreptkin skirt.dmi'
icon_state = ""
name = "Kreptkin Skirt"
equiptype = "legs"
KreptkinSuitMale
icon = 'Kreptkin Suit Male.dmi'
icon_state = ""
name = "Kreptkin Suit (M)"
equiptype = "chest"
NutoriRobeFemale
icon = 'Nutori Robe female.dmi'
icon_state = ""
name = "Nutori Robes (F)"
equiptype = "chest"
NutoriRobeMale
icon = 'Nutori Robe Male.dmi'
icon_state = ""
name = "Nutori Robes (M)"
equiptype = "chest"
PuraelicChest
icon = 'Puraelic chest m.dmi'
icon_state = ""
name = "Puraelic Chestpiece"
equiptype = "chest"
PuraelicGauntlets
icon = 'Puraelic gauntlets.dmi'
icon_state = ""
name = "Puraelic Gauntlets"
equiptype = "glove"
PuraelicPantsMale
icon = 'Puraelic pants male.dmi'
icon_state = ""
name = "Puraelic Greaves (M)"
equiptype = "legs"
PuraelicPantsFemale
icon = 'Puraelic pants female.dmi'
icon_state = ""
name = "Puraelic Greaves (F)"
equiptype = "legs"
ShaedralGoggles
icon = 'Shaedral Goggles.dmi'
icon_state = ""
name = "Shaedral Goggles"
equiptype = "head"
ShaedralMask
icon = 'Shaedral Mask.dmi'
icon_state = ""
name = "Shaedral Facemask"
equiptype = "face"
ShaedralPants
icon = 'Shaedral Pants.dmi'
icon_state = ""
name = "Shaedral Pants"
equiptype = "legs"
ShaedralShirtFemale
icon = 'Shaedral shirt female.dmi'
icon_state = ""
name = "Shaedral Shirt (F)"
equiptype = "chest"
ShaedralShirtMale
icon = 'Shaedral shirt male.dmi'
icon_state = ""
name = "Shaedral Shirt (M)"
equiptype = "chest"
I'm going to preface this by saying that it probably isn't the best design decision to have each armor type be a different subtype if they are functionally the same. Some would disagree, so if you'd like to keep it, go ahead. Ter13 wrote an article about this here.

That being said, you currently define a distinct variable called equiptype, so you could use that.
obj
Armor
New()
switch(equiptype)
if("chest")
layer = MOB_LAYER + 1
if("back")
layer = MOB_LAYER + 2
// etc.
..()
usr has no business being in the InvLayer() proc, because it's a proc, not a verb. The proc already belongs to the mob you want to affect, so that should be src instead.

In the mouse procs, those are actually pseudo-verbs, which expect to only ever be called by the actual verbs (client.MouseDrop(), etc.), so usr is okay there.

One thing I'm noticing is that you never actually clear your overlays list in InvLayer() before adding more stuff to it. I think that's the entire crux of the problem. (But do get rid of the usr abuse anyway.)
Should I also change usr.Inventory() to src.Inventory()?

Also, wouldn't there be a problem that if I cleared out all those values I wouldn't be able to layer them when I equipped another item?
In response to Darklady5
Darklady5 wrote:
Should I also change usr.Inventory() to src.Inventory()?

Yes, since in the InvLayer() proc usr is meaningless, and src is the mob you actually want to be using there.

To be clear, src isn't always what you want; it depends on the proc. This proc happens to already belong to the mob you're working with, so src is right. But in Entered(), for instance, whatever atom just entered (it may be a mob or an obj) is the first argument in that proc.

Also, wouldn't there be a problem that if I cleared out all those values I wouldn't be able to layer them when I equipped another item?

I'm just saying clear the overlays, not the vars. The InvLayer() proc adds all of the various pieces to the overlays list in the order you want; the problem it's having is that you're adding to an existing overlays list. So if you clear the overlays before re-adding them all, you'll get the correct result.

Another way to do this might be overlays = list(shoulderpiece, mainhandpiece, ...) which is probably the most elegant approach.
So to clear them would I just set overlays = null followed by the list examply you gave me?
Also when I changed usr to src with usr.Inventory it came up with undefined proc error
Okay well doing the list as src.overlays = list(shoulderpiece, etc) came with two problems. For one, it didn't work until I changed it back to usr. Second, now the newly added item is the only one that shows up, as the rest disappear when the new ones added.
Also if I try changing it to += instead of just = I get thrown back to our original problem
If you set overlays to a list, you don't need to set it to null first. If you're adding a whole bunch of stuff to overlays one at a time like your existing code, you'd set it to null first.

The only Inventory() call that needs to be src instead of usr is the one in InvLayer(). That's the only place there was usr abuse. In MouseDrop() you do want it to be usr.Inventory(). As I said, MouseDrop() is a pseudo-verb and usr is okay there. The usr abuse I saw was in InvLayer().
Oh shoot, I see part of the problem. You've defined InvLayer() and all the piece vars under obj/Armor. Those should belong to the mob, because each piece of armor is just one individual piece of equipment.

There's no way to justify InvLayer() being anything but a mob proc. Likewise, the vars tracking each piece of armor in use need to belong to the mob.
If I try moving stuff under mob instead, the code -explodes- with freakout errors.
The original code I used had it in this form, which is why I stuck to it.
Don't carry on another person's mistakes if you don't have to. Redoing the mob's overlays is obviously something that the mob itself should be responsible for; therefore the InvLayer() proc must belong to /mob. Likewise, the vars that say which pieces of armor are equipped also have no business being defined under obj/Armor--they too should be mob vars. What good would it do a shoulder piece to have a var pointing to a leg piece? So move those over, and then deal with the compiler errors by correcting them as they appear.

You're approaching this very wrong right now: trying to get something that doesn't produce compiler errors, by tweaking the design as little as you can. Problem is, the design is what's broken. Fix the design and deal with those compiler errors, and then your code will be more robust for it. Don't fear the compiler error; fear the runtime error that comes up later if things aren't done right.

And I haven't even gotten into some of the other design issues. You have a lot of redundant code that could be replaced with much, much simpler code. Equipment doesn't need (and should never have) an equipped var, because the mob that's wearing it should keep track of that. If you dealt with those issues as well, this system would be very robust and even easy to extend.
A few questions going through this. By "vars that say which pieces of armor are equipped" do you mean the list of

var
chestpiece
legspiece
headpiece
facepiece
shoulderpiece
backpiece
feetpiece
glovepiece
mainhandpiece
offhandpiece
equiptype

or do you mean the ENTIRE mousedrag/drop code?
So I managed to fix compiler errors and move everything over, but now the mouse drag completely broke. It doesn't do anything. If I ONLY move Mousedrag its fine, but if I move everything it just doesn't do anything. The new code is now

mob
var
bagopened = 1
verb/bagopen()
if(bagopened==1)
bagopened = 0
winshow(src,"inventory",1) //Show the inventory window!
else if(bagopened==0)
bagopened = 1
winshow(src, "inventory",0)
else
src<<"Unknown bag opening error bagopen !=1/0"


mob
var
chest //Chest item variable
legs
shoulder
face
feet
head
back
mainhand
offhand
glove

list/hiddenlist = list()

var/equipped=0 //To know if its equipped or not




Entered(obj/Armor/A) // If an item or anything else sucessfully enters the mob's contents
..() // Checks to see if there's anything else to be called (in case).
if(istype(A))
var/obj/Armor/X=locate(A.type) in src.contents-A //Checks if there's an item with the same type already.
if(X) // If there's an item that exists with the same path
A.amount+=X.amount // Adds the amount of the item found
del X // Deletes that item found.
Inventory() // Calls the Inventory() prcoedure.

Exited()
..()
Inventory()

proc/Inventory()
var/i=1 // Current position (#) of contents
winset(src,"inventory.invent",{"cells="2x[contents.len+1]""}) // Sets column = 2, row = contents.len+1
src<<output("<b>Item</b>","inventory.invent:1,1") // Displays "Items" in the current cell, which is column 1, row 1
src<<output("<b>Amount</b>","inventory.invent:2,1") // Displays "Amount" in column 2, row 2
for(var/obj/Armor/I in contents) // Searches through the contents list
src<<output(I,"inventory.invent:1,[++i]") // Outputs to the cell: column=1, row = ++i (++i means (i+1) returned immediately. i++ means (i+1) but first returns the value of i).; this Sets the item (I) in to the current cell
src<<output(I.amount,"inventory.invent:2,[i]") // Displays the amount the item (I) has in to the cell: column=2, row = i (i is already now i+1 from the previous output())

MouseDrag(src_object,over_object,src_location,over_location,src_control,over_control,params)// When we drag it...
if(!(src in usr.contents)) return // If its not in our inventory...just cancel ...


MouseDrop(over_object=src,src_location,over_location,src_control,over_control,params) //When we drop it
if(src in usr.contents)
if(src_control == "inventory.invent")
if(over_control == "inventory.chestslot") //If its inside the inventory window.
if(equiptype == "chest") //If you're equipping a 'chest' type
if(!usr.chest) //And the chest slot is empty
usr << "Equipped [src.name]"
usr.chest=src
src.loc = usr.hiddenlist
equipped = 1
usr << output(usr.chest, "inventory.chestslot")
chestpiece = icon
InvLayer()
else
usr << output(null,"inventory.about")
usr << output("Need to unequip first!","inventory.about")
else
usr << output(null,"inventory.about")
usr << output("That doesn't go there/isn't an equippable item!","inventory.about")

if(over_control == "inventory.head") //If its inside the inventory window.
if(equiptype == "head") //If you're equipping a 'chest' type
if(!usr.head) //And the chest slot is empty
usr << "Equipped [src.name]"
usr.head=src
src.loc = usr.hiddenlist
equipped = 1
usr << output(usr.head, "inventory.head")
headpiece = icon
InvLayer()
else
usr << output(null,"inventory.about")
usr << output("Need to unequip first!","inventory.about")
else
usr << output(null,"inventory.about")
usr << output("That doesn't go there/isn't an equippable item!","inventory.about")

if(over_control == "inventory.face") //If its inside the inventory window.
if(equiptype == "face") //If you're equipping a 'chest' type
if(!usr.face) //And the chest slot is empty
usr << "Equipped [src.name]"
usr.face=src
src.loc = usr.hiddenlist
equipped = 1
usr << output(usr.face, "inventory.face")
facepiece = icon
InvLayer()
else
usr << output(null,"inventory.about")
usr << output("Need to unequip first!","inventory.about")
else
usr << output(null,"inventory.about")
usr << output("That doesn't go there/isn't an equippable item!","inventory.about")

if(over_control == "inventory.shoulder") //If its inside the inventory window.
if(equiptype == "shoulder") //If you're equipping a 'chest' type
if(!usr.shoulder) //And the chest slot is empty
usr << "Equipped [src.name]"
usr.shoulder=src
src.loc = usr.hiddenlist
equipped = 1
usr << output(usr.shoulder, "inventory.shoulder")
shoulderpiece = icon
InvLayer()
else
usr << output(null,"inventory.about")
usr << output("Need to unequip first!","inventory.about")
else
usr << output(null,"inventory.about")
usr << output("That doesn't go there/isn't an equippable item!","inventory.about")

if(over_control == "inventory.back") //If its inside the inventory window.
if(equiptype == "back") //If you're equipping a 'chest' type
if(!usr.back) //And the chest slot is empty
usr << "Equipped [src.name]"
usr.back=src
src.loc = usr.hiddenlist
equipped = 1
usr << output(usr.back, "inventory.back")
backpiece = icon
InvLayer()
else
usr << output(null,"inventory.about")
usr << output("Need to unequip first!","inventory.about")
else
usr << output(null,"inventory.about")
usr << output("That doesn't go there/isn't an equippable item!","inventory.about")

if(over_control == "inventory.legs") //If its inside the inventory window.
if(equiptype == "legs") //If you're equipping a 'chest' type
if(!usr.legs) //And the chest slot is empty
usr << "Equipped [src.name]"
usr.legs=src
src.loc = usr.hiddenlist
equipped = 1
usr << output(usr.legs, "inventory.legs")
legspiece = icon
InvLayer()
else
usr << output(null,"inventory.about")
usr << output("Need to unequip first!","inventory.about")
else
usr << output(null,"inventory.about")
usr << output("That doesn't go there/isn't an equippable item!","inventory.about")

if(over_control == "inventory.feet") //If its inside the inventory window.
if(equiptype == "feet") //If you're equipping a 'chest' type
if(!usr.feet) //And the chest slot is empty
usr << "Equipped [src.name]"
usr.feet=src
src.loc = usr.hiddenlist
equipped = 1
usr << output(usr.feet, "inventory.feet")
feetpiece = icon
InvLayer()
else
usr << output(null,"inventory.about")
usr << output("Need to unequip first!","inventory.about")
else
usr << output(null,"inventory.about")
usr << output("That doesn't go there/isn't an equippable item!","inventory.about")

if(over_control == "inventory.glove") //If its inside the inventory window.
if(equiptype == "glove") //If you're equipping a 'chest' type
if(!usr.glove) //And the chest slot is empty
usr << "Equipped [src.name]"
usr.glove=src
src.loc = usr.hiddenlist
equipped = 1
usr << output(usr.glove, "inventory.glove")
glovepiece = icon
InvLayer()
else
usr << output(null,"inventory.about")
usr << output("Need to unequip first!","inventory.about")
else
usr << output(null,"inventory.about")
usr << output("That doesn't go there/isn't an equippable item!","inventory.about")



else
return

else
if(src_control == "inventory.chestslot")
if(usr.chest==src)
if(equipped)
usr.overlays -= chestpiece
usr.chest=null
equipped=0
src.loc=usr
usr << output(usr.chest, "inventory.chestslot")
usr.Inventory()
var
chestpiece
legspiece
headpiece
facepiece
shoulderpiece
backpiece
feetpiece
glovepiece
mainhandpiece
offhandpiece
equiptype

proc/InvLayer()

usr.overlays += list(shoulderpiece, mainhandpiece, offhandpiece, backpiece, legspiece, feetpiece, chestpiece, glovepiece, facepiece, headpiece)
usr.Inventory()

atom/proc/Bumped(atom/A) return 1 // And here is where we define the default for Bumped().. Note it is under /atom not /atom/movable. /atom children are /area, /turf and /movable [hence atom/movable]. The bumped() object does not necessarily have to be just an /obj or /mob right?

obj/Armor // A datum named Item for items (obviously).


density = 1 // Makes the item dense (unable to walk through)
var/amount = 1 // Stacking system!
Bumped(mob/M) // If something Bump()s into it, this is called.
if(!ismob(M)) return 0 // If M (the argument sent) is not a mob, the rest is stopped from happening
if(!M.client) return 0 // If M is not a client (human player), the rest of the procedure does not happen.
Pickup_proc(M) // Calls the procedure Pickup_proc.

verb/Pickup()
set src in oview(1) // Makes the verb available if the user if within 1 tile from the source.
Pickup_proc(usr) // You know what this does.


proc/Pickup_proc(mob/M) // Reason why I defined this instead of just having the verb is so I can pick up /Item's by bumping into them. Sure I could call the verb through Bumped() but than the usr would be someone else.
if(!(M in oview(1,src))) return // Checks if M is within 1 tile. If it isn't, the procedure stops.
.=Move(M) // Tries to moves the item to one step behind the user.
M << "[(.)?"\green":"\red"] You[(.)?"":" did not"] pick up [src.name]." // Checks if the item was picked up sucessfully. (x)?y:z is a mini-if() statement: if(x){ y } else { z }

//Armors list

var/equiptype


KasablancRobeMale
icon = 'Kasablanc Robe Male.dmi'
icon_state = ""
name = "Kasablanc Robe (M)"
equiptype = "chest"
KasablancRobeFemale
icon = 'Kasablanc Robe female.dmi'
icon_state = ""
name = "Kasablanc Robe (F)"
equiptype = "chest"
KasablancPants
icon = 'Kasablanc pants.dmi'
icon_state = ""
name = "Kasablanc Pants"
equiptype = "legs"
KasablancCloak
icon = 'Kasablanc Cloak.dmi'
icon_state = ""
name = "Kasablanc Cloak"
equiptype = "back"
KreptkinPantsMale
icon = 'Kreptkin Pants Male.dmi'
icon_state = ""
name = "Kreptkin Pants"
equiptype = "legs"
KreptkinShirtFemale
icon = 'Kreptkin shirt female.dmi'
icon_state = ""
name = "Kreptkin Blouse (F)"
equiptype = "chest"
KreptkinSkirt
icon = 'Kreptkin skirt.dmi'
icon_state = ""
name = "Kreptkin Skirt"
equiptype = "legs"
KreptkinSuitMale
icon = 'Kreptkin Suit Male.dmi'
icon_state = ""
name = "Kreptkin Suit (M)"
equiptype = "chest"
NutoriRobeFemale
icon = 'Nutori Robe female.dmi'
icon_state = ""
name = "Nutori Robes (F)"
equiptype = "chest"
NutoriRobeMale
icon = 'Nutori Robe Male.dmi'
icon_state = ""
name = "Nutori Robes (M)"
equiptype = "chest"
PuraelicChest
icon = 'Puraelic chest m.dmi'
icon_state = ""
name = "Puraelic Chestpiece"
equiptype = "chest"
PuraelicGauntlets
icon = 'Puraelic gauntlets.dmi'
icon_state = ""
name = "Puraelic Gauntlets"
equiptype = "glove"
PuraelicPantsMale
icon = 'Puraelic pants male.dmi'
icon_state = ""
name = "Puraelic Greaves (M)"
equiptype = "legs"
PuraelicPantsFemale
icon = 'Puraelic pants female.dmi'
icon_state = ""
name = "Puraelic Greaves (F)"
equiptype = "legs"
ShaedralGoggles
icon = 'Shaedral Goggles.dmi'
icon_state = ""
name = "Shaedral Goggles"
equiptype = "head"
ShaedralMask
icon = 'Shaedral Mask.dmi'
icon_state = ""
name = "Shaedral Facemask"
equiptype = "face"
ShaedralPants
icon = 'Shaedral Pants.dmi'
icon_state = ""
name = "Shaedral Pants"
equiptype = "legs"
ShaedralShirtFemale
icon = 'Shaedral shirt female.dmi'
icon_state = ""
name = "Shaedral Shirt (F)"
equiptype = "chest"
ShaedralShirtMale
icon = 'Shaedral shirt male.dmi'
icon_state = ""
name = "Shaedral Shirt (M)"
equiptype = "chest"


I had to put two instances of equiptype one in obj and one in mob because compiler flipped out if i only left it in one or the other.
On further review, the shoulderpiece, etc. vars are really pointless. You actually already have the vars you need under the mob; the InvLayer() proc still needs to be a mob proc, though.

Just to help you out, here are some of the concepts I mean.

First, all the vars like shoulderpiece, mainhandpiece, etc. are pointless. All an equippable object needs to track is its overlay icon. So you'd just have a var/overlay_icon, and that's it. No shoulderpiece, glovepiece, and so on.

InvLayer() would look like this:

mob/proc/InvLayer()
var/list/new_overlays = list()
for(var/slot in list("shoulder","mainhand",...))
var/obj/Armor/A = vars[slot]
if(A) new_overlays += A.overlay_icon
// this performs better than adding overlays one at a time
overlays = new_overlays


In MouseDrop() you have a crapload of redundant code. It'd be much better if you replaced all those if() blocks with one:
if(findtextEx(over_control,"inventory.")==1) // inside the inventory window.
if(over_control == "inventory.[equiptype]") // type matches
Equip(usr)
else
usr << output(null,"inventory.about")
usr << output(equiptype ? "That doesn't go there!" : "That isn't an equippable item!", "inventory.about")

You should have separate procs handle equipping and unequipping; it's just better design.

obj/Armor/proc/Equip(mob/M)   // note: we pass the mob instead of relying on usr
// auto-unequip--it's much nicer
var/obj/Armor/old = M.vars[equiptype]
if(old && old != src) old.Unequip(M, 1)

M << "Equipped [name]"
M.vars[equiptype] = src
loc = M.hiddenlist
// do not set equippped=1 here, because that var has no right to exist
M << output(src, "inventory.[equiptype]")
overlay_icon = icon
M.InvLayer()

obj/Armor/proc/Unequip(mob/M, auto)
if(M.vars[equiptype] != src) return
M << "Removed [name]"
M.vars[equiptype] = null
loc = M
if(!auto)
// no point doing this stuff if something else is being equipped
M << output(null, "inventory.[equiptype]")
M.InvLayer()

Without the equipped var, which is redundant and really a bad idea, all you need to do to tell if an object is equipped is to find its mob--if it's in mob.hiddenlist, presumably hiddenlist's parent is the owner or at least there's some reference to the owner--and then look at mob.vars[equiptype] to see if it matches the piece of equipment. This can be done with a proc if you like.

obj/Armor/proc/Equipped()
// this is just a guess; I have no idea how hiddenlist is implemented
var/obj/hiddenlist/H = loc
if(!istype(H)) return 0
var/mob/M = H.loc
return M.vars[equiptype] == src
There is so much in here I don't get that doesn't match -anything- I've done/learned thus far to such a degree that I'm more than a little overwhelmed. I don't even know where to START with adding all this stuff, let alone trying to understand how several things I've never touched even begin to work. I was really just looking to try and get the overlays to organize, but assuming this is THE ONLY WAY to do that, this is my best attempt.

mob
var
bagopened = 1
verb/bagopen()
if(bagopened==1)
bagopened = 0
winshow(src,"inventory",1) //Show the inventory window!
else if(bagopened==0)
bagopened = 1
winshow(src, "inventory",0)
else
src<<"Unknown bag opening error bagopen !=1/0"


mob
var
chest //Chest item variable
legs
shoulder
face
feet
head
back
mainhand
offhand
glove

list/hiddenlist = list()

var/equipped=0 //To know if its equipped or not




Entered(obj/Armor/A) // If an item or anything else sucessfully enters the mob's contents
..() // Checks to see if there's anything else to be called (in case).
if(istype(A))
var/obj/Armor/X=locate(A.type) in src.contents-A //Checks if there's an item with the same type already.
if(X) // If there's an item that exists with the same path
A.amount+=X.amount // Adds the amount of the item found
del X // Deletes that item found.
Inventory() // Calls the Inventory() prcoedure.

Exited()
..()
Inventory()

proc/Inventory()
var/i=1 // Current position (#) of contents
winset(src,"inventory.invent",{"cells="2x[contents.len+1]""}) // Sets column = 2, row = contents.len+1
src<<output("<b>Item</b>","inventory.invent:1,1") // Displays "Items" in the current cell, which is column 1, row 1
src<<output("<b>Amount</b>","inventory.invent:2,1") // Displays "Amount" in column 2, row 2
for(var/obj/Armor/I in contents) // Searches through the contents list
src<<output(I,"inventory.invent:1,[++i]") // Outputs to the cell: column=1, row = ++i (++i means (i+1) returned immediately. i++ means (i+1) but first returns the value of i).; this Sets the item (I) in to the current cell
src<<output(I.amount,"inventory.invent:2,[i]") // Displays the amount the item (I) has in to the cell: column=2, row = i (i is already now i+1 from the previous output())

MouseDrag(src_object,over_object,src_location,over_location,src_control,over_control,params)// When we drag it...
if(!(src in usr.contents)) return // If its not in our inventory...just cancel ...


MouseDrop(over_object=src,src_location,over_location,src_control,over_control,params) //When we drop it
if(findtextEx(over_control,"inventory.")==1) // inside the inventory window.
if(over_control == "inventory.[equiptype]") // type matches
Equip(usr)
else
usr << output(null,"inventory.about")
usr << output(equiptype ? "That doesn't go there!" : "That isn't an equippable item!", "inventory.about")


// if(src in usr.contents)
// if(src_control == "inventory.invent")
// if(over_control == "inventory.chestslot") //If its inside the inventory window.
// if(equiptype == "chest") //If you're equipping a 'chest' type
// if(!usr.chest) //And the chest slot is empty
// usr << "Equipped [src.name]"
// usr.chest=src
// src.loc = usr.hiddenlist
// equipped = 1
// usr << output(usr.chest, "inventory.chestslot")
// chestpiece = icon
// InvLayer()
// else
// usr << output(null,"inventory.about")
// usr << output("Need to unequip first!","inventory.about")
// else
// usr << output(null,"inventory.about")
// usr << output("That doesn't go there/isn't an equippable item!","inventory.about")
//
// if(over_control == "inventory.head") //If its inside the inventory window.
// if(equiptype == "head") //If you're equipping a 'chest' type
// if(!usr.head) //And the chest slot is empty
// usr << "Equipped [src.name]"
// usr.head=src
// src.loc = usr.hiddenlist
// equipped = 1
// usr << output(usr.head, "inventory.head")
// headpiece = icon
// InvLayer()
// else
// usr << output(null,"inventory.about")
// usr << output("Need to unequip first!","inventory.about")
// else
// usr << output(null,"inventory.about")
// usr << output("That doesn't go there/isn't an equippable item!","inventory.about")
//
// if(over_control == "inventory.face") //If its inside the inventory window.
// if(equiptype == "face") //If you're equipping a 'chest' type
// if(!usr.face) //And the chest slot is empty
// usr << "Equipped [src.name]"
// usr.face=src
// src.loc = usr.hiddenlist
// equipped = 1
// usr << output(usr.face, "inventory.face")
// facepiece = icon
// InvLayer()
// else
// usr << output(null,"inventory.about")
// usr << output("Need to unequip first!","inventory.about")
// else
// usr << output(null,"inventory.about")
// usr << output("That doesn't go there/isn't an equippable item!","inventory.about")
//
// if(over_control == "inventory.shoulder") //If its inside the inventory window.
// if(equiptype == "shoulder") //If you're equipping a 'chest' type
// if(!usr.shoulder) //And the chest slot is empty
// usr << "Equipped [src.name]"
// usr.shoulder=src
// src.loc = usr.hiddenlist
// equipped = 1
// usr << output(usr.shoulder, "inventory.shoulder")
// shoulderpiece = icon
// InvLayer()
// else
// usr << output(null,"inventory.about")
// usr << output("Need to unequip first!","inventory.about")
// else
// usr << output(null,"inventory.about")
// usr << output("That doesn't go there/isn't an equippable item!","inventory.about")
//
// if(over_control == "inventory.back") //If its inside the inventory window.
// if(equiptype == "back") //If you're equipping a 'chest' type
// if(!usr.back) //And the chest slot is empty
// usr << "Equipped [src.name]"
// usr.back=src
// src.loc = usr.hiddenlist
// equipped = 1
// usr << output(usr.back, "inventory.back")
// backpiece = icon
// InvLayer()
// else
// usr << output(null,"inventory.about")
// usr << output("Need to unequip first!","inventory.about")
// else
// usr << output(null,"inventory.about")
// usr << output("That doesn't go there/isn't an equippable item!","inventory.about")
//
// if(over_control == "inventory.legs") //If its inside the inventory window.
// if(equiptype == "legs") //If you're equipping a 'chest' type
// if(!usr.legs) //And the chest slot is empty
// usr << "Equipped [src.name]"
// usr.legs=src
// src.loc = usr.hiddenlist
// equipped = 1
// usr << output(usr.legs, "inventory.legs")
// legspiece = icon
// InvLayer()
// else
// usr << output(null,"inventory.about")
// usr << output("Need to unequip first!","inventory.about")
// else
// usr << output(null,"inventory.about")
// usr << output("That doesn't go there/isn't an equippable item!","inventory.about")
//
// if(over_control == "inventory.feet") //If its inside the inventory window.
// if(equiptype == "feet") //If you're equipping a 'chest' type
// if(!usr.feet) //And the chest slot is empty
// usr << "Equipped [src.name]"
// usr.feet=src
// src.loc = usr.hiddenlist
// equipped = 1
// usr << output(usr.feet, "inventory.feet")
// feetpiece = icon
// InvLayer()
// else
// usr << output(null,"inventory.about")
// usr << output("Need to unequip first!","inventory.about")
// else
// usr << output(null,"inventory.about")
// usr << output("That doesn't go there/isn't an equippable item!","inventory.about")
//
// if(over_control == "inventory.glove") //If its inside the inventory window.
// if(equiptype == "glove") //If you're equipping a 'chest' type
// if(!usr.glove) //And the chest slot is empty
// usr << "Equipped [src.name]"
// usr.glove=src
// src.loc = usr.hiddenlist
// equipped = 1
// usr << output(usr.glove, "inventory.glove")
// glovepiece = icon
// InvLayer()
// else
// usr << output(null,"inventory.about")
// usr << output("Need to unequip first!","inventory.about")
// else
// usr << output(null,"inventory.about")
// usr << output("That doesn't go there/isn't an equippable item!","inventory.about")

///
//
// else
/// return
//
// else
// if(src_control == "inventory.chestslot")
// if(usr.chest==src)
// if(equipped)
// usr.overlays -= chestpiece
// usr.chest=null
// equipped=0
// src.loc=usr
// usr << output(usr.chest, "inventory.chestslot")
// usr.Inventory()
var
chestpiece
legspiece
headpiece
facepiece
shoulderpiece
backpiece
feetpiece
glovepiece
mainhandpiece
offhandpiece
equiptype

proc/InvLayer()
var/list/new_overlays = list()
for(var/slot in list("shoulder","mainhand","offhand","back","legs","feet","chest","glove","face","head"))
var/obj/Armor/A = vars[slot]
if(A) new_overlays += A.overlay_icon

overlays = new_overlays

//usr.overlays += list(shoulderpiece, mainhandpiece, offhandpiece, backpiece, legspiece, feetpiece, chestpiece, glovepiece, facepiece, headpiece)
//usr.Inventory()

atom/proc/Bumped(atom/A) return 1 // And here is where we define the default for Bumped().. Note it is under /atom not /atom/movable. /atom children are /area, /turf and /movable [hence atom/movable]. The bumped() object does not necessarily have to be just an /obj or /mob right?



obj/Armor // A datum named Item for items (obviously).



density = 1 // Makes the item dense (unable to walk through)
var/amount = 1 // Stacking system!
Bumped(mob/M) // If something Bump()s into it, this is called.
if(!ismob(M)) return 0 // If M (the argument sent) is not a mob, the rest is stopped from happening
if(!M.client) return 0 // If M is not a client (human player), the rest of the procedure does not happen.
Pickup_proc(M) // Calls the procedure Pickup_proc.

verb/Pickup()
set src in oview(1) // Makes the verb available if the user if within 1 tile from the source.
Pickup_proc(usr) // You know what this does.


proc/Pickup_proc(mob/M) // Reason why I defined this instead of just having the verb is so I can pick up /Item's by bumping into them. Sure I could call the verb through Bumped() but than the usr would be someone else.
if(!(M in oview(1,src))) return // Checks if M is within 1 tile. If it isn't, the procedure stops.
.=Move(M) // Tries to moves the item to one step behind the user.
M << "[(.)?"\green":"\red"] You[(.)?"":" did not"] pick up [src.name]." // Checks if the item was picked up sucessfully. (x)?y:z is a mini-if() statement: if(x){ y } else { z }

//Armors list

var/equiptype

KasablancRobeMale
icon = 'Kasablanc Robe Male.dmi'
icon_state = ""
name = "Kasablanc Robe (M)"
equiptype = "chest"
KasablancRobeFemale
icon = 'Kasablanc Robe female.dmi'
icon_state = ""
name = "Kasablanc Robe (F)"
equiptype = "chest"
KasablancPants
icon = 'Kasablanc pants.dmi'
icon_state = ""
name = "Kasablanc Pants"
equiptype = "legs"
KasablancCloak
icon = 'Kasablanc Cloak.dmi'
icon_state = ""
name = "Kasablanc Cloak"
equiptype = "back"
KreptkinPantsMale
icon = 'Kreptkin Pants Male.dmi'
icon_state = ""
name = "Kreptkin Pants"
equiptype = "legs"
KreptkinShirtFemale
icon = 'Kreptkin shirt female.dmi'
icon_state = ""
name = "Kreptkin Blouse (F)"
equiptype = "chest"
KreptkinSkirt
icon = 'Kreptkin skirt.dmi'
icon_state = ""
name = "Kreptkin Skirt"
equiptype = "legs"
KreptkinSuitMale
icon = 'Kreptkin Suit Male.dmi'
icon_state = ""
name = "Kreptkin Suit (M)"
equiptype = "chest"
NutoriRobeFemale
icon = 'Nutori Robe female.dmi'
icon_state = ""
name = "Nutori Robes (F)"
equiptype = "chest"
NutoriRobeMale
icon = 'Nutori Robe Male.dmi'
icon_state = ""
name = "Nutori Robes (M)"
equiptype = "chest"
PuraelicChest
icon = 'Puraelic chest m.dmi'
icon_state = ""
name = "Puraelic Chestpiece"
equiptype = "chest"
PuraelicGauntlets
icon = 'Puraelic gauntlets.dmi'
icon_state = ""
name = "Puraelic Gauntlets"
equiptype = "glove"
PuraelicPantsMale
icon = 'Puraelic pants male.dmi'
icon_state = ""
name = "Puraelic Greaves (M)"
equiptype = "legs"
PuraelicPantsFemale
icon = 'Puraelic pants female.dmi'
icon_state = ""
name = "Puraelic Greaves (F)"
equiptype = "legs"
ShaedralGoggles
icon = 'Shaedral Goggles.dmi'
icon_state = ""
name = "Shaedral Goggles"
equiptype = "head"
ShaedralMask
icon = 'Shaedral Mask.dmi'
icon_state = ""
name = "Shaedral Facemask"
equiptype = "face"
ShaedralPants
icon = 'Shaedral Pants.dmi'
icon_state = ""
name = "Shaedral Pants"
equiptype = "legs"
ShaedralShirtFemale
icon = 'Shaedral shirt female.dmi'
icon_state = ""
name = "Shaedral Shirt (F)"
equiptype = "chest"
ShaedralShirtMale
icon = 'Shaedral shirt male.dmi'
icon_state = ""
name = "Shaedral Shirt (M)"
equiptype = "chest"


obj/Armor/proc/Equip(mob/M) // note: we pass the mob instead of relying on usr
// auto-unequip--it's much nicer
var/obj/Armor/old = M.vars[equiptype]
if(old && old != src) old.Unequip(M, 1)

M << "Equipped [name]"
M.vars[equiptype] = src
loc = M.hiddenlist
// do not set equippped=1 here, because that var has no right to exist
M << output(src, "inventory.[equiptype]")
overlay_icon = icon
M.InvLayer()

obj/Armor/proc/Unequip(mob/M, auto)
if(M.vars[equiptype] != src) return
M << "Removed [name]"
M.vars[equiptype] = null
loc = M
if(!auto)
// no point doing this stuff if something else is being equipped
M << output(null, "inventory.[equiptype]")
M.InvLayer()
The above ends up with the compiler errors:

inventory2.dm:66:error: Equip: undefined proc
inventory2.dm:385:error: overlay_icon: undefined var
inventory2.dm:242:error: A.overlay_icon: undefined var
The After Zone.dmb - 3 errors, 0 warnings
Page: 1 2