ID:148382
 
I cant seem to get this code to work properly, it cant seem to ever visualise what the code is doing. Can any one help?
Its meant to equip any weapon, and unequip any weapon that is equipped, but it doesnt seem to do that.
Arms parent_type = /obj/ verb/Get() set src in oview(1) if(usr.weight == usr.maxweight) usr << "You cannot pickup [src], because you are carrying too much, put something down." return else src.Move(usr) Helm var defense,equipped = 0 verb/EquipUnequip() for(var/Arms/Helm/H in usr.contents) if(H.equipped == 0 && src.equipped == 1) H.equipped = 0 usr.defense-=H.defense usr << "You equip [src] and unequip [H]" usr.defense+=src.defense src.equipped = 1 return if(!H) usr << "You equip [src]" usr.defense+=src.defense src.equipped = 1 return if(H == src && src.equipped==1) usr << "You unequip [src]" usr.defense-=src.defense src.equipped = 0 return else usr << "You equip [src]" usr.defense+=src.defense src.equipped = 1 return verb/Drop() if(src.equipped == 1) usr << "You unequip [src] and drop it" src.equipped = 0 usr.defense-=src.defense src.Move(usr.loc)
Mrhat99au wrote:
I cant seem to get this code to work properly, it cant seem to ever visualise what the code is doing. Can any one help?
Its meant to equip any weapon, and unequip any weapon that is equipped, but it doesnt seem to do that.

Well, for starters, you've done equipment backwards. Way too many people do it this way, so you're not alone in the error. This is the wrong way to do it:
obj/item/weapon
var/equipped
Having a var belonging to the equipment that's 1 if it's in use and 0 if it isn't is practically useless. If at any time you want to know which weapon or armor is in use, you have to loop through everything in your contents to find it. That's ridiculous. This is the right way:
mob
var/obj/item/weapon/weapon // points to the actual weapon
var/obj/item/armor/armor // points to the armor
Each var will be null if nothing is equipped for that slot, or otherwise will be a reference to the actual item in use. That's the way it really should be done, and it's the reason your automatic unequipping code is so complex. When you change over to this system you can rewrite it like this:
// automatically unequip the current weapon
if(usr.armor != src) // equipping a new weapon, src
usr.armor.Unequip()
Much easier, isn't it?

Lummox JR