SHARE
TWEET

Untitled

a guest Jun 18th, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // local EVOLVE_RANK_RESPECTED = 1
  3. // local EVOLVE_RANK_DONATOR = 2
  4. // local EVOLVE_RANK_ADMIN = 3
  5. // local EVOLVE_RANK_SUPERADMIN = 4
  6. // local EVOLVE_RANK_OWNER = 5
  7.  
  8. local DATABASE_HOST = "********"
  9. local DATABASE_PORT = "****"
  10. local DATABASE_NAME = "**********""
  11. local DATABASE_USERNAME = "*********"
  12. local DATABASE_PASSWORD = "********"
  13.  
  14.  
  15. function sql_value_stats ( ply )
  16.         unique_id = sql.QueryValue("SELECT unique_id FROM player_info WHERE unique_id = '"..steamID.."'")
  17.         VIPoints = sql.QueryValue("SELECT VIPoints FROM player_info WHERE unique_id = '"..steamID.."'")
  18.         ply:SetNWString("unique_id", unique_id)
  19.         ply:SetNWInt("VIPoints", money)
  20. end
  21. function sql_evolverank ( ply )
  22.         unique_id = sql.QueryValue("SELECT unique_id FROM evolveranks WHERE unique_id = '"..steamID.."'")
  23.         name = sql.QueryValue("SELECT name FROM evolveranks WHERE unique_id = '"..steamID.."'")
  24.         rank = sql.QueryValue("SELECT rank FROM evolveranks WHERE unique_id = '"..steamID.."'")
  25.         ply:SetNWString("unique_id", unique_id)
  26.         ply:SetNWString("name", name)
  27.         ply:SetNWInt("rank", rank )
  28. end
  29.  
  30.  
  31. function saveStat ( ply )
  32.         VIPoints = ply:GetNWInt("VIPoints")
  33.         unique_id = ply:GetNWString("SteamID")
  34.         sql.Query("UPDATE player_info SET VIPoints = "..VIPoints.." WHERE unique_id = '"..unique_id.."')
  35.         ply:ChatPrint("Stats updated !")
  36. end
  37.  
  38.  
  39. function tables_exist()
  40.  
  41.         if (sql.TableExists("vipointstable") && sql.TableExists("player_skills") && sql.TableExists("evolverank") then
  42.                 Msg("Both tables already exist!")
  43.         else
  44.                 if (!sql.TableExists("vipointstable"))
  45.                         query = "CREATE TABLE vipointstable ( unique_id varchar(255), VIPoints int, admins )"
  46.                         result = sql.Query(query)
  47.                         if sql.TableExists("vipointstable")) then
  48.                             Msg("vipointstable has been created! \n")
  49.                         else
  50.                             Msg("vipointstable failed to query! \n")
  51.                             Msg( sql.LastError( result ) .. "\n" )
  52.                         end
  53.                 end
  54.    
  55.                 if (!sql.TableExists("evolverank")) then
  56.                         query = "CREATE TABLE evolveranks ( unique_id varchar(255), name, rank ) "
  57.                         result = sql.Query( query )
  58.                         if sql.TableExists("evolveranks")) then
  59.                                 Msg("Evolveranks table has been created! \n")
  60.                         else
  61.                                 Msg("Evolveranks failed to query! \n")
  62.                                 Msg( sql.LastError( result ) .. "\n")
  63.                                
  64.                         end
  65.  
  66.                 end
  67.         end
  68. end
  69.  
  70. function new_player( SteamID, ply)
  71.  
  72.                 steamID = SteamID
  73.                 sql.Query( "INSERT INTO player_info( `unique_id`, `VIPoints`)VALUES ('"..steamID.."', '100')" )
  74.                 result = sql.Query( "SELECT unique_id, VIPoints FROM player_info WHERE unique_id = '"..steamID.."'" )
  75.                 if (result) then
  76.                        
  77.                         sql.Query( "INSERT INTO player_skills (`unique_id`, `speech`, `fish`, `farm`)VALUES ('"..steamID.."', '1', '1', '1')" )
  78.                         result = sql.Query( "SELECT unique_id, speech, fish, farm FROM player_skills WHERE unique_id = '"..steamID.."'" )
  79.                         if (result) then
  80.                                 Msg("Player account created !\n")
  81.                                 sql_value_stats( ply )
  82.                                 sql_value_skills( ply )
  83.                         else
  84.                                 Msg("Something went wrong with creating a players skills !\n")
  85.                         end
  86.                 else
  87.                         Msg("Something went wrong with creating a players info !\n")
  88.                 end    
  89. end
  90.  
  91. function player_exists( ply )
  92.         steamID = ply:GetNWString("SteamID")
  93.        
  94.         result = sql.Query("SELECT unique_id, VIPoints FROM player_info WHERE unique_id = '"..steamid"'")
  95.         if (result) then
  96.                         sql_value_stats( ply )
  97.                         sql_value_skills( ply )
  98.         else
  99.                 new_player( steamID, ply )
  100.         end
  101. end    
  102.  
  103.  
  104. function Initialize()
  105.         tables_exist()
  106. end
  107.  
  108.  
  109.  
  110. function PlayerInitialSpawn( ply )
  111.  
  112.         timer.Create("Steam_id_delay", 1, 1, function()
  113.                 SteamID = ply:SteamID()
  114.                 ply:SetNWString("SteamID", SteamID)
  115.                 timer.Create("SaveStat", 10, 0, function() saveStat( ply ) end)
  116.                 player_exists( ply )
  117.         end)   
  118. end
  119.  
  120.  
  121. function Set_Player_Status ( ply )
  122.    
  123.     rank = sql.QueryValue("SELECT rank FROM evolveranks WHERE unique_id = '"..steamID.."'")
  124.    
  125.     if rank == "respected" then ply:EV_SetRank ( "respected" )
  126.     if rank == "donator" then ply:EV_SetRank( "donator" )
  127.     if rank == "admin" then ply:EV_SetRank( "admin" )
  128.     if rank == "superadmin" then ply:EV_SetRank( "superadmin" )
  129.     if rank == "owner" then ply:EV_SetRank( "owner" )
  130.    
  131.     end
  132. end
  133.  
  134.  
  135. hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawn", PlayerInitialSpawn )
  136. hook.Add( "Initialize", "Initialize", Initialize )
  137.  
  138. function connectToDatabase()  
  139.   local databaseObject = mysqloo.connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, DATABASE_PORT)  
  140.   databaseObject.onConnected = afterConnected  
  141.   databaseObject:connect()  
  142. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top