DizzasTeR-

Ignore/Unignore

Aug 10th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. g_Ignores <- {};
  2.  
  3. function onPlayerJoin( player ) {
  4.     g_Ignores.rawset( player.ID, {} );
  5. }
  6.  
  7. function onPlayerPart( player, reason ) {
  8.     if( g_Ignores.rawin( player.ID ) ) {
  9.         g_Ignores.rawdelete( player.ID );
  10.     }
  11. }
  12.  
  13. function onPlayerCommand( player, cmd, text ) {
  14.     if( cmd == "ignore" ) {
  15.         if( !text ) return MessagePlayer( "/ignore [ID/Name]", player );
  16.         local plr = ( !IsNum( text ) ? FindPlayer( text ) : FindPlayer( text.tointeger() ) );
  17.         if( !plr ) return MessagePlayer( "Invalid player", player );
  18.         else if( g_Ignores.rawget( player.ID ).rawin( plr.ID ) ) return MessagePlayer( format( "You are already ignoring %s", plr.Name ), player );
  19.         g_Ignores.rawget( player.ID ).rawset( plr.ID, true );
  20.         MessagePlayer( format( "You are not ignoring %s", plr.Name ), player );
  21.     }
  22.    
  23.     else if( cmd == "unignore" ) {
  24.         if( !text ) return MessagePlayer( "/unignore [ID/Name]", player );
  25.         local plr = ( !IsNum( text ) ? FindPlayer( text ) : FindPlayer( text.tointeger() ) );
  26.         if( !plr ) return MessagePlayer( "Invalid player", player );
  27.         else if( !g_Ignores.rawget( player.ID ).rawin( plr.ID ) ) return MessagePlayer( format( "You are not ignoring %s", plr.Name ), player );
  28.         g_Ignores.rawget( player.ID ).rawdelete( plr.ID );
  29.         MessagePlayer( format( "You are no longer ignoring %s", plr.Name ), player );
  30.     }
  31. }
  32.  
  33. function onPlayerChat( player, text ) {
  34.     local playerIgnores = g_Ignores.rawget( player.ID );
  35.     local MaxPlayers = GetMaxPlayers();
  36.     for( local i = 0; i <= MaxPlayers; i++ ) {
  37.         local plr = FindPlayer( i );
  38.         if( !plr ) continue;
  39.         local plrIgnores = g_Ignores.rawget( plr.ID );
  40.        
  41.         if( playerIgnores.rawin( plr.ID ) ) continue;
  42.         else if( plrIgnores.rawin( player.ID ) ) continue;
  43.         MessagePlayer( format( "%s: %s", player.Name, text ), plr );
  44.     }
  45.     return 0; //You must halt the event itself to avoid double chats
  46. }
Add Comment
Please, Sign In to add comment