ID:165562
 
Hello I have a question, in my game I would like so people can buy houses.... well my problem is I want to make it so only that person who buys the house can enter it, I have thought of ways I could do it such as, have a key in your inventory that lets you go in when you click but only when your (1) space away from your door but I am unsure how to create this..


If anyone could help me that would be great :)
*Bump* Sorry about that is there really not anyone that can do this quickly couldn't something with the guild house code be used to make this....


Remember an old Guild house code only guild house members can enter the house is there anyway this could be used to do what I am doing??
In response to Nexus6669
        
obj/House
icon='Whatever.dmi'
icon_state="House"
density=1
opacity=1
var/Owner
verb/Buy()
set src in oview(1)
if(usr.Money>=500)
usr.Money-=500
src.Owner="[usr]"
usr<<"You've bought the house!"
else
usr<<"Not enough money!"
Enter(M)
if(M==src.Owner)
usr<<"Welcome home, [usr]!"
usr.loc=locate(1,1,2)
else
usr<<"Not your house!"

This should work...
In response to Dragon_fire6653
You forgot to mention to nexus he should make something to save the modified variable, a save/load system for houses.

- GhostAnime
In response to GhostAnime
GhostAnime wrote:
You forgot to mention to nexus he should make something to save the modified variable, a save/load system for houses.

- GhostAnime


Well, i'm not exactly the best with saving, in fact, I hardly know how to use the built-in procedures as of now, but i'll give it a try...
mob/var/Owns_House       

obj/House
icon='Whatever.dmi'
icon_state="House"
density=1
opacity=1
var/Owner
verb/Buy()
set src in oview(1)
if(usr.Money>=500)
usr.Money-=500
Write(savefile/F)
src.Owner="[usr]"
usr<<"You've bought the house!"

else
usr<<"Not enough money!"
Enter(M)
if(M=src.Owner)
usr<<"Welcome home, [usr]!"
usr.loc=locate(1,1,2)
else
usr<<"Not your house!"

mob/Login()
if(usr.Owns_House)
Read(savefile/F)
..()

If you see any mistakes, make corrections please...
In response to Dragon_fire6653
No put usr in proc. Told you thousand times. Ungh!

Lummox JR
In response to Lummox JR
In addition to that (usr in Movement procs = even more worse :[), I noticed a lil' more:
            Write(savefile/F)
src.Owner="[usr]"

You need to actually define the savefile (surprise, surprise) and de-indent the owner part... and it may be best to overwrite write() for the obj/house as well
---
mob/Login()
if(usr.Owns_House)
Read(savefile/F)
..()

Again, it needs to be defined (Read() here calls mob.Read(), not obj.Read() as earlier) but in addition to that, IT SHOULD NOT EVEN BE THERE. The logical place to load the saved file is in world/New()
---
   Enter(M)
if(M=src.Owner)
usr<<"Welcome home, [usr]!"
usr.loc=locate(1,1,2)
else
usr<<"Not your house!"

Like what Lummox mentioned: Don't use usr in procs, specifically in those which can cause your game to screw over with unexpected results :P Movement proc's like Bump(), Enter(),Exited(),etc. definately is a no-usr zone.

Not to mention you're checking with if(M=src.Owner)... it's == not =


- GhostAnime
In response to GhostAnime
Ok so is the code ok to use, except the saving of the code because couldn't I just put it with this part of my saving and loading code

mob
proc
Save() //Save proc
var/firstletter=copytext(src.ckey, 1, 2)//define the first letter of the player
var/savefile/F = new("players/[firstletter]/[src.ckey].sav")//makes a save file
F["last_x"] << src.x //stores last X coordinate
F["last_y"] << src.y //stores last Y coordinate
F["last_z"] << src.z //stores last Z coordinate
F["icon"] << src.icon//save there icon
F["Inventory"] << src.contents
Write(F) // Writes the stored files into one


Load() //Load proc
var/firstletter=copytext(src.ckey, 1, 2)
if(fexists("players/[firstletter]/[src.ckey].sav"))
var/savefile/F = new("players/[firstletter]/[src.ckey].sav")
Read(F) //Reads it
F["last_x"] >> src.x //Loads the last X Coordinate
F["last_y"] >> src.y //Loads the last Y Coordinate
F["last_z"] >> src.z //Loads the last Z Coordinate
F["icon"] >> src.icon//load there icon
F["Inventory"] >> src.contents
In response to Nexus6669
Well, your code currently has a problem during the load. You can't load directly to the x/y/z vars. Instead you need to load those values into temporary vars and use locate() to set the location properly. E.g.:
var/lx,ly,lz
F["last_x"] >> lx
F["last_y"] >> ly
F["last_z"] >> lz
loc = locate(lx, ly, lz)


Lummox JR
In response to Lummox JR
I have found a problem with the first part of the code..

I have used it I can buy the house but when i go to walk into the door it just doesn't do anything. once I buy it it says I bought it but but it still comes up with the buy verb and I can keep buying it and I just can't enter it...

Anyone found a way
?
In response to Nexus6669
What the hell is going on here when I bump it up to the top so I can still see if I receive help it goes to the top then goes back to where it was and deletes the message I am creating now... I have bumped it 5 times now and it takes the message out and puts it back...
In response to Nexus6669
Nexus6669 wrote:
What the hell is going on here when I bump it up to the top so I can still see if I receive help it goes to the top then goes back to where it was and deletes the message I am creating now... I have bumped it 5 times now and it takes the message out and puts it back...

I think that's a subtle hint from the moderators not to bump the message. I think the rules are like the last post made must be at least 24 hours old *and* the thread must be off the first page.

The forums aren't a chatroom, and sometimes it takes awhile for someone to read a post and then respond. If the thread's on the first page, there's still a good chance that someone will read it and be able to help. The no-bumping rule has to do with preventing forum clutter.
In response to Jon88
Oh I am really sorry :( I just need help with this... I have tried myself alot and I really want to hurry and get this code done. Is there anyone that can correct or help with the code?