Advertisement
RanAway

[ Pawn ] brightness menu

May 23rd, 2022 (edited)
1,638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.29 KB | None | 0 0
  1. //------------------------------------------------------------------//
  2. //                      EPILEPSY WARNING!!!!!                       //
  3. //      This code contains flashing visual effects that may         //
  4. //      trigger symptoms of an epileptic seizure in sensitive       //
  5. //      users. Please exercise caution if you are sensitive         //
  6. //                      to flashing lights.                         //
  7. //------------------------------------------------------------------//
  8.  
  9. //-------------------- Includes --------------------//
  10. #include < amxmodx >
  11.  
  12. //-------------------- Defines --------------------//
  13. #define Prefix                      "AMXX"
  14. #define ADMIN_ACCESS                ADMIN_IMMUNITY
  15.  
  16. //-------------------- Effect list --------------------//
  17. enum _:EffectInfo { effectname[ 64 ], effectid[ 66 ] }
  18. new Effectlist[][ EffectInfo ] =
  19. {
  20.     {   "NORMAL",                       "m"                                                     }// normal
  21.     {   "UNDERWATER LIGHT MUTATION",    "UNDERWATER LIGHT MUTATION"                             }// UNDERWATER LIGHT MUTATION
  22.     {   "GENTLE PULSE 1",               "jklmnopqrstuvwxyzyxwvutsrqponmlkj"                     }// GENTLE PULSE 1
  23.     {   "SLOW STROBE",                  "aaaaaaaazzzzzzzz"                                      }// SLOW STROBE (fourth variety)
  24.     {   "FAST STROBE",                  "mamamamamama"                                          }// FAST STROBE
  25.     {   "SLOW STRONG PULSE",            "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba"   }// SLOW STRONG PULSE
  26.     {   "SLOW PULSE NOT FADE TO BLACK", "abcdefghijklmnopqrrqponmlkjihgfedcba"                  }// SLOW PULSE NOT FADE TO BLACK
  27.     {   "FLICKER #1",                   "mmnmmommommnonmmonqnmmo"                               }// FLICKER (first variety)
  28.     {   "FLICKER #2",                   "nmonqnmomnmomomno"                                     }// FLICKER (second variety)
  29.     {   "FLUORESCENT FLICKER",          "mmamammmmammamamaaamammma"                             }// FLUORESCENT FLICKER
  30.     {   "CANDLE #1",                    "mmmmmaaaaammmmmaaaaaabcdefgabcdefg"                    }// CANDLE (first variety)
  31.     {   "CANDLE #2",                    "mmmaaaabcdefgmmmmaaaammmaamm"                          }// CANDLE (second variety)
  32.     {   "CANDLE #3",                    "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa"            }   // CANDLE (third variety)
  33. }
  34.  
  35. //-------------------- Functions --------------------//
  36. new bool: letterprecentage = false, bool: specialeffect = false, bool: typemenu[ 33 ]
  37. new Lights[ 33 ][ 26 ], SLights[ 33 ], page[ 33 ], RememberPlayer[ 33 ]
  38.  
  39. //-------------------- Plugin init --------------------//
  40. public plugin_init()
  41. {
  42.     register_plugin( "Advanced Brightness", "v1.0", "RanAway`" )
  43.    
  44.     //-------------------- Commands --------------------//
  45.     register_clcmd( "say /brightness", "BrightnessMenu" )
  46.     register_clcmd( "nightvision", "BrightnessMenu" )
  47. }
  48.  
  49. //-------------------- Authorized --------------------//
  50. public client_authorized( id ) Lights[ id ][ 0 ] = 'm', SLights[ id ] = 0
  51.  
  52. //-------------------- Brightness menu --------------------//
  53. public BrightnessMenu( id )
  54. {
  55.     new item[ 200 ], output[ 90 ]
  56.  
  57.     //-------------------- Organize the menu --------------------//
  58.     if( SLights[ id ] != 0 )
  59.         formatex( output, charsmax( output ), Effectlist[ SLights[ id ] ][ effectname ] )
  60.     else
  61.         get_brightness_string( Lights[ id ][ 0 ], output )
  62.    
  63.     formatex( item, charsmax( item ), "\r[\w %s \r]\w Brightness adjuster", Prefix )
  64.     new menu = menu_create( item, "sub_brightness" )
  65.    
  66.     menu_additem( menu, "Light", _, .callback = menu_makecallback( "blockmenu" ) )
  67.     menu_additem( menu, "Dark", _, .callback = menu_makecallback( "blockmenu" ) )
  68.     menu_additem( menu, "Normal^n", _, .callback = menu_makecallback( "blockmenu" ) )
  69.    
  70.     menu_additem( menu, "Custom \r+", _, .callback = menu_makecallback( "blockmenu" ) )
  71.     menu_additem( menu, "Custom \r-^n", _, .callback = menu_makecallback( "blockmenu" ) )
  72.    
  73.     formatex( item, charsmax( item ), "%sSpecial effects", SLights[ id ] != 0 ? "\y" : "\d" )
  74.     menu_additem( menu, item, _, .callback = menu_makecallback( "blockmenu" ) )
  75.  
  76.     menu_additem( menu, "Admin options^n", _, ADMIN_ACCESS )
  77.    
  78.     formatex( item, charsmax( item ), "\r<<< %s%s \r>>>", SLights[ id ] != 0 ? "\y" : "\d", output )
  79.     menu_addtext( menu, item, 0 )
  80.  
  81.     menu_display( id, menu )
  82.     return 1
  83. }
  84.  
  85. public blockmenu( id, menu, item )
  86. {
  87.     if( ( item == 0 && ( SLights[ id ] == 0 && Lights[ id ][ 0 ] == 'z' ) )
  88.     || ( item == 1 && ( SLights[ id ] == 0 && Lights[ id ][ 0 ] == 'a' ) )
  89.     || ( item == 2 && ( SLights[ id ] == 0 && Lights[ id ][ 0 ] == 'm' ) )
  90.     || ( item == 3 && ( SLights[ id ] != 0 || Lights[ id ][ 0 ] == 'z' ) )
  91.     || ( item == 4 && ( SLights[ id ] != 0 || Lights[ id ][ 0 ] == 'a' ) )
  92.     || ( item == 5 && specialeffect == false ) )
  93.         return ITEM_DISABLED
  94.  
  95.     return 1
  96. }
  97.  
  98. public sub_brightness( id, menu, item )
  99. {
  100.     if( item == MENU_EXIT ) return menu_destroy( menu )
  101.    
  102.     if( item == 0 ) Lights[ id ][ 0 ] = 'z', SLights[ id ] = 0
  103.     if( item == 1 ) Lights[ id ][ 0 ] = 'a', SLights[ id ] = 0
  104.     if( item == 2 ) Lights[ id ][ 0 ] = 'm', SLights[ id ] = 0
  105.     if( item == 3 ) if( Lights[ id ][ 0 ]++ > 'z' ) Lights[ id ][ 0 ] = 'z'
  106.     if( item == 4 ) if( Lights[ id ][ 0 ]-- < 'a' ) Lights[ id ][ 0 ] = 'a'
  107.     if( item == 5 )
  108.     {
  109.         //-------------------- Make sure the light set right --------------------//
  110.         if( SLights[ id ]++ >= charsmax( Effectlist ) )
  111.         {
  112.             SLights[ id ] = 0
  113.             set_light( id, Lights[ id ][ 0 ] )
  114.         }
  115.         else set_light( id, Effectlist[ SLights[ id ] ][ effectid ] )
  116.        
  117.         return BrightnessMenu( id )
  118.     }
  119.     if( item == 6 ) return AdminOptions( id )
  120.    
  121.     set_light( id, Lights[ id ][ 0 ] )
  122.     return BrightnessMenu( id )
  123. }
  124.  
  125. //-------------------- Admin options menu --------------------//
  126. public AdminOptions( id )
  127. {
  128.     //-------------------- Access to the menu & prevent heap low --------------------//
  129.     if( !( get_user_flags( id ) & ADMIN_ACCESS ) || !is_user_connected( id ) ) return 0
  130.  
  131.     new item[ 300 ], warning[ 200 ]
  132.  
  133.     add( warning, charsmax( warning ), "\d^n----------------- \rEPILEPSY WARNING!!!!!!!! \d------------------^n" )
  134.     add( warning, charsmax( warning ), "\r-\y Flashing effects ahead; may cause seizures.^n" )
  135.     add( warning, charsmax( warning ), "\r-\y Sensitive users should exercise caution.^n" )
  136.  
  137.     formatex( item, charsmax( item ), "\r[\w %s \r]\w Admin options", Prefix )
  138.     new menu = menu_create( item, "sub_adminoptions" )
  139.    
  140.     menu_additem( menu, "select player", _, .callback = menu_makecallback( "blockselect" ) )
  141.     menu_additem( menu, "Change for all^n" )
  142.  
  143.     formatex( item, charsmax( item ), "\r<<< \w%s \r>>>^n%s", letterprecentage ? "Letters" : "Precentage", warning )
  144.     menu_additem( menu, item )
  145.    
  146.     formatex( item, charsmax( item ), "Special effects: %s", specialeffect ? "\ractivated" : "\ydeactivated" )
  147.     menu_additem( menu, item )
  148.  
  149.     menu_setprop( menu, MPROP_EXITNAME, "back" )
  150.     menu_display( id, menu )
  151.     return 1
  152. }
  153.  
  154. public blockselect( id, menu, item )
  155. {
  156.     //-------------------- block the button "select player" if there is no one ( not include you ) online --------------------//
  157.     new playercounter = 0
  158.     for( new i = 1; i <= get_maxplayers(); i++ )
  159.     {
  160.         //-------------------- If the player is not connected or yourself --------------------//
  161.         if( !is_user_connected( i ) || i == id ) continue
  162.  
  163.         playercounter++
  164.     }
  165.  
  166.     if( playercounter == 0 ) return ITEM_DISABLED
  167.     return 1
  168. }
  169.  
  170. public sub_adminoptions( id, menu, item )
  171. {
  172.     //-------------------- Access to the menu --------------------//
  173.     if( !( get_user_flags( id ) & ADMIN_ACCESS ) ) return 0
  174.  
  175.     if( item == MENU_EXIT ) return BrightnessMenu( id )
  176.    
  177.     if( item == 0 ) return typemenu[ id ] = true, page[ id ] = 0, selectplayer( id )
  178.     if( item == 1 ) return typemenu[ id ] = false, adminbrightness( id )
  179.     if( item == 2 ) letterprecentage = !letterprecentage
  180.     if( item == 3 ) specialeffect = !specialeffect
  181.    
  182.     return AdminOptions( id )
  183. }
  184.  
  185. //-------------------- selecting menu --------------------//
  186. public selectplayer( id )
  187. {
  188.     //-------------------- Access to the menu & prevent heap low --------------------//
  189.     if( !( get_user_flags( id ) & ADMIN_ACCESS ) || !is_user_connected( id ) ) return 0
  190.  
  191.     new item[ 200 ], data[ 6 ]
  192.    
  193.     formatex( item, charsmax( item ), "\r[\w %s \r]\w select player", Prefix )
  194.     new menu = menu_create( item, "sub_chooseplayer" )
  195.    
  196.     for( new i = 1; i <= get_maxplayers(); i++ )
  197.     {
  198.         //-------------------- If the player is not connected or yourself --------------------//
  199.         if( !is_user_connected( i ) || i == id ) continue
  200.  
  201.         num_to_str( i, data, charsmax( data ) )
  202.         menu_additem( menu, GetName( i ), data )
  203.     }
  204.  
  205.     //-------------------- Previous / Next / Exit --------------------//
  206.     if( menu_items( menu ) > 7 )
  207.     {
  208.         menu_setprop( menu, MPROP_NEXTNAME, "next page" )
  209.         menu_setprop( menu, MPROP_BACKNAME, "previous page" )
  210.     }
  211.     menu_setprop( menu, MPROP_EXITNAME, "back" )
  212.     menu_display( id, menu, page[ id ] )
  213.     return 1
  214. }
  215.  
  216. public sub_chooseplayer( id, menu, item )
  217. {
  218.     //-------------------- Access to the menu --------------------//
  219.     if( !( get_user_flags( id ) & ADMIN_ACCESS ) ) return 0
  220.    
  221.     if( item == MENU_EXIT ) return AdminOptions( id )
  222.    
  223.     //-------------------- Get player info --------------------//
  224.     new access, data[ 6 ], name[ 32 ]
  225.     menu_item_getinfo( menu, item, access, data, charsmax( data ), name, charsmax( name ), access )
  226.     player_menu_info( id, menu, menu, page[ id ] )
  227.  
  228.     //-------------------- Remember player's data --------------------//
  229.     RememberPlayer[ id ] = str_to_num( data )
  230.  
  231.     //-------------------- If the player is not connected --------------------//
  232.     if( !is_user_connected( RememberPlayer[ id ] ) ) return selectplayer( id )
  233.  
  234.     return adminbrightness( id )
  235. }
  236.  
  237. //-------------------- Admin brightness menu --------------------//
  238. public adminbrightness( id )
  239. {
  240.     //-------------------- Access to the menu & prevent heap low --------------------//
  241.     if( !( get_user_flags( id ) & ADMIN_ACCESS ) || !is_user_connected( id ) ) return 0
  242.  
  243.     new item[ 200 ], output[ 90 ], text[ 33 ], player = typemenu[ id ] ? RememberPlayer[ id ] : id
  244.    
  245.     //-------------------- Organize the menu --------------------//
  246.     if( typemenu[ id ] )
  247.         formatex( text, charsmax( text ), "%s", GetName( player ) )
  248.     else
  249.         formatex( text, charsmax( text ), "everyone" )
  250.    
  251.     if( SLights[ player ] != 0 || specialeffect == false )
  252.         formatex( output, charsmax( output ), Effectlist[ SLights[ player ] ][ effectname ] )
  253.     else
  254.         get_brightness_string( Lights[ player ][ 0 ], output )
  255.    
  256.     formatex( item, charsmax( item ), "\r[\w %s \r]\w Brightness adjuster for: \r%s", Prefix, text )
  257.     new menu = menu_create( item, "sub_adminbrightness" )
  258.    
  259.     menu_additem( menu, "Light", _, .callback = menu_makecallback( "blockadminmenu" ) )
  260.     menu_additem( menu, "Dark", _, .callback = menu_makecallback( "blockadminmenu" ) )
  261.     menu_additem( menu, "Normal^n", _, .callback = menu_makecallback( "blockadminmenu" ) )
  262.    
  263.     menu_additem( menu, "Custom \r+", _, .callback = menu_makecallback( "blockadminmenu" ) )
  264.     menu_additem( menu, "Custom \r-^n", _, .callback = menu_makecallback( "blockadminmenu" ) )
  265.  
  266.     formatex( item, charsmax( item ), "%sSpecial effects^n", SLights[ id ] != 0 ? "\y" : "\d" )
  267.     menu_additem( menu, item, _, .callback = menu_makecallback( "blockadminmenu" ) )
  268.  
  269.     formatex( item, charsmax( item ), "\r<<< %s%s \r>>>", SLights[ id ] != 0 ? "\y" : "\d", output )
  270.     menu_addtext( menu, item )
  271.    
  272.     menu_setprop( menu, MPROP_EXITNAME, "back" )
  273.     menu_display( id, menu )
  274.     return 1
  275. }
  276.  
  277. public blockadminmenu( id, menu, item )
  278. {
  279.     new player = typemenu[ id ] ? RememberPlayer[ id ] : id
  280.     if( ( item == 0 && ( SLights[ player ] == 0 && Lights[ player ][ 0 ] == 'z' ) )
  281.     || ( item == 1 && ( SLights[ player ] == 0 && Lights[ player ][ 0 ] == 'a' ) )
  282.     || ( item == 2 && ( SLights[ player ] == 0 && Lights[ player ][ 0 ] == 'm' ) )
  283.     || ( item == 3 && ( SLights[ player ] != 0 || Lights[ player ][ 0 ] == 'z' ) )
  284.     || ( item == 4 && ( SLights[ player ] != 0 || Lights[ player ][ 0 ] == 'a' ) )
  285.     || ( item == 5 && specialeffect == false ) )
  286.         return ITEM_DISABLED
  287.  
  288.     return 1
  289. }
  290.  
  291. public sub_adminbrightness( id, menu, item )
  292. {
  293.     //-------------------- Access to the menu --------------------//
  294.     if( !( get_user_flags( id ) & ADMIN_ACCESS ) ) return 0
  295.    
  296.     if( item == MENU_EXIT ) return typemenu[ id ] ? selectplayer( id ) : AdminOptions( id )
  297.    
  298.     new player = typemenu[ id ] ? RememberPlayer[ id ] : id
  299.  
  300.     if( item == 0 ) Lights[ player ][ 0 ] = 'z', SLights[ player ] = 0
  301.     if( item == 1 ) Lights[ player ][ 0 ] = 'a', SLights[ player ] = 0
  302.     if( item == 2 ) Lights[ player ][ 0 ] = 'm', SLights[ player ] = 0
  303.     if( item == 3 ) if( Lights[ player ][ 0 ]++ > 'z' ) Lights[ player ][ 0 ] = 'z'
  304.     if( item == 4 ) if( Lights[ player ][ 0 ]-- < 'a' ) Lights[ player ][ 0 ] = 'a'
  305.     if( item == 5 )
  306.     {
  307.         //-------------------- Make sure the light set right - everyone --------------------//
  308.         if( !typemenu[ id ] )
  309.         {
  310.             SLights[ player ]++
  311.             for( new i = 1; i <= get_maxplayers(); i++ )
  312.             {
  313.                 if( !is_user_connected( i ) ) continue
  314.  
  315.                 if( SLights[ player ] >= charsmax( Effectlist ) )
  316.                 {
  317.                     SLights[ player ] = 0
  318.                     set_light( i, Lights[ player ][ 0 ] )
  319.                 }
  320.                 else SLights[ i ] = SLights[ player ], set_light( i, Effectlist[ SLights[ player ] ][ effectid ] )
  321.             }
  322.         }
  323.         //-------------------- Make sure the light set right - selected player --------------------//
  324.         else
  325.         {
  326.                 if( SLights[ player ]++ >= charsmax( Effectlist ) )
  327.                 {
  328.                     SLights[ player ] = 0
  329.                     set_light( player, Lights[ player ][ 0 ] )
  330.                 }
  331.                 else set_light( player, Effectlist[ SLights[ player ] ][ effectid ] )
  332.         }
  333.         return adminbrightness( id )
  334.     }
  335.    
  336.     if( !typemenu[ id ] )
  337.     {
  338.         for( new i = 1; i <= get_maxplayers(); i++ )
  339.         {
  340.             if( !is_user_connected( i ) ) continue
  341.            
  342.             Lights[ i ][ 0 ] = Lights[ player ][ 0 ]
  343.             set_light( i, Lights[ player ][ 0 ] )
  344.         }
  345.     }
  346.     else set_light( player, Lights[ player ][ 0 ] )
  347.  
  348.     return adminbrightness( id )
  349. }
  350.  
  351. //-------------------- Stocks --------------------//
  352. GetName( id )
  353. {
  354.     new name[ 33 ]
  355.     get_user_name( id, name, charsmax( name ) )
  356.     return name
  357. }
  358.  
  359. stock get_brightness_string( input, output[] )
  360. {
  361.     new multiplier = 100, pos = 0
  362.     for( new i = 0; i < 26; i++ )
  363.     {
  364.         //------------- letters --------------//
  365.         if( letterprecentage )
  366.         {
  367.             if( i == input - 'a' )
  368.                 pos += formatex( output[ pos ], 90 - pos, "\y%c\d", 'a' + i )
  369.             else
  370.                 pos += formatex( output[ pos ], 90 - pos, "%c", 'a' + i )
  371.         }
  372.         //------------- precentage --------------//
  373.         else
  374.         {
  375.             if( i == input - 'a' )
  376.             {
  377.                 pos = formatex( output[ pos ], 90 - pos, "\y%d%%\d", ( ( input - 'a' ) * multiplier ) / 25 )
  378.                 break
  379.             }
  380.         }
  381.     }
  382.     output[ pos ] = EOS
  383. }
  384.  
  385. stock set_light( id, const light[] )
  386. {
  387.     message_begin( MSG_ONE_UNRELIABLE, SVC_LIGHTSTYLE, .player = id )
  388.     write_byte( 0 )
  389.     write_string( light )
  390.     message_end()
  391. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement