ID:144104
 
Code:
obj
var
Cdef
cloths
icon='Clothes.dmi'
layer=MOB_LAYER + 1
Blue
name="Blue Robe"
icon_state="Blue"
Cdef=10
Green
name="Green Robe"
icon_state="Green"
Cdef=25
Click()
if(suffix=="Equipped")
suffix=null
usr.overlays-=type
usr<<"You unequip [src]."
usr.def-=src.Cdef
else
for(var/obj/cloths/O in usr)
if(O.suffix=="Equipped")
O.suffix=null
usr.overlays-=O.type
usr<<"You unequip [O]."
suffix="Equipped"
usr.overlays+=type
usr.def+=src.Cdef


Problem description:

Well,... Let me try to explain the bug. it works fine by clicking the robe and getting the def, then clicking again and losing the def. But if you have BOTH robes, click(equip) one and then click the other one without unequipting the first one you dont lose the def of the first one. Example: You have 50def, you equiped the blue one and get 10def added on, then equiped the green one and get 25def added on, then again click the blue one and get ANOTHER 10 def added on, repeat and get 1000def in a minute...

Question: How would I fix this o.o
 obj
var
Cdef
cloths
icon='Clothes.dmi'
layer=MOB_LAYER + 1
Blue
name="Blue Robe"
icon_state="Blue"
Cdef=10
Green
name="Green Robe"
icon_state="Green"
Cdef=25
Click()
if(suffix=="Equipped")
suffix=null
usr.overlays-=type
usr<<"You unequip [src]."
usr.def-=src.Cdef
else
for(var/obj/cloths/O in usr)
if(O.suffix=="Equipped")
O.suffix=null
usr.overlays-=O.type
usr.def -= src.Cdef//You forgot to take out the def...
usr<<"You unequip [O]."
suffix="Equipped"
usr.overlays+=type
usr.def+=src.Cdef

There ya go, look at the line I commented...

-KirbyAllStar
In response to KirbyAllStar
Thanks, that helped alot, people cant gain ALOT of extra def :) But there is a bug with it o.o. If you where one robe and click the other without actually unequiping the first one, the def wont change, but if you clicked a robe that gives lower def and then unequiped it, the robe you will get the extra def.

Example: Start with 50def. Click blue robe with 20def giving you 70 def, then click a green robe that gives 10def still keeping your def to 70, when you unequiped the green one, your base def goes to 60 (only removing the blue robes def and not the green as its sappose to)

Sorry, im no good at explaining bugs :P
In response to Torla2217
Sorry that was my fault...

for(var/obj/cloths/O in usr)
if(O.suffix=="Equipped")
O.suffix=null
usr.overlays-=O.type
usr.def -= O.Cdef//Change it from src to O
usr<<"You unequip [O]."


-KirbyAllStar