ID:1902312
 
(See the best response by Kaiochao.)
I'm currently trying to use RPG framework to have an item that each player can customize and its name and icon state are based on a variable that the player changes. Example Item:

Code:
    CustomSword
name = src.swordname
icon_state = src.swordname
description = "None"
overlay_state = src.swordname
overlay_layer = 1
map_state = "[src.swordname]-map"

slot = MAIN_HAND

equipped(mob/m)
m.overlay(src)

unequipped(mob/m)
m.remove(src)


The item itself is an /obj

The player has a variable named "swordname" however I always thought src referred to the player's mob.

I can post more examples of my code here if needed but if anyone can refer me to the documentation on this or some sample code, the help would be much appreciated.

Thank you!
That's the issue.

src actually means 'whatever object this comes from'
usr means 'whatever initiated this'

Example:
obj/Apple

verb/Examine()
usr << "This is an [src.name]"

Outputs: "This is an Apple" to the player which called Examine().

Examine is defined under Apple. So src = Apple
The verb is initated when a player calls it. So usr = the player's mob.
Also, to answer the other part of your question (how do I actually do this?).

Here's one way. If you right-click a CustomSword in your inventory it will allow you to personalise it. Click personalise again to reset it back to normal.

obj/CustomSword
verb/Personalise()
set src in usr
if(name == initial(src.name))
name = "[usr.name]'s [initial(src.name)]"
else
name = initial(src.name)
The way you would go about automatically doing it is alter the verb you're using to pick up the sword in the first place. You alter it to include a type check and then if it turns out what you're picking up is a CustomSword then make sure it calls Personalise() on it.

Your Pick_Up() verb could be completely different but as long as it does the same check then this will work.

You will also want that when you drop an item of type CustomSword that you say name = initial(name). I'll let you do that to get the hang of it.

obj
verb/Pick_Up()
set src in oview(1)

if(istype(src,/obj/CustomSword))
var/obj/CustomSword/CS = src
CS.Personalise(usr)

obj/CustomSword

proc/Personalise(mob/OWNER)
name = "[OWNER.name]'s [initial(src.name)]"

Is there a way to get the players mob's variables without using a verb which finds its usr?

Can the object find variables in mobs or would I need to make some tmp vars which get their values from the mob?

For example something like;

swordID = mobs/mob.swordname


or

set usr as mobs/mob //then do, swordname = usr.swordname


or

tmp/swordname = "[mobs/mob.swordname]"



Don't know if you can actually use mobs/mob but I'm trying just state the variables location.
In response to DaGilbert
Best response
No. When setting initial values, you can only use constant values, and you can't reference variables of other types.

The solution to your problem requires your decision on when you want to link the variables of the sword with a specific mob. It must happen inside a proc or verb. You have a lot of options:
* When the sword is created by a mob (override a crafting-related proc, probably)
* When the sword is picked up by a mob (override a proc related to picking up items)
* When the sword is equipped by a mob (override a proc related to equipping items)
Notice that in each of the cases, I'm talking about the sword and a mob. When translating this concept from English to code, you'll have a specific mob to reference.
In response to DaGilbert
Short answer, no.
Okay I got it now! :D

Thanks Zecronious for the examples and Kaiochao for the different methods!

What ive done is this;

        

CustomSword
name = "CustomSword"
icon_state = "sword"
description = "None"
overlay_state = "sword"
overlay_layer = 1
map_state = "sword-map"

slot = MAIN_HAND

equipped(mob/m)
src.name = usr.swordname
src.overlay_state = usr.swordname
m.overlay(src)

unequipped(mob/m)
m.remove(src)


So when the item is equipped the equipping mob's swordname aka, custom name, is changing the items name to that value

Although I would like to know more about this equipped() and how it works. and what mob/m does.

the only other code I could find on equipped is

item
proc
equipped(mob/m)


And this which I assume is related

mob
var
list/equipment

proc
equip(item/item, slot = null)

if(dead) return 0

if(!equipment)
equipment = list()

if(!item) return

if(isnull(slot))
slot = item.slot

if(!slot)
return

if(equipment[slot])
if(!unequip(equipment[slot]))
return 0

if(item.can_equip(src))
item.in_slot = slot
equipment[slot] = item

if(inventory)
inventory.refresh()

item.equipped(src)

return 1
else
return 0


I am eyeing up that item.equipped(src)

This isn't my original code its taken from RPG framework which was mutilated and salvaged as a make shift system until I can rewrite one from scratch.

Thanks again ^.^
In equipped(), you should use m instead of usr. usr is bad juju in procs.