Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. local meta = FindMetaTable("Player")
  2. if !meta then return end
  3.  
  4. // By AC²
  5. // No pulic release.
  6. // Made for dP
  7.  
  8. local DATABASE = {}
  9.  
  10.  
  11. // OH NO!
  12. DATABASE.ERROR = {
  13. [1] = "ERROR: Module not found or couldn't initialize!",
  14. [2] = "SUCCESS: Module was found, connecting now.",
  15. [3] = "ERROR: Could not connect to database.",
  16. [4] = "SUCCESS: Connection was made!",
  17. [5] = "ERROR: Error in code, go debug! :D"
  18. }
  19.  
  20. DATABASE.Module = require("tmysql")
  21.  
  22. if DATABASE.Module then
  23. print( DATABASE.ERROR[2] )
  24. else
  25. print( DATABASE.ERROR[1] )
  26. end
  27.  
  28. print("DATABASE: OK!")
  29.  
  30. local HOST = "host here"
  31. local PORT = 3306
  32. local NAME = "name of database here"
  33. local USERNAME = "user name here"
  34. local PASSWORD = "pass"
  35. local DATABASE = "this is the table you're using"
  36. local DEFAULT_CHECKTIME = 1
  37. local DEFAULT_COINS = 100
  38. local DEFAULT_TITLE = "Guest"
  39. local DEFAULT_STATUS = 1
  40.  
  41. tmysql.initialize(HOST, USERNAME, PASSWORD, NAME, PORT, 2, 2);
  42.  
  43. function SaveAccount( pl )
  44. local Name = tmysql.escape( pl:Name() )
  45. local Coins = pl.PlayerData["coins"]
  46. local Title = pl.PlayerData["title"]
  47. local Status = pl.PlayerData["status"]
  48. tmysql.query("UPDATE `" ..DATABASE.. "` SET `name`='" ..Name.. "', `coins`='" ..Coins.. "', `title`='" ..Title.. "', `status`='" ..Status.. "' WHERE `steamid`='" .. pl:SteamID() .. "'");
  49. timer.Simple( 1, function( pl ) LoadAccount( pl ) end, pl )
  50. end
  51.  
  52. function LoadAccount( pl )
  53. if !pl or !IsValid( pl ) then return end
  54. pl.PlayerData = {}
  55. tmysql.query("SELECT `steamid`, `name`, `coins`, `title`, `status`, `admin` FROM `" ..DATABASE.. "` WHERE `steamid`='" ..pl:SteamID().. "'", function (result)
  56. if !pl or !IsValid(pl) then return end
  57. if !result or !result[1] then
  58. NewAccount( pl )
  59. return
  60. end
  61.  
  62. pl.PlayerData["coins"] = result[1][3]
  63. pl.PlayerData["title"] = result[1][4]
  64. pl.PlayerData["status"] = result[1][5]
  65.  
  66. if pl.PlayerData["status"] == "0" then
  67. pl:Kick("Your SteamID is banned!")
  68. end
  69.  
  70. end)
  71. MsgN("Account found for player "..pl:Name().." ("..pl:SteamID()..")("..pl:IPAddress()..")")
  72. timer.Simple( 1, function ( pl ) SendData( pl ) end, pl)
  73. end
  74.  
  75. function NewAccount( pl )
  76. local Name = tmysql.escape( pl:Name() )
  77. tmysql.query("INSERT INTO `" ..DATABASE.. "` (`steamid`, `name`, `password`, `coins`, `title`, `status`,`admin`, `reason` ) VALUES ('" ..pl:SteamID().. "', '" ..Name.. "', '0', '" ..DEFAULT_COINS.. "', '" ..DEFAULT_TITLE.. "', '" ..DEFAULT_STATUS.. "', '0', '0')", function()
  78. if !pl or !IsValid(pl) then return end
  79. LoadAccount( pl )
  80. end)
  81. end
  82.  
  83.  
  84. function LoadAC( pl )
  85. if !pl or !IsValid( pl ) then return end
  86. LoadAccount( pl )
  87. end
  88. hook.Add("PlayerInitialSpawn", "Load", LoadAC)
  89.  
  90. function SaveAC( pl )
  91. if !pl or !IsValid( pl ) then return end
  92. SaveAccount( pl )
  93. end
  94. hook.Add("PlayerDisconnected", "Save", SaveAC)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement