Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. exports.scoreboard:addScoreboardColumn('time')
  2. function createTables()
  3. time = executeSQLQuery("CREATE TABLE IF NOT EXISTS time ( playerUser TEXT, playerName TEXT, time TEXT)")
  4. if ( time == false ) then
  5. outputDebugString( "*Error Table time" )
  6. else
  7. outputDebugString( "*Create/Load Table time" )
  8. end
  9. end
  10. addEventHandler ( "onResourceStart" , resourceRoot, createTables)
  11.  
  12. function addDataValue ( player, data, value)
  13. local user = getAccountName( getPlayerAccount( player ) )
  14. local selectUser = executeSQLQuery("SELECT * FROM time WHERE playerUser=?", user)
  15. if #selectUser == 0 then return end
  16. for _, info in ipairs( selectUser ) do
  17. if data == "time" then
  18. local setValue = info.time + value
  19. executeSQLQuery("UPDATE `time` SET `time`=? WHERE `playerUser`=?", setValue, user)
  20. end
  21. end
  22. refreshNowDatas(player)
  23. end
  24.  
  25. function getDataValue ( player, data)
  26. local user = getAccountName( getPlayerAccount( player ) )
  27. local selectUser = executeSQLQuery("SELECT * FROM time WHERE playerUser=?", user)
  28. if #selectUser == 0 then return end
  29. for _, info in ipairs( selectUser ) do
  30. if data == "time" then
  31. return formatValue(info.time)
  32. end
  33. end
  34. end
  35.  
  36. function setDataValue ( player, data, value)
  37. local user = getAccountName( getPlayerAccount( player ) )
  38. local selectUser = executeSQLQuery("SELECT * FROM time WHERE playerUser=?", user)
  39. if #selectUser == 0 then return end
  40. if data == "time" then
  41. executeSQLQuery("UPDATE `time` SET `time`=? WHERE `playerUser`=?", value, user)
  42. end
  43. refreshNowDatas(player)
  44. end
  45.  
  46. function startDataValue( player)
  47. if isPlayerLogged(player) then
  48. local user = getAccountName( getPlayerAccount( player ) )
  49. local selectUser = executeSQLQuery("SELECT * FROM time WHERE playerUser=?", user)
  50. if #selectUser == 0 then
  51. executeSQLQuery("INSERT INTO `time`(`playerUser`,`playerName`,`time`) VALUES(?,?,?)", user, getPlayerName(player),"0","0","0")
  52. outputDebugString("New Data Added by "..string.gsub(getPlayerName(player), "(#%x%x%x%x%x%x)",""))
  53. end
  54. setElementData(player,"playerOnline",getTickCount())
  55. setColorInLogin(player)
  56. setDataValue( player, "playerName", getPlayerName(player))
  57. onRecallTeam( player )
  58. loginDonator( player )
  59. --getPlayerTeamStatus( player )
  60. refreshNowDatas(player)
  61. end
  62. end
  63.  
  64. local msValues = {
  65. week = 607800000,
  66. day = 86400000,
  67. hour = 3600000,
  68. minute = 60000,
  69. }
  70.  
  71. function msToTimeString(playedTime)
  72. if playedTime then
  73. local weeks = math.floor(playedTime/msValues.week)
  74. local days = math.floor(playedTime/msValues.day)
  75. local playedTime = playedTime - (msValues.day*days)
  76. local hours = math.floor(playedTime/msValues.hour)
  77. local playedTime = playedTime - (msValues.hour*hours)
  78. local minutes = math.floor(playedTime/msValues.minute)
  79. return weeks.." w, "..days.." d, "..hours.." h, "..minutes.." min."
  80. end
  81. end
  82.  
  83. function formatValue( value)
  84. return tonumber(string.format("%."..(0).."f",value))
  85. end
  86.  
  87. function getRankingData( player, data )
  88. local select = executeSQLQuery("SELECT * FROM time ")
  89. local RankingData = {}
  90. for _, info in ipairs( select ) do
  91. local getData = false
  92. if data == "time" then getData = info.time end
  93. if info.playerName and getData then
  94. getData = formatValue(getData)
  95. table.insert( RankingData,{ name = info.playerName, data = getData})
  96. end
  97. table.sort(RankingData,function(a,b) return(tonumber(a.data) or 0 ) > ( tonumber(b.data) or 0 ) end )
  98. if data == "time" then for i,data in ipairs (RankingData) do data.data = msToTimeString(data.data) end end
  99. callClientFunction(player,"refreshRanking",RankingData)
  100. end
  101.  
  102. function getPlayerAllData( player , getPlayer)
  103. local user = getAccountName( getPlayerAccount( getPlayer ) )
  104. local selectUser = executeSQLQuery("SELECT * FROM time WHERE playerUser=?", user)
  105. local RankingData = {}
  106. if #selectUser == 0 then return end
  107. for _, info in ipairs( selectUser ) do
  108. local name = info.playerName
  109. local time = msToTimeString(info.time)
  110. table.insert( RankingData,{ name, time})
  111. callClientFunction(player,"refreshPlayerStats",RankingData)
  112. end
  113. end
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement