DaBOSS54320

Bully LUA: GetTimer Examples

May 3rd, 2016
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | None | 0 0
  1. -- Example 1: delay
  2. function main()
  3.     local t -- defaults to nil without a specified value, this just declares it as local
  4.     while true do
  5.         if t and GetTimer() >= t + 3000 then -- if t is not nil and the timer is 3000ms past t...
  6.             TextPrintString("pointless delay thingy works",3,1)
  7.             t = nil -- make it nil again
  8.         elseif IsButtonBeingPressed(3,0) and not t then -- if button is pressed and t is nil...
  9.             t = GetTimer() -- set t to the current time
  10.         end
  11.         Wait(0)
  12.     end
  13. end
  14.  
  15. -- Example 2: opportunity
  16. function main()
  17.     TextPrintString("Get ready...",10,1)
  18.     Wait(math.random(2000,10000))
  19.     local t = GetTimer()
  20.     while GetTimer() < t + 1000 do -- while the time is less than 1000ms past the start time...
  21.         TextPrintString("NOW!",0,1) -- print text
  22.         Wait(0) -- show text and let bully process buttons
  23.         if IsButtonBeingPressed(3,0) then -- check if the nigga pressed it
  24.             MissionSucceed()
  25.         end
  26.     end
  27.     MissionFail()
  28. end
Advertisement
Add Comment
Please, Sign In to add comment