Housing System

I was wondering how you would make a housing system? Where you go to a NPC, select a house, buy it, and then only you can unlock it. How would you be able to make this?

You’d have to have a map with seperate rooms, probably create brushes around the rooms and then call them in the Lua code, to check if a certain player is allowed in there.

But to let only certain players unlock it, you’d need a door as an entity, and then set the variables for it in the code.

You make a table with houses or appartments and the doors postion in them.

House Table:
    Name = "Funny house"
    Cost = 1000
    Doors = {Vector(1,1,1),Vector(2,2,2)}
    Name = "Strange house"
    Cost = 500
    Doors = {Vector(10,10,10)}

I dont know exacly how the table layout looks with “Doors =” but you get the idea.

Then when the player buys it you search trow all doors and check the cords of it. If it matches the house you buy then it adds you to the owner.

Door positions? Bad idea. To uniquely identify an entity such as a door use it’s entity ID - MaxPlayers()

To refer to it use that same number + MaxPlayers().

Nevermind the MaxPlayers() part if you’re never going to change the number of player slots.

The way I would do it is three tables.

[lua]local DoorName = {}
DoorName[1] = (‘Funny House’)
DoorName[2] = (‘Strange House’)
DoorName[3] = (‘Devil House’)
DoorName[4] = (‘Yurimans House’)

local DoorCost = {}
DoorCost[1] = (‘1000’)
DoorCost[2] = (‘500’)
DoorCost[3] = (‘7000’)
DoorCost[4] = (‘2’)

local DoorPos = {}
DoorPos[1] = (Vector(2,2,2))
DoorPos[2] = (Vector(10,10,10))
DoorPos[3] = (Vector(6,6,6))
DoorPos[4] = (Vector(-50, -50, -60))

And then call them in the setup of the entity :3:

It’s seemplez

@LuckyLuke Well then you cant have more than one door.
Read what the man sais.
Off-Topic: thanks for taking 2$ for my house lol

@Crazy Quebec the uniqely id for entities on map load is different for each server so cords is best since they dont change.

Well actualy, the way I set the tables, you should be able to select individual values from those tables… or was I misinformed on it?

Well since you used 3 tables instead of using 1 2d table i understood it as DoorName[1] = (‘Funny House’) , DoorCost[1] = (‘1000’) , DoorPos[1] = (Vector(2,2,2)) is one house.

A vector is uselessly large, and the Entity ID changing is fixed by removing MaxPlayers() when saving and adding MaxPlayers() when loading. The entity index differs because different servers have a different amount of entity indexes reserved for players.

It’s also way easier to refer to an entity by it’s index then by it’s position, you’d need to loop through all door entities to find out which one is which.

ehm can you show a example?

Vectors are one of the easiest way’s to create a door system.

[lua]local Doors = {}
local NAME, COST = 1, 2

local function SaveDoorInfo(door)
Doors[door:EntIndex() - MaxPlayers()] = {door.Name,door.Cost}

local function LoadDoorInfo(door)
local index = door:EntIndex() + MaxPlayers()
door.Name = Doors[index][NAME]
door.Cost = Doors[index][COST]

Something like that?


Easy, but wasteful, inefficient and counter-intuitive.