Jump to content

guiSetText Problem


Jade

Recommended Posts

addEventHandler("onClientRender",root, 
    function() 
        local hours = getRealTime().hour 
        local minutes = getRealTime().minute 
        local seconds = getRealTime().second 
   
dxDrawText(hours..":"..minutes..":"..seconds,0,0,10,10,tocolor(255,157,0,255),0.6,"bankgothic") 
    end 
) 

own script

https://community.multitheftauto.com/in ... ls&id=5724

I need to guisettext

-- author Reflex 
addEventHandler("onClientRender",root, 
    function() 
        local hours = getRealTime().hour 
        local minutes = getRealTime().minute 
--      dxDrawText(hours..":"..minutes,x/1.093,y/10.8,74,10,tocolor(127, 199, 255,150),0.55,"bankgothic") 
    end 
) 
-- 
  
zamanayari = guiCreateLabel ( 0.01, 0.22, 0.3, 0.4, "Zaman",true ) 
  
  function serverzamani() 
    guiSetText(zamanayari, "?" ) 
    end 
  
setTimer(serverzamani, 60000, 0) 
  

Link to comment
zamanayari = guiCreateLabel ( 0.01, 0.22, 0.3, 0.4, "Zaman",true ) 
  
function serverzamani() 
    local time = getRealTime() 
    local hours = time.hour 
    local minutes = timer.minute 
    guiSetText(zamanayari, string.format("%02d:%02d", hours, minutes) ) 
end 
  
setTimer(serverzamani, 60000, 0) 

Link to comment

Well, yea, my bad.

zamanayari = guiCreateLabel ( 0.01, 0.22, 0.3, 0.4, "Zaman",true ) 
      
function serverzamani() 
    local time = getRealTime() 
    local hours = time.hour 
    local minutes = time.minute 
    guiSetText(zamanayari, string.format("%02d:%02d", hours, minutes) ) 
end 
addEventHadnler("onClientRender", root, serverzamani) 

Link to comment
  • Moderators

Please use a setTimer instead ! CVC said it would be better but he is wrong because you are actually updating the text 30 times per second at 30FPS ! (and 60 for 60FPS etc)

You can use a setTimer to update it every 5 seconds for example (not 60 (= 1min) because the timers aren't really accurate so by setting it at 5 seconds, the clock can be late from 5 secs at most which is totally acceptable for a clock the player won't really care about).

By doing that you are reducing the client CPU load because your script will be executed 1 times every 5 seconds instead of 150 times at 30 FPS (and 300 at 60FPS).

Hope it will help to understand what onClientRender is really used for.

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