Saving multiple different house designs

#1

I have a save/load system which saves and loads a players house when they join/leave, etc. Now I’m trying to work on enabling players to have multiple houses saved, so they can load between different houses.

What I had origianlly was in their data table, I had this

Plot = {
	House = {},
	Purchases = {}
},

Which would store all their house and items they purchased. Now I’m changing that, and insert that table automatically thru code.

So they would have a table like this

DefaultPlot = {
	House = {},
	Purchases = {}
},

automatically, but when they buy a new house, it would create this same table, but call it like

NewHousePlot = {
	House = {},
	Purchases = {}
},

So inside the players data it’d have

DefaultPlot = {
	House = {},
	Purchases = {}
},
NewHousePlot = {
	House = {},
	Purchases = {}
},

And as they buy more houses it’d keep adding more. The question is how I can add this automatically? If they also have a value of ‘House’ which defines what type of house they currently have selected

House = 'Default'

How could I check like,

PlayersData[House .. 'Plot'] -- would this return the 'DefaultPlot' table?
2 Likes
#2

I do not quite understand what you are asking for.

  1. Are you asking how to automatically add new house datum to an existing table every time a plot is purchased?
  2. Are you trying to sort through which house they’re using?
#3

You should use object oriented programming and use a constructor function. I suggest that you keep a table where you insert every house plot, either setting the key to the defaults 1,2,3 etc or to some sort of unique identifier.

Yes it would return the default house, I highly suggest that you add some sort of unique identifier if the player is to have multiple plots. That unique identifier could for example be a name.

#4

So if they have a variable such as House = "HouseType" then you could have their PlayersData table indexed by House. For example:

PlayersData = {}  -- Create the PlayersData table
PlayersData.Plots = {}  -- A table containing all the plots the owner has
PlayersData.Plots["DefaultPlot"] = {
    House = {},
    Purchases = {}
}
PlayersData.Plots["NewHousePlot"] = {
    House = {},
    Purchases = {}
}
PlayersData.Plots["Default"] = {
    House = {},
    Purchases = {}
}

-- This is the equivalent of your House = 'default' example
PlayersData.CurrentHouse = "Default"

-- The following would return the DefaultPlot you gave in your example code
PlayersData.Plots[PlayersData.CurrentHouse]

Then, for buying a new house/plot:

function buyHouse(HouseName)
    PlayersData.Plots[HouseName] = {
        House = {},
        Purchases = {}
    }
end
1 Like