ID:262358
 
Code:
    Click()
if(src.loc!=usr)return
if(src in usr.equipped)
usr.agipls-=agipls
usr.wispls-=wispls
usr.intpls-=intpls
usr.vitpls-=vitpls
usr.strpls-=strpls
usr.dexpls-=dexpls
suffix=null
usr.equipped-=src
if(shirt)usr.shirt=null
if(shoes)usr.shoes=null
if(gloves)usr.gloves=null
if(pants)usr.pants=null
if(hat)usr.hat=null
usr.overlays-=image(src.icon,"ov")
return
if(shirt)
if(!usr.shirt)usr.shirt=src
else
usr.shirt.Click()
if(shoes)
if(!usr.shoes)usr.shoes=src
else
usr.shoes.Click()
if(gloves)
if(!usr.gloves)usr.gloves=src
else
usr.gloves.Click()
if(pants)
if(!usr.pants)usr.pants=src
else
usr.pants.Click()
if(hat)
if(!usr.hat)usr.hat=src
else
usr.hat.Click()
suffix="Equipped"
usr.agipls+=agipls
usr.wispls+=wispls
usr.intpls+=intpls
usr.vitpls+=vitpls
usr.strpls+=strpls
usr.dexpls+=dexpls
usr.overlays+=image(src.icon,"ov")
usr.equipped+=src
usr.element=src.element


Problem description:
Okay, it's supposed to be if one item is equipped, and you try to equip one of the same type(hat, shoe, shirt, etc.), it will unequip the other and equip the first one. It works for the first time, but the second time, they're -both- equipped. ;o Is there anyway to fix this?
Thats some crazy code you got there.
An easy fix for that is to give each type of equipment a var such as "weaponequipped" Set the vars up and code them in so that when you equip the item, the var will equal one.
...agh. I sound confusing. Heres how I did it.

Code:
obj
weapons
verb
Equip()
set category = "Items"
if(src in usr.contents)
if(usr.weapon_equip == 0)
if(src.equipped == 0)
src.equipped = 1
usr.weapon_equip = 1
src.suffix = "Equip"
usr.Str += src.Str
usr.WeaponDelay+=src.WeaponDelay
else
src.equipped = 0
usr.weapon_equip = 0
src.suffix =""
usr.Str -= src.Str
usr.WeaponDelay-=src.WeaponDelay
else
if(src.equipped == 1)
src.equipped = 0
usr.weapon_equip = 0
src.suffix =""
usr.Str -= src.Str
usr.WeaponDelay-=src.WeaponDelay
else
usr<< "<B>Unequip your other weapon first!"


Ignore the top verb, Im currently trying to fix a small bug with it. But you should be able to see how you set up the variables.
In response to Team CS
Team CS wrote:
Thats some crazy code you got there.
An easy fix for that is to give each type of equipment a var such as "weaponequipped" Set the vars up and code them in so that when you equip the item, the var will equal one.

Good gads no. Hell Ramen is doing it the right way right now, by telling the mob which item of each type is equipped. Telling the equipment to set a var to 1 instead is absolutely wrong. The equipment can always find out if it's equipped by asking the mob that's holding it; it's much more important for the mob to know which items it has equipped.

For a system with this many slots, I'd recommend an associative list approach. The mob would have a list, equipment, which is null until needed. Items are added to it by associating a slot name (e.g., "shirt") with an item equipped for that slot. For example:
obj/item
var/slot

// call these procs from a verb, but make no assumptions about usr;
// loc should always be the mob equipping this item

proc/Equip()
if(!slot) return // not equippable
var/mob/M = loc
if(!istype(M)) return
if(!M.equipment) M.equipment = new // initialize the list
var/obj/item/O = M.equipment[slot]
// try to unequip the current item in that slot
if(O && !O.Unequip(slot)) return
M.equipment[slot] = src
suffix = "(equipped)"

// return true if successful
proc/Unequip(from_slot)
var/mob/M = loc
if(!istype(M)) return
// you can check here if cursing or such is involved; if so return

if(M.equipment && M.equipment[from_slot || slot]==src)
if(from_slot)
// slot==from_slot should always be true
// but this is not a given if a bug happens
if(from_slot==slot || M.equipment[slot]!=src) suffix = null
M.equipment -= from_slot
// do not delete equipment list if empty, because something
// else called this proc that wants to use it
else
M.equipment -= slot
suffix = null
// if from_slot was null, this is a routine unequip
// so go ahead and delete the equipment list if empty
if(!M.equipment.len) M.equipment = null
return 1


Lummox JR
In response to Lummox JR
Woah, thanks Lummox!
When you said associative(spellingerror'd for me) list, I was thinking mob/var/list/equipment=list("shirt"=null), mob.equipped[slot]=src, or something. o.O I never no you could do that. Thanks Lummox.