Advertisement
Guest User

The Fix by The Maw

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