• Problems with Tables
    10 replies, posted
Hello i want to make a Table there will stands the Bans on my server. Name Steamid Clocktime Date _________ My Script looks like: [lua] function lies(ply) for k, v in pairs(player.GetAll()) do BanTable={} BanTable[1]=v:Nick() BanTable[2]=v:SteamID() BanTable[3]=os.date( ) local savestring = util.TableToKeyValues(BanTable) file.Write("bans.txt",savestring) v123 = file.Read("bans.txt") tabelle = util.KeyValuesToTable(v123) PrintTable(tabelle) end end concommand.Add("lies",lies) [/lua] The Get all is just a Test. But the Table get everytime overwritten. I Mean when the table looks like: "Out" { "1" "Bot06" "2" "BOT" "3" "08/07/09 17:12:08" } Then if player: Bot 4 joins the server, BOT06 Gets overwritten with BOT04 How can i change that? And At the Top stands "Out" How can i change that to the name of the Player? Please help me
file.Write does not append the text in the file, it overwrites it.
How can I Change it ? I know some People could think:"Why not Mysql" I could use it, but i want it with Tables ^^. /edit: Should i create more txt files with the Steam Id ? 0:0:1234861.txt or sth?| Ahrg that does not work too -.-
You cant change it.
Is there an another way that could get working? a new txtfile for a new ban does not work too. (With Steamid) Please help me
I had the same problem with my soundstopper, you need to use glon or [url]http://wiki.garrysmod.com/?title=Util.TableToKeyValues[/url] (which is what i went with so i could still read it later) To save it into a file.
[lua] local savestring = util.TableToKeyValues(BanTable) [/lua] I did it already
my bad I overlooked that, Then add the other users to BanTable with table.Add/Merge
Oh, Thanks. Ill take a look at it. Oh².. How can i Change the "Out" with the SteamID ?
[lua]function loadSoundFile() local soundFileTbl = util.KeyValuesToTable( file.Read("aaronsound.txt") ) if soundFileTbl.block then table.Add(soundBlockList, soundFileTbl.block) end if soundFileTbl.show then table.Add(soundShowList, soundFileTbl.show) end end function saveSoundFile() local soundFileTbl = {} soundFileTbl["block"] = {} for k, v in pairs(soundBlockList) do soundFileTbl["block"][k] = v end soundFileTbl["show"] = {} for x, y in pairs(soundShowList) do soundFileTbl["show"][x] = y end file.Write("aaronsound.txt",util.TableToKeyValues( soundFileTbl )) end [/lua] Copy/Pasted out of my sound lua, hope it helps. [editline]03:25PM[/editline] aaronsound.txt [code] "Out" { "show" { "1" "weapons\smg1\smg1_fire1.wav" } "block" { "1" "physics\concrete\concrete_impact_bullet3.wav" "2" "physics\concrete\concrete_impact_bullet4.wav" } } [/code]
Thanks^^
Sorry, you need to Log In to post a reply to this thread.