Weapon Leveling System

I’ve had an idea for a TTT weapon leveling system and I’m not sure how exactly to do it. The weapons would level based on the amount of kills the player has with them and would gain newer modifiers.

The problem is, I was thinking of doing it using tables, but I am not sure if you can concancenate ( is that the right word? ) variables into table names, sort of like you do it in strings :

// In PlayerDeath hook:
LVL…<steamid>[weaponname] = LVL<steamid>[weaponname] + 1
// with <steamid> being replaced by the player’s steam id :
// LVLSTEAM_X:XXXXXXXX[weaponname]

The other way I was thinking of doing it, is using one or multiple files, storing the amounts of kills with each gun, but I’ve never worked with files before, so I am not sure how to do this. Could anyone point me in the right direction?


You need 3 parts to do such a thing.

First, you need to load the information once a player joins.

Second, you need to treat the information (like you just did in a player death hook)

Lastly, you have to save the information once a player leaves/disconnects.

I suggest doing the first and last part first, then doing whatever you want in-game with this information.

Not really understanding op, but from the looks of it, you want to do something similar to this:

Level = { }

– This is just to make sure the table exists in the first place.

if ( Level[ Player:SteamID() ] == nil or type( Level[ Player:SteamID() ] ) ~= “table” ) then

Level[ Player:SteamID() ] = { }


Level[ Player:SteamID() ][ WeaponName ] = Level[ Player:SteamID() ][ WeaponName ] + 1

You should then be able to do something like…

print( Level[ “STEAM_X:X:XXXXXXXX” ][ WeaponName ] )

Where WeaponName is your weapon class, like “weapon_crowbar”

Would the table be global or local? You indexed as global, but I’m not sure about it.

[editline]1st December 2013[/editline]

How would I load and save the information exactly? Just use a table?


Do you need a MySQL database to use PData? I’d personally prefer to avoid it, as I have no experience with MySQL

EDIT: Mark me dumb; reading through the wiki page, it said it saves in a local database.