greentumbleweed Posted April 23, 2022 Share Posted April 23, 2022 (edited) How can i make this text fade and stack on each hit? function dxDrawDamageAttacker(weapon_damage,damage_resist) addEventHandler("onClientRender", root, function() local screenW, screenH = guiGetScreenSize() local dmgrec = dxDrawText("-"..math.floor(weapon_damage * damage_resist * randomFloat(0.70, 0.85)), screenW * 0.6062, screenH * 0.4208, screenW * 0.7520, screenH * 0.4313, tocolor(46, 196, 20, 255), 1.00, "default", "left", "top", false, false, false, true, false) end) end addEvent("drawDamageAttacker", true) addEventHandler ( "onClientRender", getRootElement(), dxDrawDamageAttacker ) addEventHandler("drawDamageAttacker", root, dxDrawDamageAttacker) Edited April 23, 2022 by greentumbleweed Link to comment
Mkl Posted April 24, 2022 Share Posted April 24, 2022 (edited) Hi, Here is a fast test I did to create shade and stack effects, I don't really know if it's a proper way but it works : -- Some parametrable values local max_lines = 5 -- max lines (max stack) local timeToFade = 500 -- time to appear and disappear fade-effect (in ms) local timeToShow = 2000 -- time to plainly show the text local gap = 20 -- vertical gap between texts -- A variable to store texts local texts = {} function addText() -- in case we are in the column bottom, we don't reset the table until everything ended his display, -- including if we keep repeating the last one local is_last = true for _, v in ipairs(texts) do if not v.ended then is_last = false break end end -- nothing still displayed, we reset the table if is_last then texts = {} end -- if it's the last line, we stop the previous text if #texts == max_lines then removeEventHandler("onClientRender", root, texts[#texts].displayText) table.remove(texts, #texts) end -- New entry in the table, and local variable for short syntax texts[#texts + 1] = {} local text = texts[#texts] text.alpha = 0 -- alpha set to 0 text.firstCount = getTickCount() -- time reference text.state = 1 -- state use to situate the effect (1/2/3) (appearing/showing/vanishing) text.pos = #texts -- store his position -- function for onClientRenderEvent function text.displayText() if (text.state == 1) then -- showing fade effect text.count = getTickCount() - text.firstCount -- ratio between time and alpha value text.alpha = (text.count * 255) / timeToFade elseif (text.state == 2) then -- opac state text.alpha = 255 elseif (text.state == 3) then -- vanish fade effect text.count = timeToFade - (getTickCount() - text.firstCount) -- ratio between time and alpha value text.alpha = (text.count * 255) / timeToFade end text.y = 500 + (text.pos * gap) text.color = tocolor(255, 255, 255, text.alpha) dxDrawText("This is a test", 500, text.y, _, _, text.color) end addEventHandler("onClientRender", root, text.displayText) setTimer(function() -- first timer to opac state text.alpha = 255 text.state = 2 end, timeToFade, 1) setTimer(function() -- second timer to vanish fade effect text.state = 3 text.firstCount = getTickCount() end, timeToFade + timeToShow, 1) setTimer(function() -- last timer to the end removeEventHandler("onClientRender", root, text.displayText) text.ended = true -- bool to know this text finished to be displayed end, (timeToFade * 2) + timeToShow, 1) end addCommandHandler("somecmd", addText) Edited April 24, 2022 by Mkl Link to comment
greentumbleweed Posted April 24, 2022 Author Share Posted April 24, 2022 Thank you very much this will help me do what im trying to do! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now