ID:2038794
 
so basically i think im close to figuring it out but idk what to do. im trying to do a check for a certain item in the inventory then do a amount check to see if i can craft it but the debug code keeps listing the first item in the inventory hwo can i get this working?
mob
verb
crafter()
switch(alert("Are you sure?","Start Chuunin Tournament","Kunai","No"))
if("Kunai")
for(var/obj/A in usr.Inventory)
if(findtext("[A]","Kunai"))
if("[A.name]"=="Kunai")
if(A.amount>=10)
src.RemoveInventory(new/obj/Attack/Weapons/Kunai,10)
usr<<"works"
src.AddInventory(new/obj/Attack/Weapons/LargeShuriken,1)
else
usr<<"[A.name]"
usr<<"You need 10 kunais"
return



Your current logic:
For each obj in usr.Inventory:
  If the obj's name contains "Kunai",
    If the obj's name equals "Kunai",
      If the obj's amount is greater than or equal to 10,
        Remove 10 of a new Kunai object (which isn't actually in the inventory) from the inventory
        Add a Large Shuriken to the crafter's inventory
  Else,
    Print "You need 10 kunais"
    Return

The logic you probably want:
Search for an item of a certain type in the crafter's inventory.
If the item is found, and if its amount is at least 10, then
    remove 10 from it
    and add a new LargeShuriken.
Otherwise (if the item isn't found), tell the crafter about the requirements.

It translates pretty directly to DM if you know what code actually does.
var obj/Attack/Weapons/Kunai/k = locate() in Inventory
if(k && k.amount >= 10)
RemoveInventory(k, 10)
AddInventory(new /obj/Attack/Weapons/LargeShuriken, 1)
else src << "You need 10 Kunai"
I should point out that this is not a robust crafting system at all. If you want to use crafting for more than one thing, I would suggest setting up a more generic way to handle all of this.

i wish i could but the problem is the way the inventory system is done im kinda forced to do it crudely
In response to Mastergamerxxx
Mastergamerxxx wrote:
i wish i could but the problem is the way the inventory system is done im kinda forced to do it crudely

I can't imagine that's true. I think you're imposing a limitation on yourself that doesn't have to be there. You can get all sorts of crafting systems working with all sorts of inventory systems; they're completely orthogonal.
In response to Mastergamerxxx
Mastergamerxxx wrote:
i wish i could but the problem is the way the inventory system is done im kinda forced to do it crudely

May I ask for you to post the inventory code? I'd like to take a look at it for ya :)
ok sure
mob/proc
AddInventory(obj/item2,num,havetopay)
if(src.money>=0)
if(src.money<item2.cost*num && havetopay)
src<<"Not enough money!"
return
else
var/tmp/list/nochange=list("Blood of","Capsule of")
var/found=0
var/obj/item=new item2.type
if(havetopay) src.money-=item.cost*num
for(var/f in nochange) if(findtext("[item2.name]","[f]",1)) found++
if(!found) item.name=initial(item2.name)
else item.name=item2.name
for(var/obj/A in src.Inventory)
if(A.name==item.name)
if(!(findtext("[item.type]","clothes",1)) && !(findtext("[item.type]","Bloodline",1)))
A.amount+=num
A.suffix="x[A.amount]"
return
else
return
item.amount=num
item.suffix="x[item.amount]"
src.Inventory+=item
if(!("[initial(item.name)]" in InventoryNow)) src.currentitem="[item]"
else
src<<"You have no money!"
RemoveInventory(obj/item,howmany)
if(!howmany) howmany=1
if(!item) return
item.name=initial(item.name)
for(var/obj/A in src.Inventory) if(A.name==item.name && A.amount>1) {A.amount-=howmany;A.suffix="x[A.amount]";return}
for(var/obj/A in src.Inventory) if(A.name==item.name) src.Inventory-=A
if(src.currentitem=="[item]" && !src.Inventory.len) src.currentitem=""
src.ChangeInventoryNext()


basically it uses a stacking system to keep track of how many of a item you have but the problem with it is it's probly highly inefficient and it probly really deeply coded and intertwine to just rip out so i was trying to figure out a craft system that would work with it.

its the basic inventory code from jinketsu so i didn't personalty code it im just trying to improve stuff
A flexible crafting system will work just fine with that. There's nothing a million copy-paste verbs can do that a single unifying system can't do better.
Here's something you could take a look at :)

obj/item/var
cost = 0
amount = 1
tmp/max_amount = 1

mob
var
money = 1000
list/Inventory = list()
proc
remove_from_inventory(obj/item/item, item_amount = 1)
var total_amount = 0
for(var/obj/item/look_for_item in src.Inventory)
if(look_for_item.type == item.type)
total_amount += look_for_item.amount
if(total_amount >= item_amount)
for(var/obj/item/remove_item in src.Inventory)
if(item_amount > 0)
if((remove_item.amount-item_amount) > 0)
remove_item.amount -= item_amount
else
src.Inventory -= remove_item
item_amount -= remove_item.max_amount
continue
break
return TRUE
src << "You don't have the required amount!"
return FALSE

add_to_inventory(obj/item/item, item_amount = 1, paying = FALSE)
if(paying)
if(src.money >= round(item.cost*item_amount))
var/obj/item/copy_item = new item.type
src.money -= round(item.cost*item_amount)
var found_item = FALSE
for(var/obj/item/look_for_item in src.Inventory)
if(look_for_item.type == copy_item.type)
if(look_for_item.max_amount > look_for_item.amount)
found_item = TRUE
look_for_item.amount += item_amount
look_for_item.suffix = "x [item.amount]"
src << "You found another [copy_item.name]."
return TRUE
break
if(!found_item)
src << "You added [copy_item.name] to your inventory!"
src.Inventory += copy_item
return TRUE
else
src << "You don't have enough money!"
return FALSE
else
src.Inventory += item
return TRUE
this looks quite interesting im def gunna play around with it