Snakegold Posted August 24, 2018 Share Posted August 24, 2018 Hello, can you tell me how to make dxDrawText appears after 1 sec and disappears after 2 secs and it is possible to make the dxdrawtext appears only in specified dimension? if so give me examples please Link to comment
Z4Zy Posted August 24, 2018 Share Posted August 24, 2018 2 hours ago, Snakegold said: Hello, can you tell me how to make dxDrawText appears after 1 sec and disappears after 2 secs and it is possible to make the dxdrawtext appears only in specified dimension? if so give me examples please To create a dxDrawText appears after 1 sec and disappears after 2 sec, you need to use setTimer function. + It is possible to make the dxDrawText appears only in specified dimension... For this, You need to check player's dimension with the function getElementDimension functions with dxDrawText must be handled with the below event. onClientRender And note that this should be a Client Side Script. Link to comment
Snakegold Posted August 24, 2018 Author Share Posted August 24, 2018 function renderCountDown (text) dxDrawText("1", (screenW * 0.1596) + 1, (screenH * 0.2839) + 1, (screenW * 0.8404) + 1, (screenH * 0.4297) + 1, tocolor(0, 0, 0, 255), 4.00, "bankgothic", "center", "top", false, false, false, false, false) dxDrawText("1", screenW * 0.1596, screenH * 0.2839, screenW * 0.8404, screenH * 0.4297, tocolor(255, 255, 255, 255), 4.00, "bankgothic", "center", "top", false, false, false, false, false) end addRenderEvent(renderCountDown, "onClientRender") setTimer ( function() end, 1000, 1 ) removeRenderEvent(renderCountDown, "onClientRender") setTimer ( function() end, 3000, 1 ) I want it appears after 1 sec and disappears after 3 secs and i tried this function renderCountDown (text) local screenW , screenH = guiGetScreenSize() dxDrawText("1", (screenW * 0.1596) + 1, (screenH * 0.2839) + 1, (screenW * 0.8404) + 1, (screenH * 0.4297) + 1, tocolor(0, 0, 0, 255), 4.00, "bankgothic", "center", "top", false, false, false, false, false) dxDrawText("1", screenW * 0.1596, screenH * 0.2839, screenW * 0.8404, screenH * 0.4297, tocolor(255, 255, 255, 255), 4.00, "bankgothic", "center", "top", false, false, false, false, false) end addEventHandler ("onClientRender",root,renderCountDown) addRenderEvent(renderCountDown, "onClientRender") setTimer ( function() end, 1000, 1 ) removeRenderEvent(renderCountDown, "onClientRender") setTimer ( function() end, 3000, 1 ) Link to comment
Dimos7 Posted August 24, 2018 Share Posted August 24, 2018 function renderCountDown (text) dxDrawText("1", (screenW * 0.1596) + 1, (screenH * 0.2839) + 1, (screenW * 0.8404) + 1, (screenH * 0.4297) + 1, tocolor(0, 0, 0, 255), 4.00, "bankgothic", "center", "top", false, false, false, false, false) dxDrawText("1", screenW * 0.1596, screenH * 0.2839, screenW * 0.8404, screenH * 0.4297, tocolor(255, 255, 255, 255), 4.00, "bankgothic", "center", "top", false, false, false, false, false) end setTimer (function() addRenderEvent(renderCountDown, "onClientRender") end, 1000, 1 ) setTimer ( function() removeRenderEvent(renderCountDown, "onClientRender") end, 3000, 1 ) 1 Link to comment
Snakegold Posted August 24, 2018 Author Share Posted August 24, 2018 ERROR: attempt to call global 'addRenderEvent' (a nil value) ERROR: attempt to call global 'removeRenderEvent' (a nil value) Link to comment
Dimos7 Posted August 24, 2018 Share Posted August 24, 2018 -------------------- -- Author: IIYAMA -- -------------------- local renderEvents = { "onClientRender", "onClientPreRender", "onClientHUDRender" } local allTargetFunctions = {} -- All attached functions will be stored in this table. local acceptedRenderEventTypes = {} -- Is type in use? See: renderEvents. local renderEventTypeStatus = {} -- Is the event in use? (so it doesn't have to be attached again) do -- prepare the data for i=1, #renderEvents do local event = renderEvents[i] allTargetFunctions[event] = {} acceptedRenderEventTypes[event] = true renderEventTypeStatus[event] = false end end -- render all events here local processTargetFunction = function (timeSlice) local targetFunctions = allTargetFunctions[eventName] for i=#targetFunctions, 1, -1 do local targetFunctionData = targetFunctions[i] local arguments = targetFunctionData[2] if not arguments then targetFunctionData[1](timeSlice) else if timeSlice then targetFunctionData[1](timeSlice, unpack(arguments)) else targetFunctionData[1](unpack(arguments)) end end end end -- check if a function is already attached local checkIfFunctionIsTargetted = function (theFunction, event) if not event or not acceptedRenderEventTypes[event] then event = "onClientRender" end local targetFunctions = allTargetFunctions[event] for i=1, #targetFunctions do if targetFunctions[i][1] == theFunction then return true end end return false end -- add render event, default type is onClientRender function addRenderEvent(theFunction, event, ...) if not event or not acceptedRenderEventTypes[event] then event = "onClientRender" end if not checkIfFunctionIsTargetted(theFunction) then local targetFunctions = allTargetFunctions[event] targetFunctions[#targetFunctions + 1] = {theFunction, {...}} -- attach an event if not renderEventTypeStatus[event] then addEventHandler (event, root, processTargetFunction, false, "high") renderEventTypeStatus[event] = true end return true end return false end -- remove a render event function removeRenderEvent(theFunction, event) if not event or not acceptedRenderEventTypes[event] then event = "onClientRender" end local targetFunctions = allTargetFunctions[event] for i=1, #targetFunctions do if targetFunctions[i][1] == theFunction then table.remove(targetFunctions, i) if #targetFunctions == 0 then if renderEventTypeStatus[event] then removeEventHandler (event, root, processTargetFunction) renderEventTypeStatus[event] = false end end return true end end return false end Make sure copy that code to your script Link to comment
JeViCo Posted August 25, 2018 Share Posted August 25, 2018 (edited) wtf why so difficult? function renderCountDown (text) if not isTimer(offRender) then offRender = setTimer(function() removeEventHandler("onClientRender",getRootElement(),renderCountDown) -- remove render after 3 seconds return end,3000,1) end dxDrawText("1", (screenW * 0.1596) + 1, (screenH * 0.2839) + 1, (screenW * 0.8404) + 1, (screenH * 0.4297) + 1, tocolor(0, 0, 0, 255), 4.00, "bankgothic", "center", "top", false, false, false, false, false) dxDrawText("1", screenW * 0.1596, screenH * 0.2839, screenW * 0.8404, screenH * 0.4297, tocolor(255, 255, 255, 255), 4.00, "bankgothic", "center", "top", false, false, false, false, false) end addEventHandler("onClientRender",getRootElement(),renderCountDown) -- add render OR function renderCountDown (text) if not startTick then startTick = getTickCount() end if getTickCount() - startTick > 3000 then -- 3000ms = 3s removeEventHandler("onClientRender",getRootElement(),renderCountDown) -- remove render startTick = nil return end dxDrawText("1", (screenW * 0.1596) + 1, (screenH * 0.2839) + 1, (screenW * 0.8404) + 1, (screenH * 0.4297) + 1, tocolor(0, 0, 0, 255), 4.00, "bankgothic", "center", "top", false, false, false, false, false) dxDrawText("1", screenW * 0.1596, screenH * 0.2839, screenW * 0.8404, screenH * 0.4297, tocolor(255, 255, 255, 255), 4.00, "bankgothic", "center", "top", false, false, false, false, false) end addEventHandler("onClientRender",getRootElement(),renderCountDown) -- add render I didn't test both @Snakegold Edited August 25, 2018 by JeViCo 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