Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require( "mysql" )
- local db, error = mysql.connect("74.86.13.144", "thesocia_antid2", "*********", "thesocia_zombie")
- if (db == 0) then print(tostring(error) .. "\n") return end
- print("connection opened - " .. db .. "!\n");
- function GetInfo( ply )
- local id = mysql.query(db, "SELECT id FROM Players WHERE id = '"..steamID.."'")
- local xp = mysql.query(db, "SELECT xp FROM Players WHERE id = '"..steamID.."'")
- local rank = mysql.query(db, "SELECT rank FROM Players WHERE id = '"..steamID.."'")
- local money = mysql.query(db, "SELECT money FROM Players WHERE id = '"..steamID.."'")
- local hp = mysql.query(db, "SELECT hp FROM Players WHERE id = '"..steamID.."'")
- local kills = mysql.query(db, "SELECT kills FROM Players WHERE id = '"..steamID.."'")
- local priv = mysql.query(db, "SELECT priv FROM Players WHERE id = '"..steamID.."'")
- ply:SetNWString("id", id)
- ply:SetNWInt("xp", xp)
- ply:SetNWInt("rank", rank)
- ply:SetNWInt("money", money)
- ply:SetNWInt("hp", hp)
- ply:SetNWInt("kills", kills)
- ply:SetNWInt("priv", priv)
- end
- function save( ply )
- local id = ply:GetNWString("id")
- local xp = ply:GetNWInt("xp")
- local rank = ply:GetNWInt("rank")
- local money = ply:GetNWInt("money")
- local hp = ply:GetNWInt("hp")
- local kills = ply:GetNWInt("kills")
- local priv = ply:GetNWInt("priv")
- local test = mysql.query(db, "UPDATE Players SET xp = "..xp..", rank = "..rank..", money = "..money..", hp = "..hp..", kills = "..kills..", priv = "..priv.." WHERE id = '"..id.."'")
- ply:ChatPrint("Player Saved")
- end
- function NewPly( SteamID, ply )
- local steamID = SteamID
- local NewPlayerInsert = mysql.query(db, "INSERT INTO Players (`id`, `xp`, `rank`, `money`, `hp`, `kills`, `priv`)VALUES ('"..steamID.."', '0', '0', '0', '100', '0', '0')");
- if (NewPlayerInsert) then
- print("Player Inserted");
- end
- end
- function exists( ply )
- steamID = ply:GetNWString("SteamID")
- --[[
- result, isok, error = mysql.query(db, "SELECT id, xp, rank, hp, kills, priv FROM Players WHERE id = '"..steamID.."'")
- if (result) then
- GetInfo( ply )
- else
- NewPly( steamID, ply )
- end
- --]]
- local result = mysql.query(db, "SELECT count(*) FROM Players WHERE id = '"..steamID.."'")
- if(tonumber(result[1][1]) == 0) then
- NewPly( steamID, ply )
- else
- GetInfo( ply )
- ply:ChatPrint("Character Loaded")
- end
- end
- function PlyInitSpawn( ply )
- timer.Create("Steam_id_delay", 1, 1, function()
- SteamID = ply:SteamID()
- ply:SetNWString("SteamID", SteamID)
- timer.Create("SaveInfo", 10, 0, function() save( ply ) end)
- exists( ply )
- end)
- end
- hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawn", PlyInitSpawn )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement