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)
ID:177564
![]() Aug 26 2002, 8:34 am
|
|
Codesterz wrote:
Smelting.dm:15:error:usr.Tin: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 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 For more complex cases where you need 2 or more of some kind of ore, try this: var/mithril=0 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) Then you can rewrite smelter code to look like this: if(CountItems(usr,/obj/ore/tin) && CountItems(usr,/obj/ore/bronze)) Lummox JR |
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 |
Codesterz wrote:
Is there something wrong with this when I get to level 20 or higher it alway says you failed to catch anything. 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 |
obj/item/(Name)
The items are supposed to be deleted from the inventory...