ID:1837650
 
(See the best response by Nadrew.)
Okay so I'm attempting to create a proc that checks and item's EquipSlot variable, determines what slot to equip the item in.

Code:
mob/var/slot1
mob/var/slot2

obj/item/equip/var/EquipSlot = 0

obj/item/equip/proc/SlotCheck()
usr.slot[src.EquipSlot] = src

///^ Obviously this won't work, but I want to figure out something like this that will work.



http://www.byond.com/developer/Wizkidd0123/EquipmentDemo

You can use that demo for reference. It does pretty much what you're looking for.
#define HEAD  1
#define TORSO 2
#define LHAND 4
#define RHAND 8
#define LEG 16

// number them w.e, I just like multiplying the prev. * 2 because it looks cool
Equipment

parent_type = /obj

var
list/slot = list("Head"=HEAD, "Torso"=TORSO, "LHand"=LHAND, "RHand"=RHAND, "Leg"=LEG)
list/data

proc


Equip(mob/m, Equipment/item)

if(!data)
data = list()

if(!data[item.slot])
data[item.slot] = list()

if(isOpen(item.slot))

Add2Equip(m, item)

else

var/previousItem = data[item.slot][m.ckey]

if(istype(previousItem,item))
Unequip(m, previousItem)
//Same item. Unequip it

else
//Different item, unequip previous and equip new
Unequip(m, previousItem)
Add2Equip(m, item)


Add2Equip(mob/m, Equipment/item)

data[item.slot][m.ckey] = item
world << "Equipped [item]: Slot([item.slot])"

Unequip(mob/m, Equipment/item)

data[item.slot] -= m.ckey
world << "Unequipped [item]: Slot([item.slot])"

isOpen(slot)
if(usr.ckey in data[slot])return 0
return 1

//Now let's try this out! (:
Head

slot = "Head"

Helmet

Torso

slot = "Torso"

Shield
slot = "LHand"

Weapon

slot = "RHand"

Sword1
Sword2

Leg
slot = "Leg"

var/Equipment/Equipment = new


mob/Login()
src.contents += new/Equipment/Head/Helmet
src.contents += new/Equipment/Weapon/Sword1
src.contents += new/Equipment/Weapon/Sword2
.=..()

mob/verb
Equip(var/item in usr.contents)
Equipment.Equip(usr,item)
Best response
Your 'data' list is entirely redundant, as are the associated values of your 'slot' list. This can be done with a single basic list.

mob
var/list/equipment


obj/equipment
var/slot
verb
Equip()
set src in usr
if(!slot) return // No slot, no equipment.
if(!usr.equipment) usr.equipment = list()
if(usr.equipment[src.slot])
var/obj/item/equipped = usr.equipment[src.slot]
if(equipped) equipped.Unequip(usr)
if(equipped == src) return // Stop with unequip.
usr.equipment[src.slot] = src
usr << "You have equipped [src] to your [src.slot]"
proc
Unequip(mob/holder)
if(holder.equipment && holder.equipment[src.slot])
if(holder.equipment[src.slot] == src)
holder.equipment[src.slot] = null
holder << "You have unequipped [src] from [src.slot]."


This allows you to have a dynamic array of slots without having to update the slots list, and entirely removes the need for a second list (which I didn't see the use of in the first place).
In response to Nadrew
Nadrew wrote:
Your 'data' list is entirely redundant, as are the associated values of your 'slot' list.

How are the associated values redundant? something like:
Equipment/Head/Helmet{slot=HEAD}

won't work if it is done directly that way, without the help of the associative list (it gives me a runtime error)

The reason I created the "data" datum was in order for admins and so forth to be able to monitor(if they pleased) which players had which items equipped, and which slot said item was located in and all that good stuff(once more things are added to the system itself)

Not to mention that your approach just looks outright ugly to me(personal preference here, but w.e)
Equipment/Head/Helmet{slot="Head"}


Would work perfectly fine with my example, there's no need to a numerical constant, you can use strings. Admins would easily be able to monitor equipment with mine too simply by viewing the contents of the 'equipment' list. This would show both the equipped item and the slot the item is equipped to.

Your method seems complex for the sake of complexity, and keep in mind my approach was written on the fly as an example of a less complicated means of doing what the original poster wanted that accomplishes the same thing without limiting the slots to constant values. You can literally give any piece of equipment any slot value you want and it would still work correctly without having to add a new numerical constant for a new slot.
In response to Nadrew
I would implement Unequip as a verb, not a proc, but allow it to be called as a proc by Equip. (usr would therefore still be valid.) It should not be assumed however that usr is the person wearing the equipment, nor that it's actually equipped.

The holder does not need to be an argument in Unequip(), because equipment you're carrying should be in the wearer's contents. Therefore, if src.loc is a mob, they're the holder. Otherwise, it should be assumed that src is not equipped at all.
I had a little bit of time to go back to this and edit some things, and this is what I came up with: please don't flame me for the use of datums, specifically the "database" one, as I plan on expanding upon it when more things are added. I actually like the way it turned out, I'll save it and possibly use it in the distant future, with some obvious tweaks of course. The way the code is written is visually pleasing(for me) and I don't find it "complex" as Nadrew stated.

I'm just posting this here so that I have somewhere I can find this and in case somebody else likes my approach as well.

Database datum:
database

var/list/data

proc

add(arg1, arg2)

if(!data[arg1])
data[arg1] = list()

if(!data[arg1][arg2])
data[arg1][arg2] = list()

modify(arg1, arg2, toggle, arg3)

switch(toggle)

if("-")
data[arg1][arg2] -= arg3
if("=")
data[arg1][arg2] = arg3
if("+")
data[arg1][arg2] += arg3

var/database/database = new

world/New()
.=..()
database.data = list()

mob/Player
Login()
.=..()
if(!database.data[src.ckey])
database.add(src.ckey, "items")


Equipment:
Equipment

parent_type = /obj

var/slot

proc

Equip(mob/m, Equipment/item)

if(isOpen(m, item.slot))
Add2Equip(m, item)

else

var/previousItem = database.data[m.ckey][item.slot]

//Same item. just unequip it
if(istype(previousItem,item))
Unequip(m, previousItem)

else
//Different item, unequip previous and equip new
Unequip(m, previousItem)
Add2Equip(m, item)

Pickup(mob/m, Equipment/item)

database.modify(m.ckey, "items", "+", item)
item.loc = m

m << "You picked up ([item])!"

Drop(mob/m, Equipment/item)

//Unequip before dropping
if(isEquipped(m, item))
Unequip(m, item)

database.modify(m.ckey, "items", "-", item)
item.loc = m.loc

m << "You dropped ([item])"

Add2Equip(mob/m, Equipment/item)

database.modify(m.ckey, item.slot, "=", item)
m << "Equipped [item]: Slot([item.slot])"

Unequip(mob/m, Equipment/item)

database.modify(m.ckey, item.slot, "=", null)
m << "Unequipped [item]: Slot([item.slot])"

isOpen(mob/m, slot)

if(database.data[m.ckey][slot])return 0
return 1

isEquipped(mob/m, Equipment/item)

if(database.data[m.ckey][item.slot] == item)return 1
return 0

verb/Get()

set src in oview(1)

Equipment.Pickup(usr,src)
usr.verbs += typesof(/mob/Equipment/verb)

//Test (:

Head

slot = "Head"

Helmet{icon='Helmets/Basic.dmi'}

Weapon

slot = "RHand"

Sword1{icon='Swords/Basic.dmi';icon_state="1"}
Sword2{icon='Swords/Basic.dmi';icon_state="2"}



var/Equipment/Equipment = new


mob/Equipment/verb

Equip(var/item in database.data[usr.ckey]["items"])
Equipment.Equip(usr, item)

Drop(var/item in database.data[usr.ckey]["items"])
Equipment.Drop(usr, item)


Also, please keep in mind that I did this in the spare time that I had, so there might be a lot of things that could be made more efficient. I'll get back to it some other time.

EDIT: Made some changes to the "database" datum to make it more relevant to the system itself, along with some other (minor) changes on the Equipment side(to accommodate the database revamp)
Thanks for the replies guys.