ID:162306
 
I am trying to work on an anvil system and I am probably doing this ALL wrong, because this doesn't seem to be working, so can someone guide me in the right direction?
    Forge2
icon_state="Forge"
density=1
Click()
if(get_dist(usr, src) < 2)
usr.Freeze=1
if(locate(/obj/items/Mining/Ores)in usr.contents)
var/Smeltlist=list()
if(locate(/obj/items/Mining/Ores/Ironore)in usr.contents)
Smeltlist+="Ironore"
if(locate(/obj/items/Mining/Ores/Copperore)in usr.contents)
Smeltlist+="Copperore"
if(locate(/obj/items/Mining/Ores/Bronzeore)in usr.contents)
Smeltlist+="Bronzeore"
if(locate(/obj/items/Mining/Ores/Silverore)in usr.contents)
Smeltlist+="Silverore"
var/D=input("Which ore would you like to smelt?") in Smeltlist+"Cancel"
var/Total
for(D in usr.contents)
Total++
var/C=input("How many would you like to smelt?","Smelt",Total)as num
if(C>Total)
usr<<"[A][RED]You do not have this many!"
usr.Freeze=0
return
if(C<1)
usr<<"[A][RED]You cannot smelt less than 1!"
usr.Freeze=0
return
else
if(D==/obj/items/Mining/Ores/Ironore)
if(usr.Mining>=1)
start1:
if(Total>1)
sleep(20)
usr<<"[A][BLUE]You forge an iron ingot!"
del(D)
new/obj/items/Blacksmithing/Ingots/Ironingot(usr)
Total--
if(usr.Blacksmithing>=200)
goto start1:
else
usr.BlacksmithingXP+=5
usr.Blacksmithingup()
goto start1:
else
usr<<"[A][GREEN]Smelting completed!"
usr.Freeze=0
del(Smeltlist)
return
else
usr<<"[A][RED]You need at least 1 mining to smelt this!"
usr.Freeze=0
return
else
usr<<"[A][RED]You have nothing to smelt!"
usr.Freeze=0
return

The code isn't finished, I just did the coding for iron ore, once I know how to do it, I will apply to all of them. Thanks
Well, let's go for a bit more of an object-oriented approach, here. Each type of ore will have three variables:

minskill: the Mining skill required to smelt it
maxskill: the most Blacksmithing (why is there a Mining requirement but then a Blacksmithing skill gain?) skill you can get by smelting it
ingottype: the type of ingot that will be created when the ore is smelted

Obviously, all these variables would be defined under /obj/items/Mining/Ores, and then given values for each specific type of ore. For example:

obj/items/Mining/Ores/Ironore
minskill = 1
maxskill = 200
ingottype = /obj/items/Mining/Ores/Ironingot


With these variables, we can create a very generalized process of smelting the ore:

var/obj/Mining/Ores/O //we'll worry about selecting it in a little bit
if(usr.Mining >= O.minskill)
var/oretype = O.type //nab the type of the ore we'll be smelting
var/ingottype = O.ingottype //nab the type of the ingots we'll be making
//loop while we're still in range and we still have ore to smelt
while(get_dist(usr,src) < 2 && O)
//increase experience, if applicable
if(usr.Blacksmithing < O.maxskill)
usr.BlacksmithingXP += 5
usr.Blacksmithingup()
//as a note: you might as well make the Blacksmithingup() proc accept an argument and add that argument to BlacksmithingXP itself. So you'd just have Blacksmithingup(5) here. It'd be cleaner.
//delete the ore
del(O)
//create a new ingot (we only need to cast it to obj because we just want its name)
var/obj/I = new ingottype(usr)
//tell them what they just created
usr << "[A][BLUE]You smelt \a [I]"
//I've had bad luck with the \a text macro, actually, so I don't know if it will work here
//sleep for a bit
sleep(20)
//then, find a new piece of ore to smelt
O = locate(oretype) in usr
//now we're out of the while() loop so let's tell them we're done
usr << "[A][GREEN]You stop smelting."

//and here we've failed the skill check, so inform the player
else
usr << "[A][RED]You need at least [O.minskill] to smelt this!"

And that will work for any type of ore provided you've defined the three variables correctly. Now, we just need to write something to select the type of ore. Basically, we just need a list containing one of each type of ore you have in your inventory. That's actually rather easy, though there's one caveat: we also want to make sure we don't have multiples. Fortunately, a simple locate() can do that for us:

var/list/orelist = list()
for(var/obj/items/Mining/Ores/Q in usr)
//if we have a unique ore type
if(!locate(Q.type) in orelist)
orelist += Q
//if we found no ore
if(!orelist.len)
usr << "[A][RED]You have nothing to smelt!"
return
//select from the list, using "null|anything" to make a cancel button
var/obj/items/Mining/Ores/O = input("Which ore would you like to smelt?") as null|anything in orelist
//if they selected cancel
if(!O)
return


And that's all you need to do to select a piece of ore, and that goes straight into the first chunk of code. Easy.
In response to Garthor
Oh, oops, I accidentally used the wrong variable for the if statement

if(usr.Mining>=1)


to

if(usr.Blacksmithing>=1)


Lol my fault
In response to Godzooks
Well, I have it formatted to what it needs to be to have no errors, but theres 1 problem

obj/Non_items/Blacksmithing
icon='Blacksmithing.dmi'
Forge
icon_state="Forge"
Click()
if(get_dist(src,usr)<2)
var/list/orelist = list()
for(var/obj/items/Mining/Ores/Q in usr)
if(!locate(Q.type)in orelist)
orelist += Q
if(!orelist.len)
usr << "[A][RED]You have nothing to smelt!"
return

var/obj/items/Mining/Ores/O = input("Which ore would you like to smelt?") as null|anything in orelist
if(!O)
return
else
if(usr.Blacksmithing >= O.Forgelvl)
var/Oretype = O.type
var/Ingot = O.Ingot
while(get_dist(usr,src) < 2 && 0)
sleep(20)
var/obj/I = new Ingot(usr)
usr<<"[A][BLUE]You forge a new [I]!"
if(usr.Blacksmithing<O.Maxlvl)
usr.BlacksmithingXP+= O.Expgain
usr.Blacksmithingup()
del(O) // This part doesn't seem to work
O=locate(Oretype)in usr.contents // This part doesn't seem to work
usr<<"[A][GREEN]You stop smelting." // It goes straight to this
return
else
usr<<"[A][RED]You need at least [O.Forgelvl] to smelt this!"
return


It doesn't delete the ore, and it doesnt go to the while proc to keep going through until all of the ores have been forged.
In response to Godzooks
Couple mistakes:

                    if(!orelist.len)
usr << "[A][RED]You have nothing to smelt!"
return


This has to go outside the for() loop.

                                del(O) // This part doesn't seem to work
O=locate(Oretype)in usr.contents // This part doesn't seem to work


This needs to be outside the if() statement. Because you are using one of O's variables, you'll probably want to put it after.

                            sleep(20)


The sleep() in the while() loop should go at the end, not the beginning. Otherwise, players moving away from the anvil will still produce one more ingot. You'd also want to put a sleep() BEFORE the while() loop, I suppose, so the first ingot is not created instantly.
In response to Garthor
Ok is it correct now?
obj/Non_items/Blacksmithing
icon='Blacksmithing.dmi'
Forge
icon_state="Forge"
Click()
if(get_dist(src,usr)<2)
var/list/orelist = list()
if(!orelist.len)
usr << "[A][RED]You have nothing to smelt!"
return
else
for(var/obj/items/Mining/Ores/Q in usr)
if(!locate(Q.type)in orelist)
orelist += Q


var/obj/items/Mining/Ores/O = input("Which ore would you like to smelt?") as null|anything in orelist
if(!O)
return
else
if(usr.Blacksmithing >= O.Forgelvl)
var/Oretype = O.type
var/Ingot = O.Ingot
sleep(20)
while(get_dist(usr,src) < 2 && 0)
var/obj/I = new Ingot(usr)
usr<<"[A][BLUE]You forge a new [I]!"
if(usr.Blacksmithing<O.Maxlvl)
usr.BlacksmithingXP+= O.Expgain
usr.Blacksmithingup()
del(O) // This part doesn't seem to work
O=locate(Oretype)in usr.contents // This part doesn't seem to work
usr<<"[A][GREEN]You stop smelting." // It goes straight to this
return
else
usr<<"[A][RED]You need at least [O.Forgelvl] to smelt this!"
return
In response to Godzooks
                            del(O) // This part doesn't seem to work
O=locate(Oretype)in usr.contents // This part doesn't seem to work
usr<<"[A][GREEN]You stop smelting." // It goes straight to this
return


The indentation on these four lines is wrong. The first two should be inside the while(), and the last two shouldn't.

                if(!orelist.len)
usr << "[A][RED]You have nothing to smelt!"
return


This needs to be AFTER you populate the orelist list.
In response to Garthor
Well I am kinda confused because you are just showing little pieces of code and not showing where they go, but explaining, and I have a hard time with directions lol. But I combined what I want it to do with your system you showed me and heres exactly how I want it to work.

obj/Non_items/Blacksmithing
icon='Blacksmithing.dmi'
Forge
icon_state="Forge"
verb/Forge()
set src in oview(1)
var/list/Orelist=list()
var/Qty
var/ForgeAmt
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]You have nothing to smelt!"
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)
for(O in usr.contents)
if(locate(O)in usr.contents)
Qty++
var/obj/items/Mining/Ores/Amt = input("How many would you like to smelt?","Forge",Qty)as num
if(Amt<1)
usr.Working=0
return
if(Amt>Qty)
ForgeAmt=Qty
else
ForgeAmt=Amt
var/Ingot2=O.Ingot
while(ForgeAmt>0)
var/obj/I = new Ingot2(usr)
usr<<"[A][BLUE]You forge a new [I]!"
if(usr.Blacksmithing<O.Maxlvl)
usr.BlacksmithingXP+= O.Expgain
usr.Blacksmithingup()

del(O)
ForgeAmt--
usr<<"[A][GREEN]Smelting completed."
usr.Working=0
return
else
usr<<"[A][RED]You need at least [O.Forgelvl] to forge this!"
usr.Working=0
return

PS (Sorry for the edit, I posted early)
Now just a few things

-The system doesn't work after I define how many I want to put int :/
-Where exactly do I put sleep(20) in?
-What do I do after it asks if(ForgeAmt>0) to go back to while()