ID:145086
 
Ok, I have been trying for weeks now to have a working smithing system. It was alot harder to delete more than one item for osme reason, idk maybe im stupid. But lets get over that now and go to the helping..
turf/obj/anvil
icon = 'OBJ.dmi'
icon_state = "anvil"
layer=4
density=1
verb
Smith()
set src in oview(1)
if(!(locate(/obj/Items/Smith/Hammer) in usr.contents))
usr << "<font size=1><font color=yellow>You need a hammer to start smithing!"
return
else
var/smithing = input("What would you like to create?","SMITH MENU")in list("Iron Sword","Cancel")
if(smithing == "Iron Sword")
var/Iron_Bar = 0
for(var/obj/Items/Smith/I in usr.contents)
if(istype(I,ironitemType))
Iron_Bar++
if(Iron_Bar>=5)
for( var/i = 0; i < 6; i++ )
var/obj/Items/Smith/B = locate() in usr.contents
if(istype(B,ironitemType))
if( istype( B, ironitemType ) )
del(B)
usr.contents+=new/obj/Items/equipment/arms/right/Iron_Sword
usr << "<font size=1><font color=green>You smith an Iron Sword!"
return
else
usr << "<font size=1><font color=yellow>You need 5 iron bars to make an Iron Sword!"
return

This is my smithing code, it compiles cleanly.

Here is what I want it to do...
*locate 5 iron ore and delete to make an iron sword from inventory.

Here is what it is doing...
*deletes 4 ores and gives the iron sword. But next time you try smithing it doesnt delete any and gives you the sword.

So, what I'm really asking is if you can help fix this code up or, show me a cleaner system that isn't crazy.

higher than high. drakiel.

obj/anvil//You had turf/obj, I just set this as an object
icon = 'OBJ.dmi'
icon_state = "anvil"
layer=4
density=1
verb
Smith()
set src in oview(1)
if(!(locate(/obj/Items/Smith/Hammer) in usr.contents))
usr << "<font size=1><font color=yellow>You need a hammer to start smithing!"
return 0
//Since the above code block has a return, stopping the rest from happening, else is not needed here
var/smithing = input("What would you like to create?","SMITH MENU")in list("Iron Sword","Cancel")
switch(smithing)//Switch is more convient than multiple if(smithing==
if("Iron Sword")
var/Iron_Bar = 0
for(var/obj/Items/Smith/I in usr.contents) if(istype(I,ironitemType)) Iron_Bar++
if(Iron_Bar<5){usr << "<font size=1><font color=yellow>You need 5 iron bars to make an Iron Sword!";return}
//Just reorganised the top part
var/tmp/i=0
for(var/obj/Items/Smith/I in usr.contents)
if(istype(I,ironitemType))
del(I)
i++
if(i>=5)break//stops the deleting when 5 is reached
usr.contents+=new/obj/Items/equipment/arms/right/Iron_Sword
usr << "<font size=1><font color=green>You smith an Iron Sword!"
else return//this is part of the switch


I did this cuz I know you were trying... I think ;x read the comments about what was changed <.<

BTW: Tested and works, now go learn >.> Young whippershnapers

- GhostAnime

PPS: Tell me if it worked okay or not... you're lucky I didn't feel like being mean and addin problems in it... though because I did this when I was tired, I am not liable for any mistakes <.<
In response to GhostAnime
                    var/tmp/i=0
for(var/obj/Items/Smith/ironitemType/I in usr.contents)
//istype() could be included in the for() statement
del(I)
i++
if(i>=5)break//stops the deleting when 5 is reached
//usr.contents+=new/obj/Items/equipment/arms/right/Iron_Sword
new/obj/Items/equipment/arms/right/Icon_Sword(usr)
usr << "<font size=1><font color=green>You smith an Iron Sword!"
// else return//why would you need this?