ID:138949
 
Code:
obj/ForSale
name = "For Sale Sign"
icon = 'HouseSign.dmi'
density = 0
layer = HOUSE_LAYER
var
Waiting = 0
verb
Buy_House()
set src in oview(1)
set category = "House"
var/mob/player/P = usr
if(src.Waiting)
return
if(P.HasHouse)
P << "<b>You already own a house."
return
else
src.Waiting = 1
P.loc = locate(P.x,P.y-1,P.z)
P.oLoc = P.loc
var/swapmap/House = SwapMaps_CreateFromTemplate("House")
sleep(10)
House.SetID("files/House_[P.ckey][P.SaveSlot]")
House.Save()
var/turf/T = locate(House.x1+11,House.y1+1,House.z1)
P.loc = locate(P.x,P.y-2,P.z)
P.loc = T
P.HasHouse = 1
var/obj/PlayerHouse/B4/PH = new/obj/PlayerHouse/B4(src.loc)
PH.Owner = P
PH.name = "[P]'s House"
PH.Loaded = 1
src.Waiting = 0
del(src)

mob
player
Bump(A)
..()
if(istype(A,/obj/PlayerHouse/B4))
var/obj/PlayerHouse/B4/D = A
var/mob/player/P = src
var/swapmap/Found
if(D.Owner == P && P.HasHouse)
if(!D.Loaded)
Found = SwapMaps_Load("files/House_[P.ckey][P.SaveSlot]")
D.Loaded = 1
else
Found = SwapMaps_Find("files/House_[P.ckey][P.SaveSlot]")
if(Found)
var/turf/T = locate(Found.x1+11,Found.y1+1,Found.z1)
P.oLoc = P.loc
P.loc = T
else
P << "<b>You do not own this house."


Problem description: Creating the house and then entering it works fine, but if you relog it doesn't let you back into the house. Am I handling the loading incorrectly? I'm not quite sure what's going wrong. Any insight would be helpful.

The problem is the owner var. You set the house's owner by their mob, not by their key. When you logged in again you were using a different mob. The house no longer has an owner because that mob got deleted.
In response to Lummox JR
Lummox JR wrote:
The problem is the owner var. You set the house's owner by their mob, not by their key. When you logged in again you were using a different mob. The house no longer has an owner because that mob got deleted.

Yeah, but even if I manually reset the Owner variable to a reference when they log back on, it still doesn't work...

...
PH.Owner = "[P.ckey][P.SaveSlot]"

...

if(D.Owner == "[P.ckey][P.SaveSlot]" && P.HasHouse)


Changed, tested, still doesn't work.
In response to Unwanted4Murder
If you're relying on the old saved value, there's your problem. After your mob logs in, the ckey will be taken away from the mob that was saved in the savefile. (This is another reason not to have used the mob as the owner--it means your houses' savefiles are going to cause rollback problems.) You need to alter those savefiles to make the change properly, or delete them outright.
In response to Lummox JR
Lummox JR wrote:
If you're relying on the old saved value, there's your problem. After your mob logs in, the ckey will be taken away from the mob that was saved in the savefile. (This is another reason not to have used the mob as the owner--it means your houses' savefiles are going to cause rollback problems.) You need to alter those savefiles to make the change properly, or delete them outright.

No, I tested it on a key that had never tried to purchase a house before and it still didn't work... and then when I relogged after purchasing the house, it made my screen weird, with like a black bar over the top portion of my screen.

If you're interested in seeing the issue in action: byond://71.58.124.3:327
In response to Unwanted4Murder
The black bar I can't really tell you much about (I can't test the game out myself right now), but it sounds like a rogue HUD element or perhaps part of your interface.

As for the key not working, that has to be something in the logic of the routine. I recommend putting some debugging info into the routine when you try to enter the house, so it shows you the house's key and the key you're comparing it to. That should give you an idea where things are going wrong.
In response to Lummox JR
I don't think the blackness is an interface issue... it's almost as if my view got changed, somehow, and it doesn't even take me to the login screen when I get back on.

mob
player
Bump(A)
..()
if(istype(A,/obj/PlayerHouse/B4))
var/obj/PlayerHouse/B4/D = A
var/mob/player/P = src
var/swapmap/Found
world << "[P.ckey][P.SaveSlot]"
if(D.Owner == "[P.ckey][P.SaveSlot]" && P.HasHouse)
if(!D.Loaded)
world << "[D] hasn't loaded the swapmap."
Found = SwapMaps_Load("files/House_[P.ckey][P.SaveSlot]")
D.Loaded = 1
else
world << "[D] has loaded the swapmap."
Found = SwapMaps_Find("files/House_[P.ckey][P.SaveSlot]")
if(Found)
world << "It should be loaded."
var/turf/T = locate(Found.x1+11,Found.y1+1,Found.z1)
world << "It placed the turf."
P.oLoc = P.loc
P.loc = T
world << "Your location should be changed."
else
P << "<b>You do not own this house."


unwanted4murder1
Robert's House has loaded the swapmap.

But it doesn't go any further than that. So obviously my ckey and SaveSlot match the house's owner since it goes to if(!D.Loaded), but it doesn't let me in. I'm getting really confused. :/
In response to Unwanted4Murder
The fact that you're not taken to the login screen screams of a rollback issue. I think your mob ended up in the savefile.
In response to Lummox JR
But how? If I do "[P.ckey][P.SaveSlot]" it should save as a text string since it's not a direct reference to any specific mob, shouldn't it? The only other place that references the house is in the logout script:

if(P.HasHouse)
if(fexists("map_files/House_[P.ckey][P.SaveSlot].sav"))
var/swapmap/House = SwapMaps_Find("files/House_[P.ckey][P.SaveSlot]")
House.Unload()
for(var/obj/PlayerHouse/B4/D in world)
if(D.Owner == "[P.ckey][P.SaveSlot]")
D.Loaded = 0