Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local screen_w, screen_h
- local kill_messages = { "", "DOUBLE KILL", "TRIPLE KILL", "QUADRA KILL", "PENTA KILL" }
- local kill_manager = { }
- local kill_count = 0
- local kill_message_font = draw.CreateFont( "Tahoma", 20, 700 )
- local function clean_objects( )
- for i = #kill_manager, 1, -1 do
- table.remove( kill_manager, i )
- end
- kill_count = 0
- end
- local function kill_count_clamp( value )
- if ( value > #kill_messages ) then
- return #kill_messages
- else
- return value
- end
- end
- local function game_event_listener( event )
- if ( event:GetName() == "round_start" or event:GetName() == "game_start" ) then
- clean_objects( )
- end
- if ( event:GetName() == "player_death" ) then
- local local_player_index = client.GetLocalPlayerIndex( )
- local attacker_uid = event:GetInt( 'attacker' )
- local attacker_index = client.GetPlayerIndexByUserID( attacker_uid )
- if ( local_player_index == attacker_index ) then
- kill_count = kill_count + 1
- kill_manager[#kill_manager + 1] = {
- x = screen_w / 2,
- y = screen_h / 2,
- angle = math.rad( math.random( 0, 360 ) ),
- string = kill_messages[kill_count_clamp( kill_count )],
- adjusted = false
- }
- end
- end
- end
- client.AllowListener( "player_death" )
- callbacks.Register( "FireGameEvent", game_event_listener )
- local function draw_text( x, y, font, string, r, g, b, a )
- draw.SetFont( font )
- draw.Color( r, g, b, a )
- draw.Text( x, y, string )
- end
- local function check_screen_bound( x, y, size_x, size_y )
- if ( x > 0 and x + size_x < screen_w and y > 0 and y + size_y < screen_h ) then
- return true
- else
- return false
- end
- end
- local function center_string( object, size_x, size_y )
- object.x = object.x - size_x
- object.y = object.y - size_y
- object.adjusted = true
- end
- local function draw_messages( )
- if ( not engine.GetServerIP( ) ) then
- clean_objects( )
- return
- end
- screen_w, screen_h = draw.GetScreenSize( )
- for i = #kill_manager, 1, -1 do
- local string_size_x, string_size_y = draw.GetTextSize( kill_manager[i].string )
- if ( not kill_manager[i].adjusted ) then
- center_string( kill_manager[i], string_size_x, string_size_y )
- end
- local x = math.sin( kill_manager[i].angle ) * 1.5
- local y = math.cos( kill_manager[i].angle ) * 1.5
- kill_manager[i].x = kill_manager[i].x + x
- kill_manager[i].y = kill_manager[i].y + y
- local in_screen_bounds = check_screen_bound( kill_manager[i].x, kill_manager[i].y, string_size_x, string_size_y )
- if ( in_screen_bounds ) then
- draw_text( kill_manager[i].x, kill_manager[i].y, kill_message_font, kill_manager[i].string, 255, 255, 255, 255 )
- elseif ( not in_screen_bounds ) then
- table.remove( kill_manager, i )
- end
- end
- end
- callbacks.Register( "Draw", draw_messages )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement