Tonyx97 Posted November 5, 2013 Share Posted November 5, 2013 Hi all, I need a "timer" with less than 50 miliseconds, I remember the function sleep() for Lua, but doesn't work in MTA, I use getTickCounts but I don't know how to use, see the code: function callTimer ( key, keyState ) if keyState == "down" then pos = 0 sleep = 1500 lastCount = getTickCount() while getTickCount() >= lastCount+sleep then if pos >= 100 then pos = 0 outputChatBox("test") unbindKey("n","both",callTimer) break end pos = pos + 1 outputChatBox(pos) lastCount = getTickCount() end elseif keyState == "up" then if pos < 100 then pos = 100 end end end bindKey("num_5","both",callTimer) I want that print the number every 1.5 seconds while I'm pressing the num_5 Link to comment
Spajk Posted November 5, 2013 Share Posted November 5, 2013 sorry, but why you need it less then 50 ms when you want to do it every 1.5 secs ? Link to comment
arezu Posted November 6, 2013 Share Posted November 6, 2013 I dont know what you want to achieve exactly with that code, but I guess you are trying to do something with animations, so you should use onClientRender and getKeyState (and/or bindKey and save the key state) instead in that case. onClientRender is called each frame, which means if you have 50 fps, then it will run each 1000/50 = 20ms. 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