ID:142916
 
Can someone please help me? I am still having trouble with this, and I guess my last post is deleted.

Code:
obj/items/Blacksmithing
icon='Blacksmithing.dmi'
Ingots
Iron_ingot
icon_state="Iron ingot"
Copper_ingot
icon_state="Copper ingot"

obj/Non_items/Blacksmithing
icon='Blacksmithing.dmi'
Forge
icon_state="Forge"
verb/Forge()
set src in oview(1)
var/list/Orelist=list()
if(usr.Working==1)
return
else
usr.Working=1
for(var/obj/items/Mining/Ores/Q in usr.contents)
if(!locate(Q.type)in Orelist)
Orelist += Q
if(!Orelist.len)
usr<<"[A][RED]No ores found!"
usr.Working=0
return
var/obj/items/Mining/Ores/O = input("Which ore would you like to smelt?")as null|anything in Orelist
if(!O)
usr.Working=0
return
else
if(usr.Blacksmithing>=O.Forgelvl)
var/Maxlvl=O.Maxlvl // Maximum gain level
var/Expgain=O.Expgain // Experience gain
var/Ingot=O.Ingot // Used to grab the ingot to make
var/Sleeptime=O.Sleeptime // Used for how long to smelt selected ore for
var/Qty // Used to find out the amount of ores of the type you select
var/ForgeAmt // Used with the upcoming while() proc
var/Name=O.Name // Used for telling purposes
for(O in usr)
if(locate(O)in usr)
Qty++
var/obj/items/Mining/Ores/Amt = input("How many would you like to smelt?","Amount",Qty)as num
if(Amt<1)
usr.Working=0
return
if(Amt>Qty)
ForgeAmt=Qty
else
ForgeAmt=Amt
usr<<"[A][GREEN]You start blacksmithing!"
while(ForgeAmt>0)
sleep(Sleeptime)
usr<<"[A][BLUE]You forge a new [Name]!"
del(O)
ForgeAmt--
new Ingot(usr)
if(usr.Blacksmithing<Maxlvl)
usr.BlacksmithingXP+=Expgain
usr.Blacksmithingup()
usr<<"[A][GREEN]Smelting completed!"
usr.Working=0
return
else
usr<<"[A][RED]You need at least [O.Forgelvl] blacksmithing to forge this!"
usr.Working=0

obj/items/Mining
icon='Mining.dmi'
Ores
Iron_ore
icon_state="Ironore"
Forgelvl = 1
Maxlvl = 200
Expgain = 0
Ingot=/obj/items/Blacksmithing/Ingots/Iron_ingot
Sleeptime=20
Name="Iron ingot"
Copper_ore
icon_state="Copperore"
Forgelvl = 10
Maxlvl = 200
Expgain = 0
Ingot=/obj/items/Blacksmithing/Ingots/Copper_ingot


Problem description:
Theres a few problems:

(1) The part where it sees how many ores are in your inventory of the kind you selected, it counts all of the objects in your inventory.

Example:
-You want to forge iron ingots

---Inventory---
Copper Ore
Copper Ore
Copper Ore
Iron Ore
Iron Ore
Iron Ingot

It counts a total of 6 when it needs to only count 2


(2) During the while() proc, it doesn't delete the ore type you are smelting.

Example:
-You want to forge iron ingots

"You forge an iron ingot!"
new Ingot(usr)
del(O) << That wont work for some reason

I think this is because you aren't using the for loop properly. Your for(O in usr) loop should be something like:
for(var/obj/items/Blacksmithing/Ingots/i in usr)
if(istype(i,O.type))
Qty++


In your while loop you will need to set O to a different ingot at the top of the loop, since you are deleting it partway through.
In response to Hazman
That didn't work
In response to Godzooks
Well, I found a really funky way to calculate the total amount of ores of the type you select (and its a horrible way of doing so), but, when I go to delete the ores as while() continues, it only deletes the first ore, and none of the others. I think this is because once it deletes the first one, the variable no longer exists so it cannot delete any others. But I can't find a way to fix it
In response to Godzooks
Lower the quantity variable when you lose/drop/destroy/use/etc. an object and it's no longer there. Then delete the object when it goes to zero.
In response to Naokohiro
What? That made no sense. You want me to make all the ingots, then delete all the ores? That wouldn't look right then.
In response to Godzooks
Oh thank god, I finally found a way to fix it lol. There we go, now its working :D