Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. -- Written by Team Ulysses, http://ulyssesmod.net/
  2. module( "Utime", package.seeall )
  3. if not SERVER then return end
  4.  
  5. utime_welcome = CreateConVar( "utime_welcome", "1", FCVAR_ARCHIVE )
  6.  
  7. if not sql.TableExists( "utime" ) then
  8. sql.Query( "CREATE TABLE IF NOT EXISTS utime ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, player INTEGER NOT NULL, totaltime INTEGER NOT NULL, lastvisit INTEGER NOT NULL );" )
  9. sql.Query( "CREATE INDEX IDX_UTIME_PLAYER ON utime ( player DESC );" )
  10. end
  11.  
  12. function onJoin( ply )
  13. local uid = ply:UniqueID()
  14. local row = sql.QueryRow( "SELECT totaltime, lastvisit FROM utime WHERE player = " .. uid .. ";" )
  15. local time = 0
  16.  
  17. if row then
  18. if utime_welcome:GetBool() then
  19. ULib.tsay( ply, "[UTime]Welcome back " .. ply:Nick() .. ", you last played on this server " .. os.date( "%c", row.lastvisit ) )
  20. end
  21. sql.Query( "UPDATE utime SET lastvisit = " .. os.time() .. " WHERE player = " .. uid .. ";" )
  22. time = row.totaltime
  23. else
  24. if utime_welcome:GetBool() then
  25. ULib.tsay( ply, "[UTime]Welcome to our server " .. ply:Nick() .. "!" )
  26. end
  27. sql.Query( "INSERT into utime ( player, totaltime, lastvisit ) VALUES ( " .. uid .. ", 0, " .. os.time() .. " );" )
  28. end
  29. ply:SetUTime( time )
  30. ply:SetUTimeStart( CurTime() )
  31. end
  32. hook.Add( "PlayerInitialSpawn", "UTimeInitialSpawn", onJoin )
  33.  
  34. function updatePlayer( ply )
  35. sql.Query( "UPDATE utime SET totaltime = " .. math.floor( ply:GetUTimeTotalTime() ) .. " WHERE player = " .. ply:UniqueID() .. ";" )
  36. end
  37. hook.Add( "PlayerDisconnected", "UTimeDisconnect", updatePlayer )
  38.  
  39. function updateAll()
  40. local players = player.GetAll()
  41.  
  42. for _, ply in ipairs( players ) do
  43. if ply and ply:IsConnected() then
  44. updatePlayer( ply )
  45. end
  46. end
  47. end
  48. timer.Create( "UTimeTimer", 67, 0, updateAll )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement