DaBOSS54320

Bully LUA: TEXT_Print

Dec 3rd, 2015
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.39 KB | None | 0 0
  1. -- This is a text management system for LUA scripting in Bully. It consists of 3 functions that can be used in place of TextPrintString. The goal is to be able to check when text is already on screen and to prevent a call to TextPrintString from overwriting the text from a previous call.
  2. -- All the following code should be put in the script that you wish to use this text management system on, and put outside of any other functions so it only runs once (unless you know what you're doing and have other plans on how to use it).
  3. -- The table t_textPrint holds information about what text is already printed on screen.
  4. -- The TEXT_Print function takes the same arguments as TextPrintString and will only print text if there isn't already text on screen. If it prints successfully, the function will return true, and otherwise return false.
  5. -- The TEXT_ForcePrint function works similarly to TEXT_Print, only it will print no matter if there is already text on screen or not. It does not return any value as it is already guaranteed to print successfully every time.
  6. -- The TEXT_CanPrint function can be used to check if text can be printed or not. It takes 1 argument, style: 1 for the top of the screen and 2 for the bottom, just like the normal TextPrintString's style argument. It returns true if text can be printed and false otherwise. It basically performs the same check as TEXT_Print does before printing text but of course without printing any text.
  7. -- Note: If TextPrintString is used normally (that is without being called through one of the functions provided here), the t_textPrint table will not be updated and the script will be unaware of any text being on screen. You must always use the 3 functions provided here if you want the system to work properly and never TextPrintString by itself (unless of course you have good reason to and understand the effects).
  8.  
  9. t_textPrint = {{0,0},{0,0}}
  10. function TEXT_Print(text,seconds,style)
  11.     if GetTimer() - t_textPrint[style][2] > t_textPrint[style][1] then
  12.         TextPrintString(text,seconds,style)
  13.         t_textPrint[style][1] = GetTimer()
  14.         t_textPrint[style][2] = seconds*1000
  15.         return true
  16.     end
  17.     return false
  18. end
  19. function TEXT_ForcePrint(text,seconds,style)
  20.     TextPrintString(text,seconds,style)
  21.     t_textPrint[style][1] = GetTimer()
  22.     t_textPrint[style][2] = seconds*1000
  23. end
  24. function TEXT_CanPrint(style)
  25.     return GetTimer() - t_textPrint[style][2] > t_textPrint[style][1]
  26. end
Advertisement
Add Comment
Please, Sign In to add comment