ID:154241
 
Could someone show me design and code wise how one would go about assigning a player's key to a mob to show that the that key holder is the owner of the mob??

Also I should make it clear these are like NPC mobs while the player keeps their own ID, icon, and stats.

LJR
Not so sure about it LJR, if I were you I would look for one of the monster demos I believe i saw, or library... One or the other, or just my imagination.

..to lazy to post info.
LordJR wrote:
Could someone show me design and code wise how one would go about assigning a player's key to a mob to show that the that key holder is the owner of the mob??

Also I should make it clear these are like NPC mobs while the player keeps their own ID, icon, and stats.

Just make another variable and set it to usr.key.

mob/pet/bibbles
var/owner = "Spuzzum"
name = "Bibbles"
desc = "I'm not sure what it is. Don't ask."


I leave it up to you to determine what sort of algorithms you want to use to lookup the owner from the pet's perspective -- or looking up the pet from the owner's perspective, which is considerably more difficult. =P

A nifty system that you might want to let bother your conscience is to have a variable that exists as text -- once something tries to access that text, it converts that text to an actual mob reference by scanning the world for a target. You can then later use the mob reference directly. When that mob reference vanishes (when it is saved, normally), you convert the reference back into a text string for saving the pet independently without being forced to have an actual reference, which can cure many problems, especially when pets might be loaded at any time, before or after their owners.
In response to Spuzzum
Spuzzum wrote:
A nifty system that you might want to let bother your conscience is to have a variable that exists as text -- once something tries to access that text, it converts that text to an actual mob reference by scanning the world for a target. You can then later use the mob reference directly. When that mob reference vanishes (when it is saved, normally), you convert the reference back into a text string for saving the pet independently without being forced to have an actual reference, which can cure many problems, especially when pets might be loaded at any time, before or after their owners.

You hit on something that's a big problem for anyone who deletes the mob: A mob reference is handier, but it can also vanish suddenly.

I think relying on automatic conversion to a text key is probably not likely to work, so what's needed is a pair of vars:
obj/pet
var/mob/owner
var/owner_ckey

proc/IsOwner(mob/M)
if(M==owner) return 1
if(!owner && M.client && M.client.ckey==owner_ckey)
owner=M // restore the reference
return 1
return 0

The idea is to set the key along with the owner reference. If the owner reference vanishes, it can be reestablished later from the key. The proc above is just one way it could be restored. (The code would need further modification for situations where a user has multiple characters whose names may differ from the key. I'd suggest owner_ckey="[owner.client.ckey]:[ckey(owner.name)]" for that. Then you'd compare later if owner_ckey=="[M.client.ckey]:[ckey(M.name)]".)

Lummox JR
In response to Lummox JR
I think relying on automatic conversion to a text key is probably not likely to work, so what's needed is a pair of vars:

*shrug* It works for my text MUD -- it saves room exits as text string IDs, and then converts them to references at run-time when the room is loaded. When the room is unloaded, the references are converted back into text strings before the room is saved. If the reference itself is deleted, the world checks through to see anything that references it and clears the reference.

Thus, it is possible, though there is ample room for error if you don't provide for every situation, like trying to load a room twice, trying to save an unloaded room, and so on.