ID:176754
 
When I log in and equip an item I get the un-equip ability for the item but if I leave the game with the item equiped then load back my game the unequip function is gone and I cant un-equip the item. How can I stop this from happening? Here is the code:
obj
weapons
verb/equip()
set src in usr
if(!usr.ArmEqu)
usr.baseatk+=src.batkadd
usr.maxatk+=src.matkadd src.verbs+=/obj/weapons/proc/unequip src.verbs-=/obj/weapons/verb/equip usr.RArmE = 1
else
usr << "Cannot equip there" proc/unequip()
set src in usr usr.Damage-=src.damageadd
src.verbs-=/obj/weapons/proc/unequip
src.verbs+=/obj/weapons/verb/equip usr.ArmEqu = 0
Thank you for any help.
ShadowBlade6300 wrote:
When I log in and equip an item I get the un-equip ability for the item but if I leave the game with the item equiped then load back my game the unequip function is gone and I cant un-equip the item. How can I stop this from happening?

The problem is that the verbs are only ever added when you equip the item, but not when the item is read from a savefile. Try this:
obj/item/equipment
var/site // this will be the name of a var like "weapon" or "arm" for the mob

proc/EquipActions()
suffix="(equipped)"
verbs -= /obj/item/equipment/proc/Equip
verbs -= /obj/item/equipment/proc/Unequip // just in case
verbs += /obj/item/equipment/proc/Unequip // now add it back

proc/UnequipActions()
suffix=null
verbs -= /obj/item/equipment/proc/Equip // just in case
verbs -= /obj/item/equipment/proc/Unequip
verbs += /obj/item/equipment/proc/Equip // now add it back

Read(savefile/S)
..()
if(ismob(loc) && loc.vars[site]==src)
EquipActions() // this is equipped
else
UnequipActions()

proc/Equip()
set src in usr // this is used as a verb
if(usr.vars[site])
var/obj/item/equipment/E=usr.vars[site]
if(E==src) return
E.Unequip()
usr.vars[site]=src
EquipActions()
usr << "You equip [src]."
oview() << "[usr] equips \a [src]."

proc/Unequip()
set src in usr // this is used as a verb
if(usr.vars[site]!=src) return
usr.vars[site]=null
UnequipActions()
usr << "You unequip [src]."
oview() << "[usr] unequips \a [src]."

Drop() // this overrides /obj/item/verb/Drop
UnequipActions()
..() // go ahead and drop it

The main thing to pay attention to in that code is the override of Read(): It checks to see if it's equipped after it loads. (This may in fact not work right, if the object is loaded before the mob's var that says it's equipped. You might also need to override mob.Read().) If it is equipped, then it sets up the verbs as they should be.

Verbs don't save along with everything else, which is why you're seeing this effect.

Or, you can do an alternative:
atom/movable
proc/SaveVerbs()
return 0

Read(savefile/S)
..()
if("verbs" in S.dir)
S["verbs"] >> verbs

Write(savefile/S)
..()
if(SaveVerbs())
S["verbs"] << verbs

obj/item/equipment
SaveVerbs()
return ismob(loc)

Get() // override of Get verb from obj/item
..()
UnequipActions() // set up verbs as unequipped
And that Get() override I put in is because the Equip verb probably won't exist for this item if it wasn't saved.

Lummox JR