mob
var
list
Equipped_Items[0] //the list where it keeps track of what items you have equipped
Equip
var
Slot
Level = 1
list
Mods[0]
parent_type = /obj
DblClick()
var/mob/owner = usr
if(Slot in owner.Equipped_Items) //if item slot in equipped items
if(!(owner.Equipped_Items[Slot] == src)) //if its not the item we are clicking on
//usr << output(null, "[Slot]_Equip:1,1")
var/Equip/item = owner.Equipped_Items[Slot]
owner.Equipped_Items[Slot] = null
owner.Equipped_Items -= Slot
owner.contents += item
On_Unequip(item,item.Mods)
owner.Equipped_Items += Slot
owner.Equipped_Items[Slot] += src
owner.contents -= src
On_Equip(src,src.Mods)
//owner << output(src, "[Slot]_Equip:1,1")
else //if it is
//usr << output(null, "[Slot]_Equip:1,1")
var/Equip/item = owner.Equipped_Items[Slot]
owner.Equipped_Items[Slot] = null
owner.Equipped_Items -= Slot
owner.contents += item
On_Unequip(item,item.Mods)
else //if there no item equipped already of that type, equip
owner.Equipped_Items += Slot
owner.Equipped_Items[Slot] += src
owner.contents -= src
On_Equip(src,src.Mods)
//owner << output(src, "[Slot]_Equip:1,1")
proc
Can_Equip(Equip/Item)
if(usr.Level >= Item.Level) return 1
On_Equip(Equip/Item, var/list/variables)
for(var/variablename in variables)
if(variablename in vars)
vars[variablename] += variablename
else
usr << "ERROR VARIABLE DOES NOT EXIST"
On_Unequip(Equip/Item, var/list/variables)
for(var/variablename in variables)
if(variablename in vars)
vars[variablename] -= variablename
else
usr << "ERROR VARIABLE DOES NOT EXIST"
Testitem
Mods = list(
"Attack" = 50,
"Haste" = 120,
)
Problem description:
Just wondering if this would be the correct way to add modifiers to items by storing variables I want to modify in a list. I have a testitem that grants 50 attack and 120 haste stored in a list called Mods. When the item is equipped the users variables get added with the items modifier.
Definitely thought ahead with that safety check to make sure that the variables you have in the Mods list exists :)
But there are few things I want to talk about:
------------
(1) Does the user have the item?
For your DblClick(), you should check if the item actually belongs to the user (ex: by seeing if it exists in the usr's content).
Otherwise people could DblClick() it on the ground/display area and gain the equip bonus without actually having the item.
(2) Reduce redundancy
I think you should have the if-slot-occupied-unequip check first. This way, what you could do, is unequip the currently equipped item THEN equip the item immediately without calling the equip verb once again (resulting in only one if() statement instead of if..else).
Why is this important? In case you have to fix something, it is much easier to correct in one spot than multiple spots
(3) Do not save ALL the variables :(
I think that you should define the Equip/var has a tmp variables (Equip/var/tmp/...).
The tmp variables tells DM not to save those values - great to use for any temporary variables :P
With tmp, since those variables are not saved, they are reset back to the defined values for that object. Great for fixing stats (boosting/nurfing) for something that's under/overpowered. Without tmp,, you would have to define additional checks to make sure that the Mods value is acceptable.
If you have some variables you DO want saved, be sure it is not under the tmp path.
(4) Are you accessing the correct objects variables?
I noticed that when you are adding the Mods to the variables, you did not mentioned the user.
What this results is that DM thinks you implied src thus you will be modifying src.var (the object's variable list) rather than user.vars.
because this proc can be called indirectly from the user, using usr is not recommended. You should pass who the usr is, probably with something like a variable.
For example, Equip/var/mob/Owner = (The user who owns it; set upon pickup or creation.).
------------
So to sum up what I mentioned:
------------
That's all I can think of at the moment :)