Best-Killer1 Posted September 10, 2015 Share Posted September 10, 2015 play time work with hours/days/months but i want it work with hours/minuts example : 240:14 this the cod local pt = { } exports.scoreboard:scoreboardAddColumn ( "Playtime", root, 50 ) addEventHandler ( "onResourceStart", resourceRoot, function ( ) for i, v in pairs ( getElementsByType ( "player" ) ) do pt [ v ] = 0 local x = tonumber ( getElementData ( v, "PlayerFunct:HiddenPTMins" ) ) if ( x ) then pt [ v ] = x end end end ) addEventHandler ( "onResourceStop", resourceRoot, function ( ) for i, v in pairs ( getElementsByType ( "player" ) ) do local x = 0 if ( pt [ v ] ) then x = pt [ v ] end setElementData ( v, "PlayerFunct:HiddenPTMins", x ) end end ) setTimer ( function ( ) for i, v in pairs ( getElementsByType ( "player" ) ) do if ( not pt [ v ] ) then pt [ v ] = 0 end pt [ v ] = pt [ v ] + 1 updatePlayerPlaytime ( v ) end end, 60000, 0 ) function updatePlayerPlaytime ( v) if ( not ( pt [ v ] ) ) then return false end return setElementData ( v, "Playtime", tostring ( convertMinsToActualTime ( pt [ v ] ) ) ) end function deletePlayerPlaytime ( p ) if ( p and pt [ p ] ) then pt [ p ] = nil return true end return false end function setPlayerPlaytime ( p, m ) if ( p and m ) then pt [ p ] = m updatePlayerPlaytime ( p ) return true end return false end function getPlayerPlaytime ( p ) if ( p and pt [ p ] ) then return pt [ p ] end return false end function convertMinsToActualTime ( m ) local hours = 0 local days = 0 local months = 0 while ( m >= 60 ) do m = m - 59 hours = hours + 1 if ( hours >= 24 ) then hours = hours - 23 days = days + 1 if ( days >= 30 ) then days = days - 29 months = months + 1 end end end -- Minutes only if ( hours == 0 and days == 0 and months == 0 ) then return tostring(m).."m" -- Hours and minutes elseif ( hours > 0 and days == 0 and months == 0 ) then return tostring(hours).."h "..tostring(m).."m" -- Days and Hours elseif ( hours > 0 and days > 0 and months == 0 ) then return tostring(days).."d "..tostring(hours).."h" -- Months and Days elseif ( days > 0 and months > 0 ) then return tostring(months).."mon "..tostring(days).."d" end end addCommandHandler ( "playtime", function ( p ) if ( not pt [ p ] ) then pt [ p ] = 0 end exports.NGMessages:sendClientMessage ( "You have a total of "..tostring(pt[p]).." minutes of online-time at SAEG:RPG", p, 0, 255, 0 ) end ) What i need change ? Link to comment
JR10 Posted September 10, 2015 Share Posted September 10, 2015 Replace the convertMinsToActualTime function with this: function convertMinsToActualTime ( m ) local hours = 0 while ( m >= 60 ) do m = m - 60 hours = hours + 1 end -- Minutes only if ( hours == 0 ) then return tostring(m).."m" -- Hours and minutes elseif ( hours > 0 ) then return tostring(hours).."h "..tostring(m).."m" end end Link to comment
Best-Killer1 Posted September 11, 2015 Author Share Posted September 11, 2015 Replace the convertMinsToActualTime function to this: function convertMinsToActualTime ( m ) local hours = 0 while ( m >= 60 ) do m = m - 60 hours = hours + 1 end -- Minutes only if ( hours == 0 ) then return tostring(m).."m" -- Hours and minutes elseif ( hours > 0 ) then return tostring(hours).."h "..tostring(m).."m" end end Thanx <3 Link to comment
Best-Killer1 Posted September 11, 2015 Author Share Posted September 11, 2015 how i can change it to 0:0 example : 210:50 Link to comment
JR10 Posted September 11, 2015 Share Posted September 11, 2015 Line 13 is where the function returns the string if hours exceed one. Change it to: return tostring(hours)..":"..tostring(m) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now