ID:175082
 
How do you make a mob do something if you have more a certain number of an item in your inventory?
Thanks.
ShadowBlade6300 wrote:
How do you make a mob do something if you have more a certain number of an item in your inventory?

One way to check for a number of items in your inventory might be this:
mob
proc/CountItems(objtype)
. = 0
for(var/obj/O in src)
if(istype(O, objtype)) ++.

proc/DeleteItems(objtype, number = 1)
for(var/obj/O in src)
if(istype(O, objtype))
del(O)
if(--number <= 0) return
You can use CountItems(/obj/doodad) to count how many doodads you have, and decide from there if that's enough doodads to do what you want. One common application of this is metallurgy in an RPG.
if(CountItems(/obj/ore/iron) >= 2 && CountItems(/obj/ore/tungsten))
DeleteItems(/obj/ore/iron, 2)
DeleteItems(/obj/ore/tungsten)
new /obj/ore/alloy(src)

Lummox JR
In response to Lummox JR
Or for a more generic approach, you can just test <code>if(mob.contents.len >= desired_amount)</code>.
In response to Foomer
Foomer wrote:
Or for a more generic approach, you can just test <code>if(mob.contents.len >= desired_amount)</code>.

Problem is that covers all items, not just items of a particular type. That tends to be a lot less useful.

Lummox JR
In response to Lummox JR
Oh, I misread "an item" as "items" :P