ID:1070523
 
(See the best response by Kaiochao.)
Code:
mob
var
Armor_Equipped = 0
weapon_equipped = 0
obj
Equipables
Armors
Red_Armor
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]."
Equip()
if(usr.Armor_Equipped == 0)
set src in usr
usr.overlays += src
usr.Arm += 2
usr.Armor_Equipped = 1
view() << "[usr] wears some armor."
src.suffix = "(Equipped)"
else
usr << "You are already wearing something."
UnEquip()
if(usr.Armor_Equipped == 1)
usr.overlays -= src
usr.Arm -= 2
view() << "[usr] takes off some armor."
usr.Armor_Equipped = 0
src.suffix = ""
else
usr << "You aren't wearing this."

obj
verb
Get()

Drop()

Equip()

UnEquip()

obj
Equipables
Armors
Red_Armor
icon = 'Armors.dmi'
icon_state = "Red Armor"


OK I am using this bad code, for my its good but all are working - the item src when you Equip a object the item src equips under the player src why?? I want the src of the item is above the src of my player not UNDER... HOW I CAN DO THAT???? I NEED SOME ONE HELP PLEASE

Best response
You need to set the layer of the objects being used as overlays.
In response to Kaiochao
Kaiochao wrote:
You need to set the layer of the objects being used as overlays.

How i can do that?? are any tutorial here on byond?
In response to Xalexx16
layer is a built-in variable that you can change in the object's properties.
In response to Boubi
Boubi wrote:
layer is a built-in variable that you can change in the object's properties.

YEAH IT WORKED FINALLY THANKS A LOT!!!
Please stop saying things like "the player's src." I think you meant to say "I want the item to appear over my player, not under." Or if you really wanted to be specific (and show that you actually know what your code means), you would say "I want the item's icon to appear over the player mob."

src isn't some thing that exists for all objects in your game. It's not as if your armor "has" a variable called src. When you write the following line:

usr.overlays += src


...you could read that as, add the object that "contains" this code to the overlays of the object that activated this code.
No, not that Boubi's response worked i added that to my red armor obj.
obj
Equipables
Armors
Red_Armor
icon = 'Armors.dmi'
icon_state = "Red Armor"
layer = 4 // This makes the armor above the src.
In response to Xalexx16
Xalexx16 wrote:
> layer = 4 // This makes the armor above the src.
>


This is not correct. Red_Armor does not have a variable called src. Src only exists in procedures (procs and verbs). Imagine you had a self destruct proc like this:

Red_Armor
icon = 'Armors.dmi'
icon_state = "Red Armor"
layer = 4
proc
Self_Destruct()
del src


That procedure will delete the armor. What is the value of src? Well, it's the armor itself.

Imagine that the armor is laying on the ground. Its layer is equal to 4. Does that mean that it appears above itself? Nonsense! It just means that it will be drawn in layer 4, so if a player walks into the same space the armor will appear above them. When the armor is just hanging out on the ground doing nothing, there is no "src" or "usr."

Now I can tell that you're either a non-native english speaker or just very young, which makes understanding a programming language written by and for english speakers more difficult. Still, you should try to understand the concept of src (the object that "contains" the current proc or verb) and usr (the object that activated the proc or verb)
In response to Magicsofa
Magicsofa wrote:
Xalexx16 wrote:
> > layer = 4 // This makes the armor above the src.
> >

This is not correct. Red_Armor does not have a variable called src. Src only exists in procedures (procs and verbs). Imagine you had a self destruct proc like this:

> Red_Armor
> icon = 'Armors.dmi'
> icon_state = "Red Armor"
> layer = 4
> proc
> Self_Destruct()
> del src
>

That procedure will delete the armor. What is the value of src? Well, it's the armor itself.

Imagine that the armor is laying on the ground. Its layer is equal to 4. Does that mean that it appears above itself? Nonsense! It just means that it will be drawn in layer 4, so if a player walks into the same space the armor will appear above them. When the armor is just hanging out on the ground doing nothing, there is no "src" or "usr."

Now I can tell that you're either a non-native english speaker or just very young, which makes understanding a programming language written by and for english speakers more difficult. Still, you should try to understand the concept of src (the object that "contains" the current proc or verb) and usr (the object that activated the proc or verb)

Oh i seen that just now, and thanks it was a good response and worked, but my problem is not fully resolved because when i use Equip verb i get the armor on my src but if i use the Unequip the armor stills on the src and i can't remove from me the red armor.

Any code block within a verb or proc has two built in variables, usr and src. Its possible for usr to be null, in some cases, but never possible for src to be null because src is the SOURCE name-space, it is the owner of the current verb or proc in question.

You could imagine that src actually said self, and it would make more sense.

//this code is just to demonstrate an idea, it doesn't actually work
Red_Armor
Equip()
usr.armor = self//src
UnEquip()
usr.armor = null
Destroy()
del self//src



usr is usually the mob who called or initiated the verb / proc. Sometimes a usr can be something else or null, but that's beyond the scope of this post.

You can write code a lot better if you break it down into plain english what you want to do.

/*
When player clicks Equip for armor
-Set player's armor to the armor
-Update overlays or change graphics
-Distribute new stat values
-Update equipped status on the armor
*/

mob/var
base_defense = 1
mod_defense = 0
proc/get_defense()
return mod_defense + base_defense

Armor
parent_type = /obj
var/gives_defense = 1
var/mob/owner //we'll use this to determine who has this equipped, but you could get rid of this and just look at src.loc

proc/do_equip(mob/m)
if(!m) return
if(m.armor == src) return
owner = m
m.armor = src
m.mod_defense = src.gives_defense

proc/do_unequip(mob/m)
if(!m) return
owner = null
if(m.armor == src) m.armor = null
m.mod_defense = 0

verb/Equip()
set src in usr
do_equip(usr)
verb/UnEquip()
set src in usr
do_unequip(usr)

Armor/Red_Armor
icon = 'Armors.dmi'
icon_state = "Red Armor"
layer = 4
Equip()
..() //do default
//handle overlays here
UnEquip()
..() //do default
//handle overlays here


I hope that makes more sense.
Codes\New Armor Codes.dm:14:error: base_defense: bad variable definition
Codes\New Armor Codes.dm:14:error: mob_defense: bad variable definition
Codes\New Armor Codes.dm:23:error: m.armor: undefined var
Codes\New Armor Codes.dm:25:error: m.armor: undefined var
Codes\New Armor Codes.dm:26:error: m.mod_defense: undefined var
Codes\New Armor Codes.dm:31:error: m.armor: undefined var
Codes\New Armor Codes.dm:31:error: m.armor: undefined var
Codes\New Armor Codes.dm:32:error: m.mod_defense: undefined var
Codes\New Armor Codes.dm:34:error: Equip: duplicate definition
Codes\ARMORS.dm:93:error: Equip: previous definition
Codes\New Armor Codes.dm:59:error: Self_Destruct: duplicate definition
Codes\ARMORS.dm:105:error: Self_Destruct: previous definition
Codes\New Armor Codes.dm:3:error: usr.armor: undefined var
Codes\New Armor Codes.dm:3:error: self: undefined var
Codes\New Armor Codes.dm:2:error: Equip: undefined proc
Codes\New Armor Codes.dm:5:error: usr.armor: undefined var
Codes\New Armor Codes.dm:4:error: UnEquip: undefined proc
Codes\New Armor Codes.dm:7:error: self: undefined var
Codes\New Armor Codes.dm:6:error: Destroy: undefined proc
Codes\New Armor Codes.dm:26:error: src.give_defense: undefined var

i get a lot of errors
In response to Xalexx16
Xalexx16 wrote:
> Codes\New Armor Codes.dm:14:error: base_defense: bad variable definition
> Codes\New Armor Codes.dm:14:error: mob_defense: bad variable definition
> Codes\New Armor Codes.dm:23:error: m.armor: undefined var
> Codes\New Armor Codes.dm:25:error: m.armor: undefined var
> Codes\New Armor Codes.dm:26:error: m.mod_defense: undefined var
> Codes\New Armor Codes.dm:31:error: m.armor: undefined var
> Codes\New Armor Codes.dm:31:error: m.armor: undefined var
> Codes\New Armor Codes.dm:32:error: m.mod_defense: undefined var
> Codes\New Armor Codes.dm:34:error: Equip: duplicate definition
> Codes\ARMORS.dm:93:error: Equip: previous definition
> Codes\New Armor Codes.dm:59:error: Self_Destruct: duplicate definition
> Codes\ARMORS.dm:105:error: Self_Destruct: previous definition
> Codes\New Armor Codes.dm:3:error: usr.armor: undefined var
> Codes\New Armor Codes.dm:3:error: self: undefined var
> Codes\New Armor Codes.dm:2:error: Equip: undefined proc
> Codes\New Armor Codes.dm:5:error: usr.armor: undefined var
> Codes\New Armor Codes.dm:4:error: UnEquip: undefined proc
> Codes\New Armor Codes.dm:7:error: self: undefined var
> Codes\New Armor Codes.dm:6:error: Destroy: undefined proc
> Codes\New Armor Codes.dm:26:error: src.give_defense: undefined var
>

i get a lot of errors

Yeah. Because you haven't listened to anything anyone has tried to teach you. You're just copying and pasting our code examples which are meant to convey an idea, not fix your code. If you don't understand what you're doing with programming, you'll never be able to make anything worth while.
Nope, realy i read it but i dont understand all, you are a pro coder and you understand all for you thats simple, for me this is hard because i am a newbie, i will try do it agin.

Some time after the message i looked to the code some time and now i have only that
loading One Piece Stories.dme
Codes\New Armor Codes.dm:35:error: src.give_defense: undefined var

One Piece Stories.dmb - 1 error, 0 warnings (double-click on an error to jump to it)
Perhaps you read it, but you still copied it over. We can tell from the error messages.
You should probably try to find a library that does it for you, because you are currently incapable of writing your own system.
OK, i was looking on DM Reference and i found something about the overlays and that worked, the armor shows on the mob if you use the Equip verb and if you use the UnEquip too works, the armor not shows on the mob, thats what i was searchin. But this solution added a problem, if you drop or you add the item in the map this don't shows because of the overlays.
// the constant variables set the layer......
var/const
ARMOR_LAYER = FLOAT_LAYER-1
LEGS_LAYER = FLOAT_LAYER-2
BOTS_LAYER = FLOAT_LAYER-3
GLOVES_LAYER = FLOAT_LAYER-4
HAT_LAYER = FLOAT_LAYER-5
LEFTWEAPON_LAYER = FLOAT_LAYER-6
RIGHTWEAPON_LAYER = FLOAT_LAYER-7
// The obj
obj
Equipables
Armors
Red_Armor
icon = 'Armors.dmi'
icon_state = "Red Armor"
desc = "A simple red armor."
layer = ARMOR_LAYER // i use this because i use a armor so if you look on constant vars...
proc
Self_Destruct()
del src

// The verbs
obj
Equipables
Armors
Red_Armor
Get()
set src in oview(1)
if(Move(usr))
usr << "You pick up [src]."
Drop()
if(Move(usr.loc))
usr << "You drop [src]."
Equip()
if(usr.Armor_Equipped == 0)
set src in usr
usr.overlays += /obj/Equipables/Armors/Red_Armor
usr.Arm += 2
usr.Armor_Equipped = 1
src.suffix = "(Equipped)"
else
usr << "You are already wearing something."
Unequip()
if(usr.Armor_Equipped == 1)
usr.overlays -= /obj/Equipables/Armors/Red_Armor
usr.Arm -= 2
usr.Armor_Equipped = 0
src.suffix = ""
else
usr << "You aren't wearing this."
obj
verb
Get()

Drop()

Equip()

Unequip()

So any idea for how to do that? the problem is the obj dont show on the map.
You need to check if it is equipped before you drop it. Or you could just force an UnEquip on drop.
Not, is not equipped, but i think: If the const. verb changes the layer to -x, -x is under the turf or not?
In your drop verb, you let people just drop it, even if its equipped. You don't have any code written in the verb to check to see if its equipped or not before dropping it.
Ok now i modificated the drop code and when you drop this unequip your armor
                Drop()
if(Move(usr.loc))
usr << "You drop [src]."
if(usr.Armor_Equipped == 1)
usr.overlays -= /obj/Equipables/Armors/Red_Armor
usr.Arm -= 2
usr.Armor_Equipped = 0
src.suffix = ""
else
usr << "You Unequiped your armor and you droped it."
Page: 1 2