Advertisement
Guest User

!setname

a guest
Oct 27th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.74 KB | None | 0 0
  1. function Initialize()
  2.     table_exists() 
  3. end
  4.  
  5. function sql_value_name
  6.    
  7.     unique_id = sql.QueryValue( "SELECT unique_id FROM setname WHERE unique_id = '"..steamID.."'" )
  8.     name = sql.QueryValue("SELECT name FROM setname WHERE unique_id = '"..steamID.."'")
  9.    
  10.     ply:SetNWString("unique_id", unique_id)
  11.     ply:SetNWInt("name", name)
  12.    
  13. end
  14.  
  15. function saveSetName ( ply )
  16.  
  17.     name = ply:GetNWInt( "name" )
  18.     unique_id = ply:GetNWString( "SteamID" )
  19.    
  20.     sql.Query( "UPDATE setname SET name = "..name.." WHERE unique_id = "..unique_id.."'" )
  21.     ply:ChatPring( "Name '"..name.."' restored!" )
  22.  
  23. end
  24.  
  25. function tables_exist()
  26.     if (sql.TableExists("setname")) then
  27.         return 0
  28.     else
  29.         if (!sql.TableExists("setname")) then // ! = not
  30.             query = "CREATE TABLE setname ( unique_id varchar(255), name )"
  31.             result = sql.Query(query)
  32.                 Msg( "Succes! 'Table setname' created! \n" )
  33.             else
  34.                 Msg("Someting went wrong with the 'setname' query! \n")
  35.                 Msg( sql.LastError( result ) .. "\n")
  36.         end
  37.     end
  38. end
  39.  
  40. function new_player( SteamID, ply )
  41.  
  42.     steamID = SteamID
  43.    
  44.     sql.Query( "INSERT INTO setname ( 'unique_id', 'name' )VALUES ('"..steamID.."', '100')" )
  45.     result = sql.Query( "SELECT uniaue_id, name FROM setname WHERE unique_id - '"..steamID.."'" )
  46.     if (result) then
  47.        
  48.         sql.Query( "INSERT INTO setname ('unique_id', 'name' )VALUES ('"..steamID.."', '1', '1', '1')" )
  49.         if (result) then
  50.            
  51.             Msg( "Player account created!\n")
  52.             sql_value_name( ply )
  53.     else
  54.         Msg( "Something went wrong with creating a players info!" )
  55.     end
  56.    
  57. end
  58.  
  59. function player_exists( ply )
  60.  
  61.     steamID = ply:GetNWString( "SteamID" )
  62.    
  63.     result = sql.Query( "SELECT unique_id, name FROM setname WHERE unique_id = '"..steamID.."'" )
  64.     if (result) then
  65.         sql_value_name( ply )
  66.     else
  67.         new_player( steamID, ply )
  68.     end
  69.    
  70. end
  71.  
  72. function playerInitialSpawn( ply )
  73.     timer.Create( "Steam_id_delay", 1, 1, function(
  74.        
  75.         SteamID = ply:SteamID()
  76.        
  77.         ply:SetNWString( "SteamID", SteamID )
  78.        
  79.         timer.Create( "SaveStat", 10, 0, function() saveStat( ply ) end)
  80.        
  81.         player_exists( ply )
  82.        
  83.     end)
  84. end
  85.  
  86. hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawn", PlayerInitialSpawn )
  87. hook.Add( "Initialize", "Initialize", Initialize )
  88. hook.Add( "PlayerSay", "CommandIdent", functoin( ply, text, team)
  89.    
  90.     local SetName = string.Explode( " ", text )
  91.  
  92.     if( SetName[1] == "!setname" ) then
  93.        
  94.         if( tonumber( SetName[2] ) ) then
  95.            
  96.             ply:Nick( tonumber(SetName[2]) )
  97.            
  98.             name = ply:GetNWInt( "name" )
  99.             unique_id = ply:GetNWString( "SteamID" )
  100.            
  101.             sql.Query( "UPDATE setname SET name = "..name.." WHERE unique_id = "..unique_id.."'" )
  102.             ply:ChatPring( "Name '"..name.."' restored!" )
  103.            
  104.             print( ply:Nick() .. " set their name to " .. SetName[2] )
  105.        
  106.         end
  107.        
  108.     end
  109.  
  110. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement