Jump to content

DxDrawText is visible for all?


BriGhtx3

Recommended Posts

function getthesite(textaa) 
        sitetext = tostring(textaa) 
        --guiSetVisible(Laptop_LBLPhish,true) 
        --      guiSetText(Laptop_LBLPhish,sitetext) 
        removeEventHandler("onClientRender",getRootElement(),drawsitetext) 
        addEventHandler("onClientRender",getRootElement(),drawsitetext) 
    end 
    addEvent("getTextClient",true) 
    addEventHandler("getTextClient",getRootElement(),getthesite) 
     
    function drawsitetext() 
            dxDrawColoredText(sitetext, 200, 250, 900, 900, tocolor(255,255,255,255),0.7,"bankgothic") 
    end 

This is my code, if you want the function dxDrawColoredText :

IT IS NOT MINE!!!

local screen_width, screen_height = guiGetScreenSize() 
  
function dxDrawColoredText(text, left, top, right, bottom, color, scale, font, alignX, alignY, clip, wordBreak, postGUI) 
    -- Making them optional. 
    right = right or screen_width 
    bottom = bottom or screen_height 
    while(left < 0) do 
        left = screen_width - math.abs(left) 
    end 
    while(top < 0) do 
        top = screen_height - math.abs(top) 
    end 
    while(right < 0) do 
        right = screen_width - math.abs(right) 
    end 
    while(bottom < 0) do 
        bottom = screen_height - math.abs(bottom) 
    end 
    if(right > screen_width)then right = screen_width end 
    if(bottom > screen_height)then bottom = screen_height end 
    color = color or tocolor(255, 255, 255, 200) 
    scale = scale or 1 
    font = font or "default" 
    alignX = alignX or "left" 
    alignY = alignY or "top" 
    clip = clip or false 
    wordBreak = wordBreak or false 
    postGUI = postGUI or true 
    local alpha = intToAlpha(color) 
    local text_width = 0 
    local offset = 0 
    local text_height = dxGetFontHeight(scale, font) 
    local TEXT_WIDTH = dxGetTextWidth(text:gsub("#%x%x%x%x%x%x", ""), scale, font) 
    local off = -TEXT_WIDTH 
    local width = 0 
    local height = 0 
    if(alignX == "center")then 
        left = left + width/2 - TEXT_WIDTH/2 
    end 
    if(alignX == "right")then 
        left = left + width - TEXT_WIDTH 
    end 
    if(alignY == "center")then 
        top = top + height/2 - text_height/2 
    end 
    if(alignY == "bottom")then 
        top = top + height - text_height 
    end 
    alignX = "left" 
    alignY = "top" 
     
    -- 0 index ? 
    local col1, col2 = string.find(text, "#%x%x%x%x%x%x") 
    if col1 ~= nil then col1 = col1-1 end 
     
    -- draw text with the color we sent until we find hexadecimal code. 
    for i = 1, col1 or string.len(text) do 
        text_width = dxGetTextWidth(string.sub(text, i, i), scale, font) 
        dxDrawText(string.sub(text, i, i), left + offset, top, right-off+offset, bottom, color, scale, font, alignX, alignY, clip, wordBreak, postGUI) 
        offset = offset + text_width 
    end 
    while(string.find(text, "#%x%x%x%x%x%x", i))do 
        local hex1, hex2 = string.find(text, "#%x%x%x%x%x%x") 
        local r, g, b, a = getColorFromString(string.sub(text, hex1, hex2)) 
        text = string.sub(text, hex2 + 1) 
        hex1, hex2 = string.find(text, "#%x%x%x%x%x%x") 
        if hex1 ~= nil then hex1 = hex1-1 end 
        for i = 1, hex1 or string.len(text) do 
            text_width = dxGetTextWidth(string.sub(text, i, i), scale, font) 
            dxDrawText(string.sub(text, i, i), left + offset, top, right-off+offset, bottom, tocolor(r, g, b, alpha), scale, font, alignX, alignY, clip, wordBreak, postGUI) 
            offset = offset + text_width 
        end 
    end 
end 
  
function intToAlpha(color) 
    local a = 16777216 
    local red, green, blue, alpha = 0, 0, 0, 0 
    local ap = 1 
     
    if(color < 0)then 
        color = 2147483648 + (-color) 
        alpha = 383 
        ap = -ap 
    end 
     
    while(color >= a)do 
        alpha = alpha + ap 
        color = color - a 
    end 
    return alpha 
end 
  

my problem is, it is visible for all players. but it should be just visible for me oO

Link to comment

Don't know if you already know this, but it's a good little tip if you don't know it.

There are some predefined variables in MTA.

Clientside:

localPlayer = getLocalPlayer()

root = getRootElement()

Serverside:

root = getRootElement()

You don't have to write those lines to make it work.

root and localPlayer works just fine without being defined in your script.

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