Looking to make a table of sorts

I’m trying to puzzle out how exactly to make a table of player names, and how to add a number to each player when they, say, kill an NPC. The end goal here is to alert them every five kills with something like “playername, you have X kills.” I understand how to alert them, and how to check if they’ve killed something, but its the table thats giving me trouble. Any help would be appreciated.

uhh something like

hook.Add( “DoPlayerDeath”, “derp”, function( _, ply )

if ply:Frags() % 5 == 0 then
	ply:PrintMessage( HUD_PRINTTALK, "You just killed 5 people or something!" )

end )

This I get. The trouble is creating a table to keep track of each players individual kills

Why do you need to do that?

In my case, I’m building a very basic RPG script as a learning piece. I have one working, but as the XP and level are not per player, it is pretty broken.

No I mean why do you think that’s neccessary? The “:Frags()” method already keeps track of how many kills a player has (assuming you’re deriving from the ‘base’ gamemode).

I want to store their level, XP, and name in one place for ease of access

So store their player object then?

Maybe? I’m just getting started here

I haven’t worked with lua or tables in awhile, but something like this might work.

local playershit = {
    {name= "Sasha", kills = 1337, deaths = 0, XP = 9001}, 
    {name= "Oubliette", kills = -99999999999, deaths = 999999999999, XP = 0},

Then just use table.Insert to place in new entries. I think you can also do something like this with the columns if you would prefer this method.

local playershit = {
Oubliette = {kills = -99999999999, deaths = 999999999999, XP = 0}

Access data members in a for loop for my above solution, or access that bottommost piece like this.


[editline]18th July 2013[/editline]

Also I was bored, here’s the for loop you would use to iterate through that table.

for k v in pairs(playershit) do
    if (v.name == "yournamehere") then
        v.kills = 1/0;
        v.deaths = 700;