ID:140425
 
Kso. I have this little diddy right here, and my problem is that I have no idea how to do something like this.

Code:
mob
var
itemID // item id
itemAmt // item amount
proc
checkItems(itemID, itemAmt)
/*
itemID = whatever item thing is.
itemAmt = whatever item amount is.
*/


// Example in an NPC
NPC/Kirone
verb/Talk()
set src in oview(1)
usr<<"Hello, [usr]. Do you have the items I want?"
if(usr.checkItems(1,10)) // if itemID is 1, and itemAmt is 10, could this work?
usr<<"Yes you do!"
else
usr<<"No you don't..."
item
Juice
itemID = 1
verb/PickUp()
// How do I make the item amount for THIS item (itemID = 1) go up one?


Problem description:
Kso. I have this little diddy right here. How can I set an itemAmt IN itemID? Read the comments to know what I mean.
Loop through your contents, and when you find the item which ID matches, you check the amount.

Something like this:
atom //don't know if you mean mob or obj when you say Items
var
itemID
itemAmt
mob
proc
checkItems(itemID, itemAmt)
for(var/atom/X in contents)
if(X.itemID!=itemID)continue //these are not the items you're looking for *waves hand*
if(X.itemAmt>=itemAmt)return 1 //return value of 1
//returns 0 by default if it doesn't find
In response to Ruben7
I plugged that code right in, tried it out and it didn't work. That's when I realized I was probably too vague, lol.

Okay, so what I need this for is talking to an NPC. I need it to check the itemID and itemAmt for quests and junk like that.

mob/npc/Kirone
verb/Talk()
set src in oview(1)
if(checkItems(1,10))
return 1
else
return 0


Kind of like that, I suppose.
In response to Kirone
I understood what you meant and my example wasn't plug and play..
mob
var
itemID
itemAmt
proc
checkItems(itemID, itemAmt)
for(var/mob/X in contents)
if(X.itemID!=itemID)continue //these are not the items you're looking for *waves hand*
if(X.itemAmt>=itemAmt)return 1 //return value of 1
//returns 0 by default if it doesn't find
NPC/Kirone
verb/Talk()
set src in oview(1)
usr<<"Hello, [usr]. Do you have the items I want?"
if(usr.checkItems(1,10)) //if usr.checkItems() returns a value other than 0 or null do this:
usr<<"Yes you do!"
else //else, do this:
usr<<"No you don't..."
item
Juice //why is juice a mob?
itemID = 1
itemAmt=1 //each Juice mob has 1 itemAmt by default
verb/PickUp()
set src in oview(1)
for(var/mob/item/Juice/J in usr.contents)//if it finds a Juice already...
J.itemAmt+=src.itemAmt //add the amount of the Juice you're about to pick up
del(src)//code ends here if it finds a Juice in your contents
Move(usr) //if there's no Juice in your contents, add it
item/Juice should not be inside of mob right? It should be under obj like so...

obj
items
verb
// All items inherit this ability to pickup
Pick_Up()
set src in oview(1)
if(Move(usr))
usr << "You picked up [src]!"
weapons
melee
swords
LongSword
consumable
drinks
Juice

mob
player
npc
monster
troll
townfolk
baker


mob is typically reserved for things which are (mob)ile. Is your potion mobile?

There are a ton of examples for how to manage inventory systems in the forums and in the libraries and demo's section.

ts

In response to Ruben7
Sorry for the misunderstanding, I know Juice wasn't a mob, but I was in a hurry so I just added an example without double checking. My bad.

I'll re-test this ASAP.