ID:1388375
 
(See the best response by Ter13.)
Code:
obj
gun
verb
Get()
set src in oview(1)
usr.contents += src
view() << "[usr] picks up \a [src]"
Drop()
new/obj/gun(usr.loc)
view() << "[usr] drops \a [src]"
del(src)
Equip()
if(usr.weapon_equipped == 0)
overlays += /obj/gun
usr.str += 2
usr.weapon_equipped = 1
view() << "[usr] equips a sword."
else
usr << "You are already wielding something."
Unequip()
if(usr.weapon_equipped == 1)
usr.weapon_equipped = 0
usr.str -= 2
view() << "[usr] unequips a sword."
else
usr << "You aren't wielding this."


Problem description: i dont get how to overlay or anything i tried searching it up but i still dont get it but the con doesn't show up

You can't just add a type to overlays, you need to create a new object:

var/obj/gun/g = new/obj/gun()
mob.overlays += g


Also, note that since you aren't specifying usr on overlays, you are adding to the equipped gun's overlays, as the current scope of the verb is src.
In response to Ter13
Ter13 wrote:
You can't just add a type to overlays

DM Reference (/atom/var/overlays):
The data types that may be used as overlays are icons, icon states (text strings), objects, and object types.
(Honestly, I've never used text as an overlay, but apparently that's a thing.)
any where would i put that code because i put it over here:

Equip()
if(usr.weapon_equipped == 0)
var/obj/gun/g = new/obj/gun()
mob.overlays += g
overlays += /obj/gun
usr.str += 2
usr.weapon_equipped = 1
view() << "[usr] equips a sword."
else
usr << "You are already wielding something."
Really, adding types? That's weird. Does it instantiate a type as a shortcut?

also: mob is undefined. You can't just copy and paste. You need to use the correct object reference, and not just copy/paste what I wrote.
then what do i do cause im still kindad confused
In response to Ter13
Ter13 wrote:
Does it instantiate a type as a shortcut?

DM Reference (full paragraph):
The data types that may be used as overlays are icons, icon states (text strings), objects, and object types. When an icon state is used, the corresponding image in the object's icon is displayed. When another object is used as an overlay, a static "snapshot" of the object is taken at the time when the overlay is created. Future changes to the object will not change the appearance of the overlay.
It apparently doesn't use object instances in the list at all. It can take object instances. Whatever it gets is converted into some kind of snapshot. Of course, I have no clue. The image() proc does this kind of thing too.
i really dont get what to do can someone just please tell me how to do this
Best response
Ah, that makes a lot of sense, just grabbing an internal appearance reference and building overlays by a series of overlapped appearances. --Should have realized that.

In this case, you will want to make sure you are adding to the usr's overlays:

Equip()
if(usr.weapon_equipped == 0)
usr.overlays += /obj/gun
usr.str += 2
usr.weapon_equipped = 1
view() << "[usr] equips a sword."
else
usr << "You are already wielding something."
thank you it worked now i finally can go on to projectiles