proc/addItem(var/mob/receiver, var/itemType, var/itemName, var/amountToGive = 1)
if(!receiver || !itemName || !itemType) return 0
var/path = "/obj/Item/"
path += "[itemType]/" //currently only necessary because of subclasses
path += itemName
path = text2path(path)
if(path in typesof(/obj/Item))
for(var/i = 0; i<amountToGive; i++)
if(length(receiver.inventory))//This is for grouping. Rather than creating a whole new obj, just increment the existing one
for(var/obj/Item/item in receiver.inventory)
if(istype(item,path))
item.amount ++
break
else
new path(receiver)
var/itemGetMsg = "Obtained [amountToGive] [itemName]"
if(amountToGive > 1) itemGetMsg += "s"
receiver << itemGetMsg + "!"
return 1
receiver << "Item '[itemName]' Not Found."
return 0
Problem description:
The above code WORKS, however the system doesn't work the way I actually want it to. Essentially I'm trying to be able to create item objects by name with that proc in a plug-and-play manner (i.e addItem(player, "Sword", 3)). What's getting in my way is that obj/Item has subclasses, and I'm not sure how I would be able to play around the type paths to accommodate that. A workaround would be to just make every item directly under obj/Item but that seems like a cheap bandaid to me, and I like what class hierarchy affords me in the way of exclusive variables, etc.
EDIT: Oh didn't see the edit