A friend and I are modifying the Cider gamemode for private use, and we want to replicate the automatic donations system.
[b]I know this will require the use of a .PHP file to insert the player data into a MySQL database.[/b]
Can somebody please give me an example or show me how to use the Garry's Mod MySQL module to access an [i]external[/i] database (one on my web hosting that I already have purchased) and check whether a player's SteamID is in the database when he first spawns in the server?
It'd also help if someone can tell me how to hook it up so that every time somebody confirms a payment on my website's donation button, it reads the amount of money they donated and what their SteamID is, but that's not necessary for this topic.
Also, can I not get the whole "OMG CIDER? USE DARKRP OR SUMTHIN" thing going on in here? Almost every time something like that gets posted the thread gets turned into a flame war and the OP never gets the help they need.
[lua]
-- Use this to connect..
function ConnectToMysql()
venus, con1, err1 = mysql.connect(Host, User, Password, Database)
if( venus == 0 ) then
print(tostring(err1))
else
print("MySQL Connection Acquired")
print("Connection logged http://venus-studios.net")
print("<----------------------->")
print("vAdmin Connection file succsessfull")
end
end
[/lua]
That's what i use so you may want to change the "prints"
[release]
This script saves the following information:
SteamID
Nickname(ingame name)
Date they FIRST spawned in the server
Date they Last joined the the server. (Updates every initial spawn or first spawn doesn't update if they're respawning from a death.)
This script also sets everyone as disconnected after the dedicated starts up so if the server crashes when you start it up again everyone is marked as offline. (also works with listen servers.)
Only lines you will need to modify are the following:
Lines 5 and 14 - Connection info
Lines 7,17,24, and 23 - change the table name iota to whatever the table name you want to use.
[/release]
[lua]
function MySQLload()
Msg("////////////////////////////////////////////////////\n")
Msg("/// MySQL Script Loaded ///\n")
Msg("////////////////////////////////////////////////////\n")
local db, error = mysql.connect("SERVER", "USERNAME", "PASSWORD", "DATABASE")
if (db == 0) then print(tostring(error) .. "\n") return end
mysqlstarta = mysql.query(db, "UPDATE iota SET ONLINE = 0;")
local succ2, error = mysql.disconnect(db)
if (not succ2) then Msg( error .. "\n" ) end
Msg("/// All players marked as offline. ///\n")
Msg("////////////////////////////////////////////////////\n")
end
function MySQLSpawn(ply)
local db, error = mysql.connect("SERVER", "USERNAME", "PASSWORD", "DATABASE")
if (db == 0) then print(tostring(error) .. "\n") return end
query22 = mysql.query(db, "SELECT count(*) FROM iota WHERE ID2 = '" .. ply:SteamID() .. "';");
if(tonumber(query22[1][1]) == 0) then
steamid = ply:SteamID()
name = ply:Nick()
joined1 = os.date("%m/%d/%y")
print("\nAttempting to insert into SQL\n\n");
query33 = mysql.query(db, "INSERT INTO iota (ID2,name,j1,lastlogin1) VALUES('" .. steamid .. "','" .. name .. "','" .. joined1 .. "','" .. joined1 .. "');");
print("Added Player:\n\nDate: " .. joined1 .. "\nNick: ".. name .. "\nSteamID: " .. steamid .. "\n\nTo the database.\n\n");
end
if(tonumber(query22[1][1]) == 1) then
steamid = ply:SteamID()
name = ply:Nick()
joined1 = os.date("%m/%d/%y")
print("Updating " .. name .. "'s Profile.");
query33 = mysql.query(db, "UPDATE iota SET lastlogin1 = '" .. joined1 .. "' WHERE ID2 = '" .. ply:SteamID() .. "';");
end
local succ2, error = mysql.disconnect(db)
if (not succ2) then Msg( error .. "\n" ) end
end
hook.Add( "PlayerInitialSpawn", "MySQLSpawn", MySQLSpawn )
hook.Add( "InitPostEntity", "MySQLload", MySQLload )[/lua]
If you searched the thread, You could have found alot.
Sorry, you need to Log In to post a reply to this thread.