Jump to content

[HELP] How to add this function to the played time script?


Tokio

Recommended Posts

i have this played time script:

Spoiler

exports.scoreboard:addScoreboardColumn('Játszott idő')

local t = { }
 
function checkValues( source,arg1,arg2)
    if (arg2 >= 60) then
        t[ source ][ 'min' ] = tonumber( t[ source ][ 'min' ] or 0 ) + 1
        t[ source ][ 'sec' ] = 0
    end
    if (arg1 >= 60) then
        t[ source ][ 'min' ] = 0
        t[ source ][ 'hours' ] = tonumber( t[ source ][ 'hours' ] or 0 ) + 1
    end
    return arg1, arg2
end
     
setTimer(
    function( )
        for _, v in pairs( getElementsByType( "player" ) ) do
            if (not t[ v ]) then
                t[ v ] = {
                            ["hours"] = 0,
                             ["min"] = 0,
                             ["sec"] = 0
                            }
            end
 
            t[ v ][ 'sec' ] = tonumber( t[ v ][ 'sec' ] or 0 ) + 1
            local min,sec = checkValues (
                    v,
                    t[ v ][ 'min' ] or 0,
                    t[ v ][ 'sec' ] or 0
						)  
	local hours = tonumber( t[ v ][ 'hours' ] or 0 )

            setElementData(
                v,
                "Játszott idő",
				tostring( hours )..' óra '..tostring( min )..' perc'
            )
        end
    end,
    1000, 0
)
   
function onPlayerQuit ( )
    local playeraccount = getPlayerAccount ( source )
    if ( playeraccount ) and not isGuestAccount ( playeraccount ) then
        local sValue = getElementData( source,'Játszott idő' )
	local hours = tonumber( t[ source ][ 'hours' ] or 0 )
	local min = tonumber( t[ source ][ 'min' ] or 0 )
	local sec = tonumber( t[ source ][ 'sec' ] or 0 )
        setAccountData ( playeraccount, "Játszott idő-hours", tostring(hours) )
        setAccountData ( playeraccount, "Játszott idő-min", tostring(min) )
        setAccountData ( playeraccount, "Játszott idő-sec", tostring(sec) )
        setAccountData ( playeraccount, "Játszott idő", tostring(sValue) )

    end
    t[ source ] = nil
end
 
function onPlayerLogin (_, playeraccount )
    if ( playeraccount ) then
        local time = getAccountData ( playeraccount, "Játszott idő" )
	local hou = getAccountData ( playeraccount, "Játszott idő-hours")
	local min = getAccountData ( playeraccount, "Játszott idő-min")
	local sec = getAccountData ( playeraccount, "Játszott idő-sec")
        if ( time ) then
            setElementData ( source, "Játszott idő", time )

                             t[ source ]["hours"] = tonumber(hou)
                             t[ source ]["min"] = tonumber(min)
                             t[ source ]["sec"] = tonumber(sec)
                else
            setElementData ( source, "Játszott idő",0 )
            setAccountData ( playeraccount, "Játszott idő",0 )
        end
    end
end
addEventHandler ( "onPlayerQuit", root, onPlayerQuit )
addEventHandler ( "onPlayerLogin", root, onPlayerLogin )

 

and i want add to this a command, which the admins can add more hours for anyone, how to make this command?? :S 

Link to comment
3 hours ago, dex. said:

getTickCount -- use this to calculate how much time he spent.(it's in milliseconds) 

https://wiki.multitheftauto.com/wiki/onPlayerJoin -- start tick count when a player joins

https://wiki.multitheftauto.com/wiki/onPlayerQuit -- end tick count when he quits

man, its worng ..
 

 

On 10/23/2017 at 15:11, 50cent said:

and i want add to this a command, which the admins can add more hours for anyone, how to make this command?? :S 

addEventHandler ( 'giveHours', function ( player, cmd, hours ) 
   	local accPlayer = getPlayerAccount ( player )
	if isGuestAccount ( accPlayer ) then
		return
	end
	if not isObjectInACLGroup ("user."..getAccountName ( accPlayer ), aclGetGroup ( "Admin" ) ) then
		return
	end
	for index, players in ipairs ( getElementsByType ( 'player' ) ) do
		local data = getElementData ( players, "Játszott idő" )
		local time = split ( data, ':' )
		local hour, min, sec = time[1] + hours, time[2], time[3]
		setElementData ( players,"Játszott idő", hour..':'..min..':'..sec )
	end
end )

and replace lines 37 - 41 to
  

 setElementData(
                v,
                "Játszott idő",
				tostring( hours )..':'..tostring( min )..':'..tostring( sec )
            )

 

Link to comment
22 hours ago, iMr.WiFi..! said:

man, its worng ..
 

 


addEventHandler ( 'giveHours', function ( player, cmd, hours ) 
   	local accPlayer = getPlayerAccount ( player )
	if isGuestAccount ( accPlayer ) then
		return
	end
	if not isObjectInACLGroup ("user."..getAccountName ( accPlayer ), aclGetGroup ( "Admin" ) ) then
		return
	end
	for index, players in ipairs ( getElementsByType ( 'player' ) ) do
		local data = getElementData ( players, "Játszott idő" )
		local time = split ( data, ':' )
		local hour, min, sec = time[1] + hours, time[2], time[3]
		setElementData ( players,"Játszott idő", hour..':'..min..':'..sec )
	end
end )

and replace lines 37 - 41 to
  


 setElementData(
                v,
                "Játszott idő",
				tostring( hours )..':'..tostring( min )..':'..tostring( sec )
            )

 

does not working :S 

"playedtime.luaa:94: attempt to perform arithmetic on global 'hours' (a nil value)" 

Link to comment
6 minutes ago, iMr.WiFi..! said:

that command will give all a hours to use it write next on f8 :
giveHours 5

- that means will give all 5 hours

i know, but does not working the cmd :S 

and I would like that the cmd just give it to me hours :/ 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...