Advertisement
Guest User

Untitled

a guest
May 2nd, 2010
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. require( "mysql" )
  2.  
  3. local db, error = mysql.connect("74.86.13.144", "thesocia_antid2", "*********", "thesocia_zombie")
  4. if (db == 0) then print(tostring(error) .. "\n") return end
  5.  
  6. print("connection opened - " .. db .. "!\n");
  7. function GetInfo( ply )
  8. local id = mysql.query(db, "SELECT id FROM Players WHERE id = '"..steamID.."'")
  9. local xp = mysql.query(db, "SELECT xp FROM Players WHERE id = '"..steamID.."'")
  10. local rank = mysql.query(db, "SELECT rank FROM Players WHERE id = '"..steamID.."'")
  11. local money = mysql.query(db, "SELECT money FROM Players WHERE id = '"..steamID.."'")
  12. local hp = mysql.query(db, "SELECT hp FROM Players WHERE id = '"..steamID.."'")
  13. local kills = mysql.query(db, "SELECT kills FROM Players WHERE id = '"..steamID.."'")
  14. local priv = mysql.query(db, "SELECT priv FROM Players WHERE id = '"..steamID.."'")
  15.  
  16. ply:SetNWString("id", id)
  17. ply:SetNWInt("xp", xp)
  18. ply:SetNWInt("rank", rank)
  19. ply:SetNWInt("money", money)
  20. ply:SetNWInt("hp", hp)
  21. ply:SetNWInt("kills", kills)
  22. ply:SetNWInt("priv", priv)
  23. end
  24. function save( ply )
  25. local id = ply:GetNWString("id")
  26. local xp = ply:GetNWInt("xp")
  27. local rank = ply:GetNWInt("rank")
  28. local money = ply:GetNWInt("money")
  29. local hp = ply:GetNWInt("hp")
  30. local kills = ply:GetNWInt("kills")
  31. local priv = ply:GetNWInt("priv")
  32. local test = mysql.query(db, "UPDATE Players SET xp = "..xp..", rank = "..rank..", money = "..money..", hp = "..hp..", kills = "..kills..", priv = "..priv.." WHERE id = '"..id.."'")
  33. ply:ChatPrint("Player Saved")
  34. end
  35. function NewPly( SteamID, ply )
  36. local steamID = SteamID
  37.  
  38. local NewPlayerInsert = mysql.query(db, "INSERT INTO Players (`id`, `xp`, `rank`, `money`, `hp`, `kills`, `priv`)VALUES ('"..steamID.."', '0', '0', '0', '100', '0', '0')");
  39. if (NewPlayerInsert) then
  40. print("Player Inserted");
  41. end
  42.  
  43. end
  44. function exists( ply )
  45. steamID = ply:GetNWString("SteamID")
  46. --[[
  47. result, isok, error = mysql.query(db, "SELECT id, xp, rank, hp, kills, priv FROM Players WHERE id = '"..steamID.."'")
  48. if (result) then
  49. GetInfo( ply )
  50. else
  51. NewPly( steamID, ply )
  52. end
  53. --]]
  54. local result = mysql.query(db, "SELECT count(*) FROM Players WHERE id = '"..steamID.."'")
  55. if(tonumber(result[1][1]) == 0) then
  56. NewPly( steamID, ply )
  57. else
  58. GetInfo( ply )
  59. ply:ChatPrint("Character Loaded")
  60. end
  61. end
  62. function PlyInitSpawn( ply )
  63. timer.Create("Steam_id_delay", 1, 1, function()
  64. SteamID = ply:SteamID()
  65. ply:SetNWString("SteamID", SteamID)
  66. timer.Create("SaveInfo", 10, 0, function() save( ply ) end)
  67. exists( ply )
  68. end)
  69. end
  70. hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawn", PlyInitSpawn )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement