Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.83 KB | None | 0 0
  1.  
  2. DATABASE_HOST = "localhost"
  3. DATABASE_PORT = 3306
  4. DATABASE_NAME = "DarkRP"
  5. DATABASE_USERNAME = "root"
  6. DATABASE_PASSWORD = ""
  7.  
  8. local MySQLOO = require("mysqloo")
  9.  
  10. DB_AUGMENTS = mysqloo.connect ( DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, DATABASE_PORT )
  11.  
  12. local function InitializeMySQL()
  13.     MySQLite.tableExists("augmentations", function(bl)
  14.         if not bl then
  15.             MsgC(Color(0,200,0), "[AUGMENTATIONS] SQL table augmentations created.\n" )
  16.             MySQLite.query("CREATE TABLE IF NOT EXISTS augmentations( steamID VARCHAR(50) NOT NULL PRIMARY KEY, thermalvisor INTEGER NOT NULL, infolink INTEGER NOT NULL, hackingai INTEGER NOT NULL, cyberhands INTEGER NOT NULL, cyberfingers INTEGER NOT NULL, supdermalarmor INTEGER NOT NULL, antifireprotection INTEGER NOT NULL, cloak INTEGER NOT NULL, cyberlegs INTEGER NOT NULL)" )                                                          
  17.         end
  18.     end)
  19.     hook.Remove("DatabaseInitialized", "InitAugDB")
  20. end
  21. hook.Add("DatabaseInitialized", "InitAugDB", InitializeMySQL)
  22.  
  23. function ConnectToDatabase()
  24.     print ("[AUGMENTATIONS] Connecting to Database")
  25.    
  26.     DB_AUGMENTS.onConnect = function()
  27.         print("[AUGMENTATIONS] Database Connection Successful!")
  28.     end
  29.     DB_AUGMENTS.onConnectionFailed = function (db, msg)
  30.         print("[AUGMENTATIONS] Connect to Database failed!")
  31.         print(msg)
  32.     end
  33.     DB_AUGMENTS:connect()
  34. end
  35.  
  36. ConnectToDatabase()
  37.  
  38. local function CheckDB()
  39.     if (DB_AUGMENTS:status() != mysqloo.DATABASE_CONNECTED) then
  40.         ConnectToDatabase()
  41.         print("[KARMASYST] Database Connection Restarted")
  42.     end
  43. end
  44. timer.Create( "DB_CHECK", 5, 0, CheckDB)
  45. function SearchDatabase(ply)
  46.     if ply == nil then return end
  47.    
  48.     local query = DB_AUGMENTS:prepare( "SELECT * FROM augmentations WHERE `steamID` = '" .. ply:SteamID() .. "' AND `thermalvisor` = '" .. ply:GetNWInt("thermalvisor") .. "' AND `infolink` = '" .. ply:GetNWInt("datalink") .. "' AND `hackingai` = '" .. ply:GetNWInt("keypadcrackingmodule") .. "' AND `cyberhands` = '" .. ply:GetNWInt("cyberhands") .. "' AND `cyberfingers` = '" .. ply:GetNWInt("cyberfingers") .. "' AND `supdermalarmor` = '" .. ply:GetNWInt("supdermalarmor") .. "' AND `antifireprotection` = '" .. ply:GetNWInt("antifireprotection") .. "' AND `cloak` = '" .. ply:GetNWInt("stels") .. "' AND `cyberlegs` = '" .. ply:GetNWInt("legscyber") .. "';")
  49.     if not query then return end
  50.     query.onData = function(q,d)
  51.         if ( #query:getData() >= 1) then
  52.             ply:ChatPrint( "You are registered in the database as user #" .. tostring( d['id'] ) )
  53.         end
  54.     end
  55.     query.onError = function( db, err )
  56.         print( "[AUGMENTATIONS] (SearchDatabase) - Error: ", err )
  57.     end
  58.     query:wait()
  59.     query:start()
  60. end
  61.  
  62.  
  63. function AddPlayer( steamid, tv, dl, ai, ch, cf, spd, af, st, clegs )
  64.     local query1 = DB_AUGMENTS:prepare( "SELECT * FROM augmentations WHERE `steamID` = '" .. steamid .. "';")
  65.     query1.onSuccess = function()
  66.     if ( #query1:getData() == 0 ) then
  67.         local query = DB_AUGMENTS:query( "INSERT INTO augmentations (`steamID`, `thermalvisor`, `infolink`, `hackingai`, `cyberhands`, `cyberfingers`, `supdermalarmor`, `antifireprotection`, `cloak`, `cyberlegs`) VALUES ('" .. steamid .. "', '" .. tv .. "', '" .. dl .. "', '" .. ai .. "', '" .. ch .. "', '" .. cf .. "', '" .. spd .. "', '" .. af .. "', '" .. st .. "', '" .. clegs .. "');")
  68.         query1.onSuccess = function()
  69.             print( "[AUGMENTATIONS] The new player " .. steamid .. " was logged!" )
  70.         end
  71.         query1.onError = function(db, err)
  72.             print("[AUGMENTATIONS] (Add Player) - Error: ", err )
  73.         end
  74.         query:start()
  75.     end
  76.     end
  77.     query1:start()
  78.    
  79.    
  80. end
  81.  
  82. hook.Add( "PlayerInitialSpawn", "SyncAugDB", function( ply )
  83.     AddPlayer( ply:SteamID(), ply:GetNWInt("thermalvisor"), ply:GetNWInt("datalink"), ply:GetNWInt("keypadcrackingmodule"), ply:GetNWInt("cyberhands"), ply:GetNWInt("cyberfingers"), ply:GetNWInt("supdermalarmor"), ply:GetNWInt("antifireprotection"), ply:GetNWInt("stels"), ply:GetNWInt("legscyber") )
  84.    
  85.     local q = DB_AUGMENTS:prepare( "SELECT * FROM augmentations WHERE `steamID` = '" .. ply:SteamID() .. "';")
  86.     q:start()
  87.         q.onSuccess = function(q, data)
  88.         PrintTable(data)
  89.             ply:SetNWInt("antifireprotection", data[1].antifireprotection)         
  90.             ply:SetNWInt("cloak", data[1].cloak)           
  91.             ply:SetNWInt("cyberfingers", data[1].cyberfingers)         
  92.             ply:SetNWInt("cyberhands", data[1].cyberhands)         
  93.             ply:SetNWInt("legscyber", data[1].cyberlegs)           
  94.             ply:SetNWInt("hackingai", data[1].hackingai)           
  95.             ply:SetNWInt("infolink", data[1].infolink)         
  96.             ply:SetNWInt("supdermalarmor", data[1].supdermalarmor)         
  97.             ply:SetNWInt("thermalvisor", data[1].thermalvisor)         
  98.         end
  99.         q.onError = function(db, err)
  100.             print("[AUGMENTATIONS] (Loading Data) - Error: ", err )
  101.         end
  102. end )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement