Jump to content

Dx ?


Recommended Posts

local screenW, screenH = guiGetScreenSize() 
  
function hex2rgb(hex) 
  hex = hex:gsub("#","") 
  return tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6)) 
end 
function draw( ) 
    for i, player in ipairs(getElementsByType("player")) do 
        local t1 = getElementData(player,"text1") 
        local c1 = getElementData(player,"color1") 
        local r, g, b =  hex2rgb(c1) 
        local s1 = getElementData(player,"score1") 
        dxDrawText(t1, screenW * 0.0139, screenH * 0.5755, screenW * 0.0593, screenH * 0.6042, tocolor(r,g,b), 1.00, "default", "left", "top", false, false, true, false, false) 
        dxDrawText(s1, screenW * 0.0673, screenH * 0.5768, screenW * 0.0857, screenH * 0.6042, tocolor(255,255,255), 1.00, "default", "left", "top", false, false, true, false, false) 
    end 
end 
addEventHandler("onClientRender",root,draw) 
addEventHandler("onClientPlayerJoin",root,draw) 
function draw2( ) 
        for i, player in ipairs(getElementsByType("player")) do 
        local t2 = getElementData(player,"text2") 
        local c2 = getElementData(player,"color2") 
        local s2 = getElementData(player,"score2") 
        local r, g, b =  hex2rgb(c2) --inject the hex to the function, with # appended in front. Returns RGB. 
        dxDrawText(t2, screenW * 0.0139, screenH * 0.6289, screenW * 0.0988, screenH * 0.6302, tocolor(r,g,b), 1.00, "default", "left", "top", false, false, true, false, false) 
        dxDrawText(s2, screenW * 0.0673, screenH * 0.6302, screenW * 0.0857, screenH * 0.6576, tocolor(255,255,255), 1.00, "default", "left", "top", false, false, true, false, false) 
        dxDrawRectangle(screenW * 0.0095, screenH * 0.5586, screenW * 0.0761, screenH * 0.0990, tocolor(0, 0, 0, 98), false) 
    end 
end 
addEventHandler("onClientRender",root,draw2) 
addEventHandler("onClientPlayerJoin",root,draw2) 
  
  

everything works fine but when u reconnect the whole thing is not visible u need to restart the resource

Link to comment

If you say that it works when u restart the script, then you dont need to add the event onClientPlayerJoin.

It is started by onClientRender, then u can avoid that.

On the other hand, if you want to use an event when the player joins, I recommend you to use a trigger.

Regards.

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