ID:177564
 
What's is wrong with this code???


Smelt()
set src in view(1)
set category = "Commands"
var/choice = input("What would you like to smelt?") in list("Bronze Bar(1 Tin Ore,1 Bronze Ore needed)")
if(choice=="Bronze Bar(1 Tin Ore,1 Bronze Ore needed)")
if(usr.Tin >= 1 && usr.Bronze >= 1)
usr<<"You Smelted a Bronze Bar!!!"
usr.Tin -= 1
usr.Bronze -= 1
new/obj/item/BronzeBar(usr)
return
else
usr << "Not enough materials!!!"




these are the error I'm getting...


loading Codesterz's Runescape.dme
Smelting.dm:15:error:usr.Tin:undefined var
Smelting.dm:15:error:usr.Bronze:undefined var
Smelting.dm:17:error:usr.Tin:undefined var
Smelting.dm:18:error:usr.Bronze:undefined var

Codesterz's Runescape.dmb - 4 errors, 0 warnings (double-click on an error to jump to it)
tin and all of the other items are located here

obj/item/(Name)

The items are supposed to be deleted from the inventory...
Codesterz wrote:
Smelting.dm:15:error:usr.Tin:undefined var
Smelting.dm:15:error:usr.Bronze:undefined var
Smelting.dm:17:error:usr.Tin:undefined var
Smelting.dm:18:error:usr.Bronze:undefined var

Unless Tin and Bronze are vars defined for all mobs, you can't use them directly with usr. You'll have to cast usr to the correct type first, like this:
var/mob/character/M = usr
...
...and then use M.Tin and M.Bronze.

Assuming this is a standard RPG, you have another option available; don't use vars, but use ores in inventory:
var/obj/ore/tin/tinore = locate() in usr
var/obj/ore/bronze/bronzeore = locate() in usr
if(T && B)
... // do the smelting
del(T)
del(B)

For more complex cases where you need 2 or more of some kind of ore, try this:
var/mithril=0
var/silver=0
var/obj/ore/O
for(O in usr)
if(istype(O,/obj/ore/mithril)) ++mithril
else if(istype(O,/obj/ore/silver)) ++silver
if(mithril>=5 && silver>=2)
new /obj/armor/vest/mithril/A(usr)
for(O in usr)
if(mithril && istype(O,/obj/ore/mithril))
--mithril
del(O)
else if(silver && istype(O,/obj/ore/silver))
--silver
del(O)

Lummox JR
In response to Lummox JR
One other suggestion: Some general procs will be very handy for this sort of thing if you use items.
proc/CountItems(atom/container,itemtype)
var/i=0
for(var/obj/O in container)
if(istype(O,itemtype)) ++i
return i

proc/DeleteItems(atom/container,itemtype,n=-1)
if(n<0) n=container.contents.len
for(var/obj/O in container)
if(n<=0) return
if(istype(O,itemtype))
--n
del(O)

Then you can rewrite smelter code to look like this:
if(CountItems(usr,/obj/ore/tin) && CountItems(usr,/obj/ore/bronze))
...
DeleteItems(usr,/obj/ore/tin,1)
DeleteItems(usr,/obj/ore/bronze,1)

Lummox JR
In response to Codesterz
Is there something wrong with this when I get to level 20 or higher it alway says you failed to catch anything.


if(usr.mlevel >= 20)
set src in view(1)
var/mlevel = rand(1,5)
if(mlevel >= 20)
usr << "You obtain some bronze ore!!!"
usr.mexp += rand(10,15)
usr.MLevelup()
new/obj/item/Bronze(usr)
return
else
usr << "You fail to get anything!!!"
return
In response to Codesterz
Codesterz wrote:
Is there something wrong with this when I get to level 20 or higher it alway says you failed to catch anything.

if(usr.mlevel >= 20)
set src in view(1)
var/mlevel = rand(1,5)
if(mlevel >= 20)

Yes, something's wrong; I already told you about this in another post. I wasn't sure if you quite got it.

Because you're setting the local var/mlevel to a number from 1 to 5, it will never be 20 or more. Thus, your if() is always failing. And usr.mlevel wouldn't be right in the if(), because that's already 20 or more, so then the if() would always be true. What you need to change is the range you're using for the rand(). As I said in my other post, ultimately you need to take almost all of this code outside of those if() blocks so you're not repeating the same thing a million times.

Lummox JR