Jump to content

onClientRender


Recommended Posts

Posted

Hi, I wrote this script for the client:

showPlayerHudComponent("clock", false) 
  
function updateHud() 
    outputChatBox("function test") -- It doesn't work 
    local screenWidth, screenHeight = guiGetScreenSize() 
    local sx, sy = screenWidth/1400, screenHeight/900 
    --[[local realtime = getRealTime() 
    local hour = realtime.hour 
    local minute = realtime.minute]]-- 
    dxDrawText("00:00", 1229*sx, 56*sy, 140*sx, 148*sy) 
end 
  
function timeHudF() 
    addEventHandler("onClientRender", getRootElement(), updateHud)   
end 
  
addEventHandler("timeHud", getRootElement(), timeHudF) 

But the function updateHud is not called. Why?

Posted
timeHud event doesn't work, check code for it.

It's called by the server.

EDIT: Yes, it doesn't work. The server script is this:

function hudChanger() 
    triggerClientEvent("timeHud", getRootElement()) 
end 
addEventHandler("onPlayerSpawn", getRootElement(), hudChanger) 

Posted

I added that

showPlayerHudComponent("clock", false) 
  
function updateHud() 
    outputChatBox("function test") -- It doesn't work 
    local screenWidth, screenHeight = guiGetScreenSize() 
    local sx, sy = screenWidth/1400, screenHeight/900 
    --[[local realtime = getRealTime() 
    local hour = realtime.hour 
    local minute = realtime.minute]]-- 
    dxDrawText("00:00", 1229*sx, 56*sy, 140*sx, 148*sy) 
end 
  
function timeHudF() 
    outputChatBox("test") -- It doesn't work 
    addEventHandler("onClientRender", getRootElement(), updateHud)   
end 
  
addEvent("timeHud", true) 
addEventHandler("timeHud", getRootElement(), timeHudF) 

But it doesn't work.

Posted

Well then it's obvious, isn't it? It's the server-side code that's likely to be messed up. And we can't assist any further if you don't post that part of the code.

Posted
Well then it's obvious, isn't it? It's the server-side code that's likely to be messed up. And we can't assist any further if you don't post that part of the code.

I already posted it up.

function hudChanger() 
    triggerClientEvent("timeHud", getRootElement()) 
end 
addEventHandler("onPlayerSpawn", getRootElement(), hudChanger) 

Posted
function hudChanger() 
    triggerClientEvent("timeHud", getRootElement()) 
end 
addEventHandler("onPlayerSpawn", getRootElement(), hudChanger) 

Sorry, missed that. It looks ay-okay. That should trigger for all clients though.

What if you put a message there, is the function "hudChanger" being executed at all?

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