Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.scoreboard:addScoreboardColumn('time')
- function createTables()
- time = executeSQLQuery("CREATE TABLE IF NOT EXISTS time ( playerUser TEXT, playerName TEXT, time TEXT)")
- if ( time == false ) then
- outputDebugString( "*Error Table time" )
- else
- outputDebugString( "*Create/Load Table time" )
- end
- end
- addEventHandler ( "onResourceStart" , resourceRoot, createTables)
- function addDataValue ( player, data, value)
- local user = getAccountName( getPlayerAccount( player ) )
- local selectUser = executeSQLQuery("SELECT * FROM time WHERE playerUser=?", user)
- if #selectUser == 0 then return end
- for _, info in ipairs( selectUser ) do
- if data == "time" then
- local setValue = info.time + value
- executeSQLQuery("UPDATE `time` SET `time`=? WHERE `playerUser`=?", setValue, user)
- end
- end
- refreshNowDatas(player)
- end
- function getDataValue ( player, data)
- local user = getAccountName( getPlayerAccount( player ) )
- local selectUser = executeSQLQuery("SELECT * FROM time WHERE playerUser=?", user)
- if #selectUser == 0 then return end
- for _, info in ipairs( selectUser ) do
- if data == "time" then
- return formatValue(info.time)
- end
- end
- end
- function setDataValue ( player, data, value)
- local user = getAccountName( getPlayerAccount( player ) )
- local selectUser = executeSQLQuery("SELECT * FROM time WHERE playerUser=?", user)
- if #selectUser == 0 then return end
- if data == "time" then
- executeSQLQuery("UPDATE `time` SET `time`=? WHERE `playerUser`=?", value, user)
- end
- refreshNowDatas(player)
- end
- function startDataValue( player)
- if isPlayerLogged(player) then
- local user = getAccountName( getPlayerAccount( player ) )
- local selectUser = executeSQLQuery("SELECT * FROM time WHERE playerUser=?", user)
- if #selectUser == 0 then
- executeSQLQuery("INSERT INTO `time`(`playerUser`,`playerName`,`time`) VALUES(?,?,?)", user, getPlayerName(player),"0","0","0")
- outputDebugString("New Data Added by "..string.gsub(getPlayerName(player), "(#%x%x%x%x%x%x)",""))
- end
- setElementData(player,"playerOnline",getTickCount())
- setColorInLogin(player)
- setDataValue( player, "playerName", getPlayerName(player))
- onRecallTeam( player )
- loginDonator( player )
- --getPlayerTeamStatus( player )
- refreshNowDatas(player)
- end
- end
- local msValues = {
- week = 607800000,
- day = 86400000,
- hour = 3600000,
- minute = 60000,
- }
- function msToTimeString(playedTime)
- if playedTime then
- local weeks = math.floor(playedTime/msValues.week)
- local days = math.floor(playedTime/msValues.day)
- local playedTime = playedTime - (msValues.day*days)
- local hours = math.floor(playedTime/msValues.hour)
- local playedTime = playedTime - (msValues.hour*hours)
- local minutes = math.floor(playedTime/msValues.minute)
- return weeks.." w, "..days.." d, "..hours.." h, "..minutes.." min."
- end
- end
- function formatValue( value)
- return tonumber(string.format("%."..(0).."f",value))
- end
- function getRankingData( player, data )
- local select = executeSQLQuery("SELECT * FROM time ")
- local RankingData = {}
- for _, info in ipairs( select ) do
- local getData = false
- if data == "time" then getData = info.time end
- if info.playerName and getData then
- getData = formatValue(getData)
- table.insert( RankingData,{ name = info.playerName, data = getData})
- end
- table.sort(RankingData,function(a,b) return(tonumber(a.data) or 0 ) > ( tonumber(b.data) or 0 ) end )
- if data == "time" then for i,data in ipairs (RankingData) do data.data = msToTimeString(data.data) end end
- callClientFunction(player,"refreshRanking",RankingData)
- end
- function getPlayerAllData( player , getPlayer)
- local user = getAccountName( getPlayerAccount( getPlayer ) )
- local selectUser = executeSQLQuery("SELECT * FROM time WHERE playerUser=?", user)
- local RankingData = {}
- if #selectUser == 0 then return end
- for _, info in ipairs( selectUser ) do
- local name = info.playerName
- local time = msToTimeString(info.time)
- table.insert( RankingData,{ name, time})
- callClientFunction(player,"refreshPlayerStats",RankingData)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement