Nakka Lindo Posted February 21, 2023 Share Posted February 21, 2023 local screenX,screenY = guiGetScreenSize() local messages = {} -- {text, player, lastTick, alpha, yPos} local timeVisible = 4000 local distanceVisible = 28 local bubble = false -- Rounded rectangle(true) or not(false) function addBubble(text, player, tick) if (not messages[player]) then messages[player] = {} end table.insert(messages[player], {["text"] = text, ["player"] = player, ["tick"] = tick, ["endTime"] = tick + 0, ["alpha"] = 0}) end function removeBubble() table.remove(messages) end addEvent("onChatIncome", true) addEventHandler("onChatIncome", root, function(message, messagetype) addBubble(message, source, getTickCount()) end ) addEventHandler("onClientRender", root, function() local tick = getTickCount() local x, y, z = getElementPosition(localPlayer) for _, pMessage in pairs(messages) do for i, v in ipairs(pMessage) do if isElement(v.player) then if tick-v.tick < timeVisible then local px, py, pz = getElementPosition(v.player) if getDistanceBetweenPoints3D(x, y, z, px, py, pz) < distanceVisible and isLineOfSightClear ( x, y, z, px, py, pz, true, not isPedInVehicle(v.player), false, true) then v.alpha = v.alpha < 190 and v.alpha + 10 or v.alpha local bx, by, bz = getPedBonePosition(v.player, 3) local sx, sy = getScreenFromWorldPosition(bx, by, bz) local elapsedTime = tick - v.tick local duration = v.endTime - v.tick local progress = elapsedTime / duration if sx and sy then if not v.yPos then v.yPos = sy end local width = dxGetTextWidth(v.text:gsub("#%x%x%x%x%x%x", ""), 1, "default-bold") local yPos = interpolateBetween ( v.yPos, 0, 0, sy - 0, 0, 0, progress, progress > 1000 and "Linear" or "OutElastic") if bubble then dxDrawRectangle( sx-width/2-.01*screenX, yPos - .14*screenY, width+.02*screenX, 16, tocolor(255, 255, 255, v.alpha) ) else drawBorde(sx-width/2-.01*screenX, yPos - .17*screenY, width+.02*screenX, 16, tocolor(0, 0, 0, v.alpha)) -- Onde ta 17 Sobe desce end dxDrawText(v.text, sx-width/2, yPos - .17*screenY, width, 20, tocolor( 255, 255, 255, v.alpha + 0), 1, "default-bold", "left", "top", false, false, false, true)-- Onde ta 17 Sobe desce end end else table.remove(messages[v.player], i) end else table.remove(messages[v.player], i) end end end end ) function drawBorde(x, y, w, h, borderColor, bgColor, postGUI) if (x and y and w and h) then if (not borderColor) then borderColor = tocolor(0, 0, 0, 200) end if (not bgColor) then bgColor = borderColor end postGUI = false dxDrawRectangle(x, y, w, h, bgColor, postGUI) dxDrawRectangle(x + 2, y - 1, w - 4, 1, borderColor, postGUI) -- top dxDrawRectangle(x + 2, y + h, w - 4, 1, borderColor, postGUI) -- bottom dxDrawRectangle(x - 1, y + 2, 1, h - 4, borderColor, postGUI) -- left dxDrawRectangle(x + w, y + 2, 1, h - 4, borderColor, postGUI) -- right end end 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