Artyom888 Posted November 24, 2019 Posted November 24, 2019 Hi, guys, help me. How to make a timer change the images? I've written a code but it doesn’t want to work. local screenSize = Vector2(guiGetScreenSize()) function random () if not systemUpTime then systemUpTime = getTickCount () end currentCount = getTickCount () tic = ( currentCount - systemUpTime ) outputDebugString( tic) if tic > 30000 then backgroundTexture = dxCreateTexture("assets/screen" .. tostring(math.random(1,6)) .. ".png") else backgroundTexture = dxCreateTexture("assets/screen1.png") end end setTimer( random, 35000, 0 ) local function draw( ) dxDrawImage ( 0, 0, screenSize.x, screenSize.y, backgroundTexture, angle, 0, -120 ) end addEventHandler("onClientRender", root, draw)
Moderators IIYAMA Posted November 24, 2019 Moderators Posted November 24, 2019 (edited) 7 hours ago, Artyom888 said: I've written a code but it doesn’t want to work. can't you be a little bit specific? ... Well, this is what I changed: local screenSize = Vector2(guiGetScreenSize()) -- Do not create textures every frame, but DO before rendering them local textures = {} for i=1, 6 do textures[i] = dxCreateTexture("assets/screen" .. i .. ".png") or "assets/screen" .. i .. ".png" -- apply a fallback in case of failing end local backgroundTexture = textures[1] function random () -- No need for tickCount if you use a timer. (unless tickCount is used for processing data) backgroundTexture = textures[math.random(6)] end setTimer( random, 30000, 0 ) local angle = 0 -- angle is missing?????????????? local function draw( ) dxDrawImage ( 0, 0, screenSize.x, screenSize.y, backgroundTexture, angle, 0, -120 ) end addEventHandler("onClientRender", root, draw) Edited November 24, 2019 by IIYAMA Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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