animeisgay

lmaobox votelogger lua

Mar 11th, 2022 (edited)
2,088
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.53 KB | None | 0 0
  1. local options =
  2. {
  3.     -- print to console
  4.     console = true,
  5.  
  6.     -- say in party chat
  7.     partychat = true,
  8.  
  9.     -- print only votes in your team
  10.     onlymyteam = true,
  11. };
  12.  
  13. local function Log( text )
  14.     if( options.console ) then
  15.         print( "[lbox] " .. text );
  16.     end
  17.  
  18.     if( options.partychat ) then
  19.         client.Command( "say_party \"" .. text .. "\"", true );
  20.     end
  21. end
  22.  
  23. local function FireGameEvent( event )
  24.     if( event:GetName( ) ~= "vote_cast" ) then return end;
  25.  
  26.     -- https://wiki.alliedmods.net/Tf2_voting#vote_cast
  27.     local player = entities.GetByIndex( event:GetInt( "entityid" ) );
  28.     if( player == nil ) then return end;
  29.  
  30.     local me = entities.GetLocalPlayer( );
  31.     if( me == nil or me == player ) then return end;
  32.  
  33.     if( options.onlymyteam ) then
  34.         if( me:GetTeamNumber( ) ~= player:GetTeamNumber( ) ) then
  35.             return;
  36.         end
  37.     end
  38.  
  39.     -- 0 = F1, 1 = F2
  40.     local option = event:GetInt( "vote_option" );
  41.     if( option == 0 ) then
  42.         option = "F1";
  43.     else
  44.         option = "F2";
  45.     end
  46.  
  47.     local playerinfo = client.GetPlayerInfo( player:GetIndex( ) );
  48.     if( playerinfo == nil ) then return end;
  49.  
  50.     local playername = playerinfo.Name;
  51.     local steamid = playerinfo.SteamID;
  52.  
  53.     Log( playername .. " " .. steamid .. " pressed " .. option );
  54. end
  55.  
  56. client.AllowListener( "vote_cast" );
  57.  
  58. callbacks.Unregister( "FireGameEvent", "votelogger_FireGameEvent" );
  59. callbacks.Register( "FireGameEvent", "votelogger_FireGameEvent", FireGameEvent );
Add Comment
Please, Sign In to add comment