Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. local screen_w, screen_h
  2.  
  3. local kill_messages = { "", "DOUBLE KILL", "TRIPLE KILL", "QUADRA KILL", "PENTA KILL" }
  4. local kill_manager = { }
  5. local kill_count = 0
  6. local kill_message_font = draw.CreateFont( "Tahoma", 20, 700 )
  7.  
  8. local function clean_objects( )
  9. for i = #kill_manager, 1, -1 do
  10. table.remove( kill_manager, i )
  11. end
  12. kill_count = 0
  13. end
  14.  
  15. local function kill_count_clamp( value )
  16. if ( value > #kill_messages ) then
  17. return #kill_messages
  18. else
  19. return value
  20. end
  21. end
  22.  
  23. local function game_event_listener( event )
  24. if ( event:GetName() == "round_start" or event:GetName() == "game_start" ) then
  25. clean_objects( )
  26. end
  27.  
  28. if ( event:GetName() == "player_death" ) then
  29. local local_player_index = client.GetLocalPlayerIndex( )
  30.  
  31. local attacker_uid = event:GetInt( 'attacker' )
  32. local attacker_index = client.GetPlayerIndexByUserID( attacker_uid )
  33.  
  34. if ( local_player_index == attacker_index ) then
  35. kill_count = kill_count + 1
  36.  
  37. kill_manager[#kill_manager + 1] = {
  38. x = screen_w / 2,
  39. y = screen_h / 2,
  40. angle = math.rad( math.random( 0, 360 ) ),
  41. string = kill_messages[kill_count_clamp( kill_count )],
  42. adjusted = false
  43. }
  44. end
  45. end
  46. end
  47.  
  48. client.AllowListener( "player_death" )
  49. callbacks.Register( "FireGameEvent", game_event_listener )
  50.  
  51. local function draw_text( x, y, font, string, r, g, b, a )
  52. draw.SetFont( font )
  53. draw.Color( r, g, b, a )
  54. draw.Text( x, y, string )
  55. end
  56.  
  57. local function check_screen_bound( x, y, size_x, size_y )
  58. if ( x > 0 and x + size_x < screen_w and y > 0 and y + size_y < screen_h ) then
  59. return true
  60. else
  61. return false
  62. end
  63. end
  64.  
  65. local function center_string( object, size_x, size_y )
  66. object.x = object.x - size_x
  67. object.y = object.y - size_y
  68. object.adjusted = true
  69. end
  70.  
  71. local function draw_messages( )
  72. if ( not engine.GetServerIP( ) ) then
  73. clean_objects( )
  74. return
  75. end
  76.  
  77. screen_w, screen_h = draw.GetScreenSize( )
  78.  
  79. for i = #kill_manager, 1, -1 do
  80. local string_size_x, string_size_y = draw.GetTextSize( kill_manager[i].string )
  81.  
  82. if ( not kill_manager[i].adjusted ) then
  83. center_string( kill_manager[i], string_size_x, string_size_y )
  84. end
  85.  
  86. local x = math.sin( kill_manager[i].angle ) * 1.5
  87. local y = math.cos( kill_manager[i].angle ) * 1.5
  88. kill_manager[i].x = kill_manager[i].x + x
  89. kill_manager[i].y = kill_manager[i].y + y
  90.  
  91. local in_screen_bounds = check_screen_bound( kill_manager[i].x, kill_manager[i].y, string_size_x, string_size_y )
  92.  
  93. if ( in_screen_bounds ) then
  94. draw_text( kill_manager[i].x, kill_manager[i].y, kill_message_font, kill_manager[i].string, 255, 255, 255, 255 )
  95. elseif ( not in_screen_bounds ) then
  96. table.remove( kill_manager, i )
  97. end
  98. end
  99. end
  100.  
  101. callbacks.Register( "Draw", draw_messages )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement