Jump to content

Change the timer images!


Artyom888

Recommended Posts

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)

 

Link to comment
  • Moderators
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 by IIYAMA
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...