Jump to content

[HELP] Time + Date


LukisLT

Recommended Posts

Posted

Hi guys, i know.. i'm lazzy, but i need your help, i have made an gui, made bind key for him etc.. now for me the hardest part... how to make this : labels : Time : Date : and i'm trying to make, that i could see after " Time " and " Date " the real time and date.. that is today, i'm still learning Lua codes, so i think here is the best place to ask for help :)

Thanks~

Lukas.

Posted
function getCurrentDateAndTime ( ) 
    local realTime = getRealTime ( ) 
    local cDate = string.format ( "%04d/%02d/%02d", realTime.year + 1900, realTime.month + 1, realTime.monthday ) 
    local cTime = string.format ( "%02d:%02d:%02d", realTime.hour, realTime.minute, realTime.second ) 
    return cDate, cTime 
end 

cDate, cTime = getCurrentDateAndTime ( ) 

Posted
Didn't worked for me, not showing the number there where i want them to show...

show your code.

Posted

I used the code of Solid's, and other code is just a gui, with " Time " and " Date " labels i wath to make : "Time : 00:00:00" and "Date 30/6/2012" for example beside the labels, the function he gived, is not showing errors, but not work too.

Posted
function GetCurrentDateAndTime ( ) 
    local aRealTime = getRealTime ( ) 
    return  
        string.format ( "%04d/%02d/%02d", aRealTime.year + 1900, aRealTime.month + 1, aRealTime.monthday ), 
        string.format ( "%02d:%02d:%02d", aRealTime.hour, aRealTime.minute, aRealTime.second ) 
end 
  
local sDate, sTime = GetCurrentDateAndTime( ) 
guiCreateLabel( 0.5, 0.5, 0.5, 0.5, 'Time: ' .. sTime .. ' Date ' .. sDate , true ) 

?

Posted

Thank you Kenix :) it works now, only small bug, i need to move text to my possition, and once o close gui, time still showing, not clossing with the gui. but, thank you, you helped me, at least to make the time show. not in gui but still, i will try to fix somehow, or else, i be back here.

Thanks~

Lukas.

Posted
Thank you Kenix :) it works now, only small bug, i need to move text to my possition, and once o close gui, time still showing, not clossing with the gui. but, thank you, you helped me, at least to make the time show. not in gui but still, i will try to fix somehow, or else, i be back here.

Thanks~

Lukas.

You have to use parent argument.

https://wiki.multitheftauto.com/wiki/GuiCreateLabel

Posted

Since you already have create the label at the gui, why you don't use guiSetText?

i think you already will need to update the time - date at the label

you will need to use event onClientRender or a timer to update the time - date in the label.

Posted (edited)
you will need to use event onClientRender or a timer to update the time - date in the label.

Never use onClientRender for this target. Use timer instead.

Think please before post advice.

Edited by Guest
Posted

Yes, i have this bug, once i start script, time doesn't tick, like on clock, to see the real time i must " restart script " or " reconncet " to update current time and date. so i will try to add render functions as you just sayd, and thanks for help :) or timer, so i wount need reconnect just to see current time :)

Posted

And one more question, i made bind key function, but there is some mistake, the panel pops up everytime i connect to server, how could i do, that the panel pops up only when i press the " bind key " ? that would be helpfull for me.

Posted
And one more question, i made bind key function, but there is some mistake, the panel pops up everytime i connect to server, how could i do, that the panel pops up only when i press the " bind key " ? that would be helpfull for me.

you need to use guiSetVisible after create the gui window.

Example:

theWindow = guiCreateWindow(100,200,50,50,"Example",false) 
guiSetVisible(theWindow,false) 

https://wiki.multitheftauto.com/wiki/GuiSetVisible

Posted

Yes thanks, i did it and it's worked for me, but last my problem, the function i using, to create time and date labels, it's outside the gui, trying hard, but no succes, to put the text in the gui.

Posted
Yes thanks, i did it and it's worked for me, but last my problem, the function i using, to create time and date labels, it's outside the gui, trying hard, but no succes, to put the text in the gui.
Thank you Kenix :) it works now, only small bug, i need to move text to my possition, and once o close gui, time still showing, not clossing with the gui. but, thank you, you helped me, at least to make the time show. not in gui but still, i will try to fix somehow, or else, i be back here.

Thanks~

Lukas.

You have to use parent argument.

https://wiki.multitheftauto.com/wiki/GuiCreateLabel

parent: This is the parent that the gui label is attached to. If the relative argument is true, sizes and positioning will be made relative to this parent. If the relative argument is false, positioning will be the number of offset pixels from the parent's origin. If no parent is passed, the parent will become the screen - causing positioning and sizing according to screen positioning.
Posted
Yes thanks, i did it and it's worked for me, but last my problem, the function i using, to create time and date labels, it's outside the gui, trying hard, but no succes, to put the text in the gui.
Since you already have create the label at the gui, why you don't use guiSetText?

i think you already will need to update the time - date at the label

you will need to use event onClientRender or a timer to update the time - date in the label.

Posted

Well, gui is created, but i didn't made label in the gui for time & date, coz Kenix function makes the label, but the label is out of panel directories, just playing around, and trying to get the text in the panel gui... but no succes so far.

Posted
Well, gui is created, but i didn't made label in the gui for time & date, coz Kenix function makes the label, but the label is out of panel directories, just playing around, and trying to get the text in the panel gui... but no succes so far.

Show us your code -.-

Posted
This is little example of what i meant to say in my last message :

example.png

Well, gui is created, but i didn't made label in the gui for time & date, coz Kenix function makes the label, but the label is out of panel directories, just playing around, and trying to get the text in the panel gui... but no succes so far.

dude you already create the label look at your image !

wasn't you need to update the label? how you're doing it?

You need to use guiSetText and delete the label in Kenix function

https://wiki.multitheftauto.com/wiki/GuiSetText

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