well, i used this on my notification functions and never was troubled:
timeToFade = getTickCount () + #text * 150;
for exports, there are two ways. one: setting variables on resource start and check if variable is assigned to a value on render and use it if it does. two: creating a local function in your exported function and pass the arguments you need to render (i prefer this one because variables are nasty-looking).
so, the new code should look like this:
local displayWidth, displayHeight = guiGetScreenSize();
local borderDistance = 20
local tipBox = { }
local boxX, boxY = borderDistance * displayWidth / displayWidth, borderDistance * displayHeight / displayHeight
local boxPadding = 10
local lineHeight = dxGetFontHeight( 1, "default-bold" )
local minimumWidth = 350
local offsetWidth = 25
local tick = 0
addEventHandler( "onClientRender", root,
function( )
if tipBox.string then
local lines = 0
local wordbreak = false
local lineWidth = dxGetTextWidth( tipBox.string, 1, "default-bold" )
while ( lineWidth + offsetWidth > minimumWidth ) do
lineWidth = lineWidth - minimumWidth
lines = lines + 1
wordbreak = true
end
local boxWidth, boxHeight = minimumWidth + ( boxPadding * 3 ), ( lineHeight * ( lines + 1 ) ) + ( boxPadding * 2 )
dxDrawRectangle( boxX, boxY, boxWidth, boxHeight, tocolor( 0, 0, 0, 180 ), true )
dxDrawRectangle( boxX, boxY+boxHeight, boxWidth, 4, tocolor( 200, 0, 100, 255 ), true )
local textX, textY = boxX + boxPadding, boxY + boxPadding
local textWidth, textHeight = textX + minimumWidth + boxPadding, textY + lineHeight + boxPadding
dxDrawText( tipBox.string, textX, textY, textWidth, textHeight, tocolor( 255, 255, 255, 255 ), 1, "default-bold", "left", "top", false, wordbreak, true )
if getTickCount () >= tick then
alpha = alpha - 25;
if alpha <= 0 then
alpha = 0;
tipBox.string = nil;
end
end
end
end
)
function notificate (text) --declare your function
tipBox.string = text;
tick = getTickCount () + (#text * 150);
alpha = 255; --if you want it to fade
end
notificate ("shakalaka boom"); --testing
i haven't tried it