How to set a class select system up?

Hello everyone!

I’ve already built a menu that makes players able to select the class they want to spawn with.
I was wondering if any of you had great tips / ideas on which way is the best to do that.

I was thinking of retrieving a table from the dabatase which contains the lane of each players’ steam ID that contains values like (1,0,0,1,1,0,1,0) (1 = purchased ; 0 = not purchased).
The gamemode would check the player’s ID line and then let’s say that the first value is the first class. If it returns 1 for the first value, the gamemode would know that this player owns the class and allows him to spawn with it.

What do you guys think of this method?

Wait… but choosing a class doesn’t change or add anything to the player’s steam ID… what do you mean?

[editline]11th February 2016[/editline]

Oh, right, misread, sorry

[editline]11th February 2016[/editline]

That sounds like a pretty good method to me… but someone will probably post a better method

That’s also what I thought! Maybe are there any better method that are very efficiant and I’m currently unaware of!

Your idea is really good, one suggestion:

Assuming the number of class don’t exceed 64.
If you want to optimise the space of your database, you should store one big integer and play with bitwise operation on it.

I think in Lua, the size of an int is 64 (correct me if I’m wrong).

In your code, you can do something like this:
[lua]
CLASS_1 = 1
CLASS_2 = 2
CLASS_3 = 4
CLASS_4 = 8
etc…

function AsPurchased(databaseIntStored, class)
return (bit.band(databaseIntStored, class) > 0)
end
[/lua]

edit:

for example: for player x, the data in your database is 9.
9 corresponding at 00001001 in binary.
From right to left:
Bit 1 corresponding to CLASS_1.
Bit 4 corresponding to CLASS_4.

This is looking a bit complicated tho! I’ve got unlimited database’s space anyways so I think it won’t matter! I’m gonna try to write that down today, will update with what’s going on!