A Lua Code that saves user information to mysql

I would like a lua code that can save:
IP Address
Time on server

And then it would upload to a Mysql DB.

Thanks this will be realy helpful

If you’re paying for it. I’ll do it.

WHAT PAY FOR IT! well for something that just saves players information and uploads to a mysql is nothing compared to the things people make and upload for free. unless its the best lua code ever I don’t think I will be paying for it. Its should be only a simple code. But i am not skilled in lua.

There are about 4 admin mods that already do this.

Find an admin mod that does the exact thing, as thegrb says.

I don’t think any lua coder will take time to write this (Unless he/she is bored?) without getting something for it.
Depending on how much it is you want saved. And if you want it loaded too?

Wrote a basic script, untested but it has the basics down. It does not save your playing time, you will have to write that part yourself; I’m too lazy.

Make the MySQL tables yourself.

Saves the players steamid, ip address, name, and time played to a mysql db.
You will have to write your own method for saving the time played.

DB_HOST = “localhost”
DB_PORT = 3306
DB_NAME = “db”
DB_USER = “user”
DB_PASS = “pass”

tmysql.initialize(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT, 2, 2);

DB_USERTABLE = “gm_users”

local meta = _R.Player

function meta:SetupInfo()
if !self or !IsValid(self) then return end
local nick = tmysql.escape( self:GetName() )
tmysql.query(“INSERT INTO " .. DB_USERTABLE .. " (steamid, ip_address, name, time_played) VALUES (’” … self:SteamID() … “’, '” … self:IPAddress() … “’, '” … nick … “’, ‘0’)”, function()
if !self or !IsValid(self) then return end

function meta:GrabInfo()
tmysql.query(“SELECT steamid, ip_address, name, time_played FROM " .. DB_USERTABLE .. " WHERE steamid=’” … self:SteamID() … “’”, function(Result)
if !self or !IsValid(self) then return end
if !Result or !Result[1] then

	self.LastIP = Result[2]
	self.LastName = Result[3]
	self.TimePlayed = Result[4]


function meta:SaveInfo()
if !self or !IsValid(self) then return end
local nick = tmysql.escape( self:GetName() )
local time_played = self.TimePlayed or 0
tmysql.query(“UPDATE " .. DB_USERTABLE .. " SET ip_address=’” … self:IPAddress() … “’, name=’” … nick … “’, time_played=’” … time_played … “’ WHERE steamid=’” … self:SteamID() … “’”);

function InitializePlayer(ply)
if !ply or !IsValid(ply) then return end
hook.Add(“PlayerInitialSpawn”, “DBInfo”, InitializePlayer)

function DisconnectPlayer(ply)
if !ply or !IsValid(ply) then return end
hook.Add(“PlayerDisconnected”, “DBSave”, DisconnectPlayer)

F**king awesome job thanks heaps. I will test now(unless you have) and what about copyright issues?

[editline]4th February 2011[/editline]

ok works for everything but the playing time but that’s alright