ID:1889720
 
(See the best response by Ter13.)
obj/proc/ItemName(obj/O)
var/ItemsName = list("Common","Uncommon","Rare","Legendary")
switch(pick(ItemsName))
if("Common")
O.name = "(<font color = Bronze> Common <\font>) [src]."
usr.contents += newlist(O)
return
else if ("Uncommon")
O.name = "(<font color = Silver> Uncommon <\font>) [src]."
usr.contents += newlist(O)
return
else if ("Rare")
O.name = "(<font color = Gold> Rare <\font>) [src]."
usr.contents += newlist(O)
return
else if ("Legendary")
O.name = "(<font color = Magenta> Legendary <\font>) [src]."
usr.contents += newlist(O)
return



obj
Weapons
Sword
name = ""
Knife
name = ""


var/Weapons = list(/obj/Weapons/Sword,/obj/Weapons/Knife)

mob/verb
CreateWeapon()
var/obj/O = pick(Weapons)
O.ItemName(O,usr)



Isnt working and idk why.
Best response
1) Switch doesn't need else-ifs.
2) You don't need to pass O as an argument for its own proc.
3) You don't need to pass usr to the ItemName proc.
4) ItemName shouldn't add the items to the contents of the usr. The proc is misnamed if so.
5) You are passing a type, not an object. You need to initialize an instance first.
6) There is no need to return in the switch control paths. The return is implicit because the function ends after the switch.
7) The objects have no initial name.
8) usr is invalid in this verb. This is a self-proc. Usr should only be called on "set src" procs.
9) that newlist is not what you want.

var
list/Qualities = list("Common","Uncommon","Rare","Legendary")

obj/proc/PickQuality()
switch(pick(Qualities))
if("Common")
name = "(<font color = Bronze> Common <\font>) [initial(name)]."
if ("Uncommon")
name = "(<font color = Silver> Uncommon <\font>) [initial(name)]."
if ("Rare")
name = "(<font color = Gold> Rare <\font>) [initial(name)]."
if ("Legendary")
name = "(<font color = Magenta> Legendary <\font>) [initial(name)]."



obj
Weapons
Sword
Knife


var/Weapons = list(/obj/Weapons/Sword,/obj/Weapons/Knife)

mob/verb
CreateWeapon()
var/t = pick(Weapons)
var/obj/O = new t(src)
O.PickQuality()
Been trying to add the item to the usr but cant seem to do it..