ID:230741
 
(See the best response by Nadrew.)
I have a rough idea of what to do here, however I would like some opinions. I'll give a simple example of what I am looking to accomplish.

When a user first logs into the game they are given a 'House' (presumably a datum?). In this House they can store objects such as a bed and television. When that user logs out, the contents of their House are saved. At this point, an Online user can break into that House and steal the television (moving it into their own 'House').

I assume the House should be a datum containging a list of contents and a way to identify the owner. Where should I store this datum? Should it's location change when the owner is online?

I'd like to hear of any other ways of handling this or if there are any Libraries/Demos that are similar to what I am aiming for. Thanks.
Depends how people are going to be accessing these houses
A simple solution would be to "lock" or prevent other players from accessing the players house without permission or some sort of metaphorical "key". I'm not entirely sure how you're going about this, though.

Another alternative could be to assign a variable to each item that dictates who that object's "owner" is and then prevent other players from picking up that item.
I thought the entire point was to allow other players to steal stuff, not to prevent it
Best response
Ideally, you'd keep track of the House datums in the game with some kind of global list. You'd just give the player a reference to the item in the list. Instead of saving the House with the player you'd just save the list of House datums. Be sure not to save a reference to the mob with the House datum or you'll start running into "rollback" issues, just save a text-only copy of their ckey or something of that sort to keep track of the owner.

var/list/Houses = list()

House
parent_type = /obj
var
owner


mob
Login()
..()
if(Houses.Find(src.ckey))
my_house = Houses[src.ckey]

var/tmp/House/my_house // Prevents saving of this variable, which would also lead to rollbacks.

verb
MakeHouse()
if(!my_house)
my_house = new()
my_house.owner = "[usr.ckey]"
Houses[usr.ckey] = my_house

AddItemToHouse()
if(my_house)
var/obj/item = input("Which item?")as null|anything in usr.contents
if(item) item.Move(my_house)


proc
SaveHouses()
var/savefile/house_save = new("houses.sav")
house_save["houses"] << Houses

LoadHouses()
var/savefile/house_save = new("houses.sav")
if(house_save["houses"]) house_save["houses"] >> Houses


Just wrote this up on the fly, but I'm sure you get the idea and can work up your own system from reading it.
Why use a datum if you're going to parent it as an object?
Yes, the point is to allow users to steal, leave a poisonous snake in the bed etc.

Nadrew's little code example was just what I needed and has put me on the right track.
In response to Falacy (#5)
Because /obj/House isn't as easy to type over and over as /House is, that's one of the primary uses of datums with a parent_type setting.
In response to Nadrew (#7)
Nadrew wrote:
Because /obj/House isn't as easy to type over and over as /House is

Seems like the extra 4 keystrokes would be worth keeping your code standardized/informative/readable...
In response to Falacy (#8)
Falacy wrote:
Seems like the extra 4 keystrokes would be worth keeping your code standardized/informative/readable...

Clearly you've never used another programming language, where forms of the type Nadrew used are much more common, and do not hinder how informative or readable the subclass is at all.