obj
Armors
Red_Armor
Get()
set src in oview(1)
usr.contents += src
view() << "[usr] picks up [src]"
Drop()
new/obj/Armors/Red_Armor(usr.loc)
view() << "[usr] drops [src]"
del(src)
Equip()
if(usr.armor_equipped == 0)
usr.Armor += 2 // usr.armor_equippped = 1
view() << "[usr] wears some armor."
else
usr << "You are already wearing something."
Unequip()
if(usr.armor_equipped == 1)
usr.Armor -= 2
view() << "[usr] takes off some armor."
else
usr << "You aren't wearing this."
mob
var
armor_equipped = 0
weapon_equipped = 0
obj
Armors
Red_Armor
icon = 'Armors.dmi'
icon_state = "Red Armor"
And i get this error
Error:
loading Game.dme
Codes\ARMORS.dm:13:error: Equip: undefined proc
Codes\ARMORS.dm:19:error: Unequip: undefined proc
Game.dmb - 2 errors, 0 warnings (double-click on an error to jump to it)
I haven't got any idea about whats bad there can some one help me?
The error, "undefined proc", means you haven't defined Equip() and Unequip() as verbs, which you'll need to do. Which is simply just:
With that out of the way though, this little snippet is fundamentally flawed. You're not using inheritence and other things to make your life easier at all. Take for example:
In this snippet, you're creating a new instance of the red armour and deleting the one in your inventory. This is generally not a good idea, especially if you've modified any of the variables associated with the original red armour. Plus, any time you create a new set of armour you'll have to come back and modify that line to make sure you're doing new/obj/Armors/Blue_Armor(usr.loc) and so forth. Same for Equip() and Unequip(); you'll have to modify the amount of defense the items give or else they'll all give 2.
For the most part, you should not be re-defining these functions for every piece of equipment. With inheritence, you can accomplish this:
Here, I've set up the /obj/item class and gave it two functions, Get() and Drop(). Any other class derived from /obj/item inherits those exact same verbs, meaning they'll all have the get and dropping methods by default. Much cleaner!
The next point I want to touch upon is armor_equipped and weapon_equipped. It's been proven that simply setting a Boolean variable to determine if something is equipped is the completely wrong way to go about it. This method does not convey any sort of information as to what you have equipped, which throws a good deal of object-orientated programming out the window. Ideally, you'd want to store a reference to the piece of equipment:
With this example, I also show how to set it up so you don't have to hardcode armour values as you were doing before. Each piece of armour has a defense variable you set, and within the equipping and unequipping method it adds/subtracts defense.
Lastly, as just a little pet peeve of mine, you shouldn't just tell the player "you have something already equipped." If I try to put on platemail and I have chainmail on, it's much nicer if the chainmail automatically unequips itself and equips the platemail for me. Saves your players a bit of time and feels much more intuitive. :)