Advertisement
Guest User

essentials.lua

a guest
Jan 28th, 2017
3,126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.49 KB | None | 0 0
  1. -- DrawText method wrapper, draws text to the screen.
  2. -- @param1  string  The text to draw
  3. -- @param2  float   Screen x-axis coordinate
  4. -- @param3  float   Screen y-axis coordinate
  5. -- @param4  table   Optional. Styles to apply to the text
  6. -- @return
  7. function drawText( str, x, y, style )
  8.     if style == nil then
  9.         style = {}
  10.     end
  11.    
  12.     SetTextFont( (style.font ~= nil) and style.font or 0 )
  13.     SetTextScale( 0.0, (style.size ~= nil) and style.size or 1.0 )
  14.     SetTextProportional( 1 )
  15.    
  16.     if style.colour ~= nil then
  17.         SetTextColour( style.colour.r ~= nil and style.colour.r or 255, style.colour.g ~= nil and style.colour.g or 255, style.colour.b ~= nil and style.colour.b or 255, style.colour.a ~= nil and style.colour.a or 255 )
  18.     else
  19.         SetTextColour( 255, 255, 255, 255 )
  20.     end
  21.    
  22.     if style.shadow ~= nil then
  23.         SetTextDropShadow( style.shadow.distance ~= nil and style.shadow.distance or 0, style.shadow.r ~= nil and style.shadow.r or 0, style.shadow.g ~= nil and style.shadow.g or 0, style.shadow.b ~= nil and style.shadow.b or 0, style.shadow.a ~= nil and style.shadow.a or 255 )
  24.     else
  25.         SetTextDropShadow( 0, 0, 0, 0, 255 )
  26.     end
  27.    
  28.     if style.border ~= nil then
  29.         SetTextEdge( style.border.size ~= nil and style.border.size or 1, style.border.r ~= nil and style.border.r or 0, style.border.g ~= nil and style.border.g or 0, style.border.b ~= nil and style.border.b or 0, style.border.a ~= nil and style.shadow.a or 255 )
  30.     end
  31.    
  32.     if style.centered ~= nil and style.centered == true then
  33.         SetTextCentre( true )
  34.     end
  35.    
  36.     if style.outline ~= nil and style.outline == true then
  37.         SetTextOutline()
  38.     end
  39.    
  40.     SetTextEntry( "STRING" )
  41.     AddTextComponentString( str )
  42.    
  43.     DrawText( x, y )
  44. end
  45.  
  46. -- Converts degrees to (inter)cardinal directions.
  47. -- @param1  float   Degrees. Expects EAST to be 90° and WEST to be 270°.
  48. --                  In GTA, WEST is usually 90°, EAST is usually 270°. To convert, subtract that value from 360.
  49. --
  50. -- @return          The converted (inter)cardinal direction.
  51. function degreesToIntercardinalDirection( dgr )
  52.     dgr = dgr % 360.0
  53.    
  54.     if (dgr >= 0.0 and dgr < 22.5) or dgr >= 337.5 then
  55.         return "N "
  56.     elseif dgr >= 22.5 and dgr < 67.5 then
  57.         return "NE"
  58.     elseif dgr >= 67.5 and dgr < 112.5 then
  59.         return "E"
  60.     elseif dgr >= 112.5 and dgr < 157.5 then
  61.         return "SE"
  62.     elseif dgr >= 157.5 and dgr < 202.5 then
  63.         return "S"
  64.     elseif dgr >= 202.5 and dgr < 247.5 then
  65.         return "SW"
  66.     elseif dgr >= 247.5 and dgr < 292.5 then
  67.         return "W"
  68.     elseif dgr >= 292.5 and dgr < 337.5 then
  69.         return "NW"
  70.     end
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement