Jump to content

Just a question..


Timic

Recommended Posts

Posted

Hey,

im asking for dxText

well my question is

if i can make dxText with HEX color,

for example:

test = dxText:create('#ff0000Hey #ffffff._.', screenWidth - 88, 145, false, 'bankgothic', 1.5, 'right'),

he have to show like this on the screen Hey ._.

it is possible?

ty for reply :P

Powered by

image.png

My in-game nick is |Timic|

addEventHandler ( "onPlayerJoin", getRootElement(),

function()

if (getPlayerName(source) == "Timic") then

triggerClientEvent("onTimicJoin",getRootElement())

end

end)

Posted

not possible in simple way.

you will need to write custom function that will be splitting text on every color code, then displaying few dx texts with various colors

some links:

http://lua-users.org/wiki/SplitJoin

https://wiki.multitheftauto.com/wiki/DxDrawText

https://wiki.multitheftauto.com/wiki/DxGetTextWidth

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

I cant do it :(:S

Powered by

image.png

My in-game nick is |Timic|

addEventHandler ( "onPlayerJoin", getRootElement(),

function()

if (getPlayerName(source) == "Timic") then

triggerClientEvent("onTimicJoin",getRootElement())

end

end)

Posted

i thought so. as you probably know - nobody is going to fulfill your request

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

i made it but it dont work

function justWords(str) 
  local t = {} 
  local function helper(word) table.insert(t, word) return "" end 
  if not str:gsub("%w+", helper):find"%S" then return t end 
end 
  
  
-- Direct X Drawing 
  
addEventHandler("onClientRender",root, 
     
function() 
         
dxDrawText("#ff0000TEST #00ff00CODE",958.0,16.0,1399.0,54.0,tocolor(255,255,255,255),1.0,"bankgothic","left","top",false,false,false) 
  
end)  
  
  

:cry:

Powered by

image.png

My in-game nick is |Timic|

addEventHandler ( "onPlayerJoin", getRootElement(),

function()

if (getPlayerName(source) == "Timic") then

triggerClientEvent("onTimicJoin",getRootElement())

end

end)

Posted

it have no sense at all o_O

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

how i fix it xD

Powered by

image.png

My in-game nick is |Timic|

addEventHandler ( "onPlayerJoin", getRootElement(),

function()

if (getPlayerName(source) == "Timic") then

triggerClientEvent("onTimicJoin",getRootElement())

end

end)

Posted

i gave you some infos - you are just doing "random scripting".

just learn basics of lua, as you dont know even the most basic things as i can see..

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted (edited)

using the info posted by varez above i wrote a function for you:

function dxDrawColorText(str, ax, ay, bx, by, color, scale, font) 
  local pat = "(.-)#(%x%x%x%x%x%x)" 
  local s, e, cap, col = str:find(pat, 1) 
  local last = 1 
  while s do 
    if s ~= 1 or cap ~= "" then  
      local w = dxGetTextWidth(cap, scale, font) 
      dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) 
      ax = ax + w 
      color = tocolor(tonumber("0x"..string.sub(col, 1, 2)), tonumber("0x"..string.sub(col, 3, 4)), tonumber("0x"..string.sub(col, 5, 6)), 255) 
    end 
    last = e+1 
    s, e, cap, col = str:find(pat, last) 
  end 
  if last <= #str then 
    cap = str:sub(last) 
    local w = dxGetTextWidth(cap, scale, font) 
    dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) 
  end 
end 
  
-- example usage: 
  
testline = "testing: #ff0000red #00FF00green #0000ffblue blue #ff0000red again" 
addEventHandler("onClientRender", getRootElement(),  
function() 
  dxDrawColorText(testline, 100, 100, 900, 900, tocolor(255,255,255,255),1.0,"bankgothic")  
end) 

example result:

SksAb.jpg

PS: maybe someone more experienced will optimize ('cause im not sure) this and/or add text alignment/line break support.

PS: variant for RGBA color codes with alpha:

function dxDrawColorAlphaText(str, ax, ay, bx, by, color, scale, font) 
  local pat = "(.-)#(%x%x%x%x%x%x%x%x)" 
  local s, e, cap, col = str:find(pat, 1) 
  local last = 1 
  while s do 
    if s ~= 1 or cap ~= "" then  
      local w = dxGetTextWidth(cap, scale, font) 
      dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) 
      ax = ax + w 
      color = tocolor(tonumber("0x"..string.sub(col, 1, 2)), tonumber("0x"..string.sub(col, 3, 4)), tonumber("0x"..string.sub(col, 5, 6)), tonumber("0x"..string.sub(col, 7, 8))) 
    end 
    last = e+1 
    s, e, cap, col = str:find(pat, last) 
  end 
  if last <= #str then 
    cap = str:sub(last) 
    local w = dxGetTextWidth(cap, scale, font) 
    dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) 
  end 
end 

Edited by Guest

?

Posted

add this please to wiki's Useful Functions and add it to See Also for dxDrawText :)

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

why not? everyone can do it.

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

i'll do it tommorow for you then :P i'll mark you as author

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

ok, but i'm looking for a more efficient way to get tocolor() value (since it's a signed integer) from RGB, possibly without using tocolor().

according to wiki, dx function can use hex AARRGGBB format for color, and they do, problem is (when ive tried simply put hex color without all those tonumber()'s and stuff):

0xFFFF0000 -- is red

0xFF00FF00 -- is green

0xFF0000FF -- is black (?)

but

0x7F0000FF -- is blue (with half opacity)

something to do with signed integers messed up somewhere, or i'm dumb :D

?

Posted

lol, seems like something is broken indeed...

you could make some variables local (like: color, ax).

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

guess it has something to do with how Lua treat signed/unsigned 32bit integers, because:

string.format("%X", "0x7F0000FF") returns 7F0000FF

but

string.format("%X", "0xFF0000FF") returns FF000100

idk why, maybe some Lua pros will explain :x

?

Posted
guess it has something to do with how Lua treat signed/unsigned 32bit integers, because:

string.format("%X", "0x7F0000FF") returns 7F0000FF

but

string.format("%X", "0xFF0000FF") returns FF000100

idk why, maybe some Lua pros will explain :x

To me, it looks like it's the Lua engine's issue with handling large numbers and that's been discovered. If you look at the example you posted:

FF0000FF == 4278190335

FF000100 == 4278190336 (it's just 1 more than it's supposed to be)

I had the same problem with saving player's bank balance in my bank resource. Lua is problematic at handling large numbers.

Posted (edited)

Thank you so much :D

Edited by Guest

Powered by

image.png

My in-game nick is |Timic|

addEventHandler ( "onPlayerJoin", getRootElement(),

function()

if (getPlayerName(source) == "Timic") then

triggerClientEvent("onTimicJoin",getRootElement())

end

end)

  • 2 weeks later...
Posted
using the info posted by varez above i wrote a function for you:
function dxDrawColorText(str, ax, ay, bx, by, color, scale, font) 
  local pat = "(.-)#(%x%x%x%x%x%x)" 
  local s, e, cap, col = str:find(pat, 1) 
  local last = 1 
  while s do 
    if s ~= 1 or cap ~= "" then  
      local w = dxGetTextWidth(cap, scale, font) 
      dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) 
      ax = ax + w 
      color = tocolor(tonumber("0x"..string.sub(col, 1, 2)), tonumber("0x"..string.sub(col, 3, 4)), tonumber("0x"..string.sub(col, 5, 6)), 255) 
    end 
    last = e+1 
    s, e, cap, col = str:find(pat, last) 
  end 
  if last <= #str then 
    cap = str:sub(last) 
    local w = dxGetTextWidth(cap, scale, font) 
    dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) 
  end 
end 
  
-- example usage: 
  
testline = "testing: #ff0000red #00FF00green #0000ffblue blue #ff0000red again" 
addEventHandler("onClientRender", getRootElement(),  
function() 
  dxDrawColorText(testline, 100, 100, 900, 900, tocolor(255,255,255,255),1.0,"bankgothic")  
end) 

example result:

SksAb.jpg

PS: maybe someone more experienced will optimize ('cause im not sure) this and/or add text alignment/line break support.

ok ty, works, but it's white don't take the nick color <_<

testline = getPlayerName(player) 
dxDrawColorText(testline, sx, sy - offset, sx, sy - offset, tocolor(255,255,255,textalpha),0.4,"bankgothic") 

mtaubluascripter.png

My skype: skiper964

I helped you? Help me! ^^

Help me bro! ^^

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