Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Initialize()
- table_exists()
- end
- function sql_value_name
- unique_id = sql.QueryValue( "SELECT unique_id FROM setname WHERE unique_id = '"..steamID.."'" )
- name = sql.QueryValue("SELECT name FROM setname WHERE unique_id = '"..steamID.."'")
- ply:SetNWString("unique_id", unique_id)
- ply:SetNWInt("name", name)
- end
- function saveSetName ( ply )
- name = ply:GetNWInt( "name" )
- unique_id = ply:GetNWString( "SteamID" )
- sql.Query( "UPDATE setname SET name = "..name.." WHERE unique_id = "..unique_id.."'" )
- ply:ChatPring( "Name '"..name.."' restored!" )
- end
- function tables_exist()
- if (sql.TableExists("setname")) then
- return 0
- else
- if (!sql.TableExists("setname")) then // ! = not
- query = "CREATE TABLE setname ( unique_id varchar(255), name )"
- result = sql.Query(query)
- Msg( "Succes! 'Table setname' created! \n" )
- else
- Msg("Someting went wrong with the 'setname' query! \n")
- Msg( sql.LastError( result ) .. "\n")
- end
- end
- end
- function new_player( SteamID, ply )
- steamID = SteamID
- sql.Query( "INSERT INTO setname ( 'unique_id', 'name' )VALUES ('"..steamID.."', '100')" )
- result = sql.Query( "SELECT uniaue_id, name FROM setname WHERE unique_id - '"..steamID.."'" )
- if (result) then
- sql.Query( "INSERT INTO setname ('unique_id', 'name' )VALUES ('"..steamID.."', '1', '1', '1')" )
- if (result) then
- Msg( "Player account created!\n")
- sql_value_name( ply )
- else
- Msg( "Something went wrong with creating a players info!" )
- end
- end
- function player_exists( ply )
- steamID = ply:GetNWString( "SteamID" )
- result = sql.Query( "SELECT unique_id, name FROM setname WHERE unique_id = '"..steamID.."'" )
- if (result) then
- sql_value_name( ply )
- else
- new_player( steamID, ply )
- end
- end
- function playerInitialSpawn( ply )
- timer.Create( "Steam_id_delay", 1, 1, function(
- SteamID = ply:SteamID()
- ply:SetNWString( "SteamID", SteamID )
- timer.Create( "SaveStat", 10, 0, function() saveStat( ply ) end)
- player_exists( ply )
- end)
- end
- hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawn", PlayerInitialSpawn )
- hook.Add( "Initialize", "Initialize", Initialize )
- hook.Add( "PlayerSay", "CommandIdent", functoin( ply, text, team)
- local SetName = string.Explode( " ", text )
- if( SetName[1] == "!setname" ) then
- if( tonumber( SetName[2] ) ) then
- ply:Nick( tonumber(SetName[2]) )
- name = ply:GetNWInt( "name" )
- unique_id = ply:GetNWString( "SteamID" )
- sql.Query( "UPDATE setname SET name = "..name.." WHERE unique_id = "..unique_id.."'" )
- ply:ChatPring( "Name '"..name.."' restored!" )
- print( ply:Nick() .. " set their name to " .. SetName[2] )
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement