ID:179060
 
How do I search the inventory for an item?
mob/monsters/animals/cow
var/justmilked = 0
icon='players1.dmi'
icon_state = "cow"
name = "Cow"
verb
Milk()
set src in oview(1)
for(usr.contents)
if(src.type == /obj/item/bottle)
del(src)
new /obj/item/drinks/milk(usr.loc)
usr << "You milked a cow!"
justmilked=1
break()
else
justmilked = 0
if (justmilked == 0)
usr << "Milk spills everywhere. You need a bottle silly!"
The for proc is used for a var in a list, not just a list.
Try for(var/obj/O as obj in usr) instead. Don't use usr.contents, just use usr. Try to avoid the use of usr as much as possible, since it's very unstable as to who usr is.
Use a var that checks if the object is in usr, then use an if.
var/has_bottle = locate(/obj/bottle) in usr.contents
if(has_bottle)
//code here
else
usr << "You do not have a bottle."


-Rcet