ID:1068500
 
(See the best response by LordAndrew.)
Code:
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?

Best response
There is a lot wrong here, aside from the errors you're receiving. I'll address the error first though.

The error, "undefined proc", means you haven't defined Equip() and Unequip() as verbs, which you'll need to do. Which is simply just:

obj
Armors
verb
Equip()

Unequip()


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:

            Drop()
new/obj/Armors/Red_Armor(usr.loc)
view() << "[usr] drops [src]"
del(src)


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:

obj
item
verb
Get()
set src in oview(1)

// Attempt to Move() the item to the player. If it succeeds, you receive a message.
if(Move(usr))
usr << "You pick up [src]."

Drop()
if(Move(usr.loc)
usr << "You drop [src]."

armor
chainmail

platemail

leather

fishscalemail


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:

mob
var
defense = 0

obj/item/armor

obj
item
verb
// Define these functions so they are inherited, but don't set up what they do just yet.
Equip()

Unequip()

armor
var
defense = 0

// I don't recommend just copy and pasting these, as these are very loose examples and would have several issues in production use.
Equip()
// Set the player's armor variable to be a reference of src, which in this case is the armour they're equipping.
usr.armor = src

// Apply the defense bonus the armour gives.
usr.defense += defense

Unequip()
usr.armor = null

usr.defense -= defense

chainmail
defense = 1

platemail
defense = 2

etcmail
defense = 4


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. :)
I used that i changed te variables but this dont work i dont get the verb Equip
In response to Xalexx16
Strange. Keep in mind you'll want to pick up the item in order to be able to equip it, as the default setting for objs is set src in usr.
You'll need to make a check to see if they're already wearing the armor before just blindly adding to their defense.
OK there are a problem, now i get the Equip and UnEquip verbs but if i click on Equip i get +1 def but the armor is not in my character and if I give click to equip every time I get +1 def and I want somo can give once and the icon appears on my character armor.
Hmm the problem is, the red armor src when is equiped this is under the Player src