Jump to content

server getRealTime() 12h format, need 24h format..


dqlepy

Recommended Posts

    local time = getRealTime()
    local hours = ""..time.hour..":"..time.minute
    local minutes = time.minute;

^^^  - This is an active real-time clock that sits in a box on the top right of the screen, that has zone names depending on player position..

F.I. - Time = 05:17 // in-game = 5:17

I need the 0 in front of the time, but only for the first 9 hours..

I tried this code, but then the whole script doesn't work, and says " undefined " everywhere, I also tried editing, and I can get it to say for instance " 23 " and not the ":" or minutes.

    local time = getRealTime()
    local hours = time.hour
    local minutes = time.minute
-- checks if hours < 10, sets 0 to front
    if (hours < 10) then
        hours = "0"..time.hour
    end
    if (minutes < 10) then
        minutes = "0"..time.minute
    end

Full function code, if that helps, with what I need fixed..

function updateDX( )
    local health = getElementHealth(localPlayer)
    local armour = getPedArmor(localPlayer)
    local hunger = getElementData(localPlayer, configs['Elements']['Fome']) or 0
    local thirst = getElementData(localPlayer, configs['Elements']['Sede']) or 0
    local stress = getElementData(localPlayer, configs['Elements']['Stress']) or 100
    local radio = getElementData(localPlayer, "ae.frequencia") or 0

    local x,y,z = getElementPosition(localPlayer)
    local street = getZoneName ( x, y, z, true )
    local direction = getZoneName ( x, y, z, false )

    local time = getRealTime()
    local hours = ""..time.hour..":"..time.minute
    local minutes = time.minute

    if getPedOccupiedVehicle(localPlayer) then

        fuel = getElementData(getPedOccupiedVehicle(getLocalPlayer()), configs['Elements']['fuel']) or 0
        speed = ( function( x, y, z ) return math.floor( math.sqrt( x*x + y*y + z*z ) * 155 ) end )( getElementVelocity( getPedOccupiedVehicle(localPlayer) ) ) 

end

    SendNUIMessage(browser, { vehicle = vehicle, talking = talking, health = health, armour = armour, thirst = thirst, hunger = hunger, street = street, radio = radio, time = hours, minutes = minutes, direction = direction, voice = voice, speed = speed, fuel = fuel })
end

 

Link to comment
15 hours ago, dqlepy said:
    local time = getRealTime()
    local hours = ""..time.hour..":"..time.minute
    local minutes = time.minute;

^^^  - This is an active real-time clock that sits in a box on the top right of the screen, that has zone names depending on player position..

F.I. - Time = 05:17 // in-game = 5:17

I need the 0 in front of the time, but only for the first 9 hours..

I tried this code, but then the whole script doesn't work, and says " undefined " everywhere, I also tried editing, and I can get it to say for instance " 23 " and not the ":" or minutes.

    local time = getRealTime()
    local hours = time.hour
    local minutes = time.minute
-- checks if hours < 10, sets 0 to front
    if (hours < 10) then
        hours = "0"..time.hour
    end
    if (minutes < 10) then
        minutes = "0"..time.minute
    end

Full function code, if that helps, with what I need fixed..

function updateDX( )
    local health = getElementHealth(localPlayer)
    local armour = getPedArmor(localPlayer)
    local hunger = getElementData(localPlayer, configs['Elements']['Fome']) or 0
    local thirst = getElementData(localPlayer, configs['Elements']['Sede']) or 0
    local stress = getElementData(localPlayer, configs['Elements']['Stress']) or 100
    local radio = getElementData(localPlayer, "ae.frequencia") or 0

    local x,y,z = getElementPosition(localPlayer)
    local street = getZoneName ( x, y, z, true )
    local direction = getZoneName ( x, y, z, false )

    local time = getRealTime()
    local hours = ""..time.hour..":"..time.minute
    local minutes = time.minute

    if getPedOccupiedVehicle(localPlayer) then

        fuel = getElementData(getPedOccupiedVehicle(getLocalPlayer()), configs['Elements']['fuel']) or 0
        speed = ( function( x, y, z ) return math.floor( math.sqrt( x*x + y*y + z*z ) * 155 ) end )( getElementVelocity( getPedOccupiedVehicle(localPlayer) ) ) 

end

    SendNUIMessage(browser, { vehicle = vehicle, talking = talking, health = health, armour = armour, thirst = thirst, hunger = hunger, street = street, radio = radio, time = hours, minutes = minutes, direction = direction, voice = voice, speed = speed, fuel = fuel })
end

 

local time = getRealTime()
local timeString = string.format("%02d:%02d", time.hour, time.minute)

-- OR

local timeString = os.date ("%H:%M")

os.date function

Link to comment
2 hours ago, AngelAlpha said:
local time = getRealTime()
local timeString = string.format("%02d:%02d", time.hour, time.minute)

-- OR

local timeString = os.date ("%H:%M")

os.date function

with the code like this..

    local time = getRealTime()
    local hours = time.hour
    local minutes = time.minute
    local timeString = string.format("%02d:%02d", time.hour, time.minute)

it just says F.I. " 18 "

    local time = getRealTime()
    local hours = ""..time.hour..":"..time.minute
    local minutes = time.minute
    local timeString = string.format("%02d:%02d", time.hour, time.minute)

but with the code like this, it says F.I. " 18:4 "

local timeString = os.date ("%H:%M")

this did also not work.. ^^^

Link to comment
1 hour ago, dqlepy said:

with the code like this..

    local time = getRealTime()
    local hours = time.hour
    local minutes = time.minute
    local timeString = string.format("%02d:%02d", time.hour, time.minute)

it just says F.I. " 18 "

    local time = getRealTime()
    local hours = ""..time.hour..":"..time.minute
    local minutes = time.minute
    local timeString = string.format("%02d:%02d", time.hour, time.minute)

but with the code like this, it says F.I. " 18:4 "

local timeString = os.date ("%H:%M")

this did also not work.. ^^^

function updateDX( )
    local health = getElementHealth(localPlayer)
    local armour = getPedArmor(localPlayer)
    local hunger = getElementData(localPlayer, configs['Elements']['Fome']) or 0
    local thirst = getElementData(localPlayer, configs['Elements']['Sede']) or 0
    local stress = getElementData(localPlayer, configs['Elements']['Stress']) or 100
    local radio = getElementData(localPlayer, "ae.frequencia") or 0

    local x,y,z = getElementPosition(localPlayer)
    local street = getZoneName ( x, y, z, true )
    local direction = getZoneName ( x, y, z, false )

    local time = getRealTime()
    local hours = string.format("%02d:%02d", time.hour, time.minute)
    local minutes = time.minute

    if getPedOccupiedVehicle(localPlayer) then

        fuel = getElementData(getPedOccupiedVehicle(getLocalPlayer()), configs['Elements']['fuel']) or 0
        speed = ( function( x, y, z ) return math.floor( math.sqrt( x*x + y*y + z*z ) * 155 ) end )( getElementVelocity( getPedOccupiedVehicle(localPlayer) ) ) 

end

    SendNUIMessage(browser, { vehicle = vehicle, talking = talking, health = health, armour = armour, thirst = thirst, hunger = hunger, street = street, radio = radio, time = hours, minutes = minutes, direction = direction, voice = voice, speed = speed, fuel = fuel })
end

 

Link to comment
50 minutes ago, AngelAlpha said:
function updateDX( )
    local health = getElementHealth(localPlayer)
    local armour = getPedArmor(localPlayer)
    local hunger = getElementData(localPlayer, configs['Elements']['Fome']) or 0
    local thirst = getElementData(localPlayer, configs['Elements']['Sede']) or 0
    local stress = getElementData(localPlayer, configs['Elements']['Stress']) or 100
    local radio = getElementData(localPlayer, "ae.frequencia") or 0

    local x,y,z = getElementPosition(localPlayer)
    local street = getZoneName ( x, y, z, true )
    local direction = getZoneName ( x, y, z, false )

    local time = getRealTime()
    local hours = string.format("%02d:%02d", time.hour, time.minute)
    local minutes = time.minute

    if getPedOccupiedVehicle(localPlayer) then

        fuel = getElementData(getPedOccupiedVehicle(getLocalPlayer()), configs['Elements']['fuel']) or 0
        speed = ( function( x, y, z ) return math.floor( math.sqrt( x*x + y*y + z*z ) * 155 ) end )( getElementVelocity( getPedOccupiedVehicle(localPlayer) ) ) 

end

    SendNUIMessage(browser, { vehicle = vehicle, talking = talking, health = health, armour = armour, thirst = thirst, hunger = hunger, street = street, radio = radio, time = hours, minutes = minutes, direction = direction, voice = voice, speed = speed, fuel = fuel })
end

 

Thank you very much, this did everything, fixed everything, now everything works extremely well, and as it's supposed to!

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...