Advertisement
RanAway

[ Pawn - advanced plugins ] brightness menu

May 23rd, 2022 (edited)
1,648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.11 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[ 32 ], effectid[ 64 ] }
  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 output[ 90 ], menu = menu_create( fmt( "\r[\w %s \r]\w Brightness adjuster", Prefix ), "sub_brightness" )
  56.  
  57.     //-------------------- Organize the menu --------------------//
  58.     if( SLights[ id ] != 0 ) formatex( output, charsmax( output ), Effectlist[ SLights[ id ] ][ effectname ] )
  59.     else get_brightness_string( Lights[ id ][ 0 ], output )
  60.  
  61.     SLights[ id ] == 0 && Lights[ id ][ 0 ] == 'z' ? menu_addtext2( menu, "\r1. \dLight" ) : menu_additem( menu, "Light" )
  62.     SLights[ id ] == 0 && Lights[ id ][ 0 ] == 'a' ? menu_addtext2( menu, "\r2. \dDark" ) : menu_additem( menu, "Dark" )
  63.     SLights[ id ] == 0 && Lights[ id ][ 0 ] == 'm' ? menu_addtext2( menu, "\r3. \dNormal^n" ) : menu_additem( menu, "Normal^n" )
  64.  
  65.     SLights[ id ] != 0 || Lights[ id ][ 0 ] == 'z' ? menu_addtext2( menu, "\r4. \dCustom \r+" ) : menu_additem( menu, "Custom \r+" )
  66.     SLights[ id ] != 0 || Lights[ id ][ 0 ] == 'a' ? menu_addtext2( menu, "\r5. \dCustom \r-^n" ) : menu_additem( menu, "Custom \r-^n" )
  67.  
  68.     !specialeffect ? menu_addtext2( menu, "\d6. \dSpecial effects" ) : menu_additem( menu, fmt( "%sSpecial effects", SLights[ id ] != 0 ? "\y" : "\d" ) )
  69.  
  70.     ~get_user_flags( id ) & ADMIN_ACCESS ? menu_addtext2( menu, "\r7. \dAdmin options^n" ) : menu_additem( menu, "Admin options^n" )
  71.  
  72.     menu_addtext( menu, fmt( "\r<<< %s%s \r>>>", SLights[ id ] != 0 ? "\y" : "\d", output ), 0 )
  73.  
  74.     menu_display( id, menu )
  75.     return 1
  76. }
  77.  
  78. public sub_brightness( id, menu, item )
  79. {
  80.     if( item == MENU_EXIT ) return menu_destroy( menu )
  81.  
  82.     if( item == 0 ) Lights[ id ][ 0 ] = 'z', SLights[ id ] = 0
  83.     if( item == 1 ) Lights[ id ][ 0 ] = 'a', SLights[ id ] = 0
  84.     if( item == 2 ) Lights[ id ][ 0 ] = 'm', SLights[ id ] = 0
  85.     if( item == 3 && Lights[ id ][ 0 ]++ > 'z' ) Lights[ id ][ 0 ] = 'z'
  86.     if( item == 4 && Lights[ id ][ 0 ]-- < 'a' ) Lights[ id ][ 0 ] = 'a'
  87.     if( item == 5 )
  88.     {
  89.         //-------------------- Make sure the light set right --------------------//
  90.         if( SLights[ id ]++ >= charsmax( Effectlist ) )
  91.         {
  92.             SLights[ id ] = 0
  93.             set_light( id, Lights[ id ][ 0 ] )
  94.         }
  95.         else set_light( id, Effectlist[ SLights[ id ] ][ effectid ] )
  96.  
  97.         return BrightnessMenu( id )
  98.     }
  99.     if( item == 6 ) return AdminOptions( id )
  100.  
  101.     set_light( id, Lights[ id ][ 0 ] )
  102.     return BrightnessMenu( id )
  103. }
  104.  
  105. //-------------------- Admin options menu --------------------//
  106. public AdminOptions( id )
  107. {
  108.     //-------------------- Access to the menu & prevent heap low --------------------//
  109.     if( ~get_user_flags( id ) & ADMIN_ACCESS || !is_user_connected( id ) ) return 0
  110.  
  111.     new warning[ 512 ], menu = menu_create( fmt( "\r[\w %s \r]\w Admin options", Prefix ), "sub_adminoptions" )
  112.  
  113.     formatex( warning, charsmax( warning ), "\d^n----------------- \rEPILEPSY WARNING!!!!!!!! \d------------------^n" )
  114.     add( warning, charsmax( warning ), "\r-\y Flashing effects ahead; may cause seizures.^n" )
  115.     add( warning, charsmax( warning ), "\r-\y Sensitive users should exercise caution.^n" )
  116.  
  117.     get_playersnum() > 1 ? menu_addtext2( menu, "\r1. \dselect player" ) : menu_additem( menu, "select player" )
  118.     menu_additem( menu, "Change for all^n" )
  119.  
  120.     menu_additem( menu, fmt( "\r<<< \w%s \r>>>^n%s", letterprecentage ? "Letters" : "Precentage", warning ) )
  121.     menu_additem( menu, fmt( "Special effects: %s", specialeffect ? "\ractivated" : "\ydeactivated" ) )
  122.  
  123.     menu_setprop( menu, MPROP_EXITNAME, "back" )
  124.     menu_display( id, menu )
  125.     return 1
  126. }
  127.  
  128. public sub_adminoptions( id, menu, item )
  129. {
  130.     if( item == MENU_EXIT ) return BrightnessMenu( id )
  131.  
  132.     if( item == 0 ) return typemenu[ id ] = true, page[ id ] = 0, selectplayer( id )
  133.     if( item == 1 ) return typemenu[ id ] = false, adminbrightness( id )
  134.     if( item == 2 ) letterprecentage ^= true
  135.     if( item == 3 ) specialeffect ^= true
  136.  
  137.     return AdminOptions( id )
  138. }
  139.  
  140. //-------------------- selecting menu --------------------//
  141. public selectplayer( id )
  142. {
  143.     //-------------------- Access to the menu & prevent heap low --------------------//
  144.     if( ~get_user_flags( id ) & ADMIN_ACCESS || !is_user_connected( id ) ) return 0
  145.  
  146.     new data[ 6 ], menu = menu_create( fmt( "\r[\w %s \r]\w select player", Prefix ), "sub_chooseplayer" )
  147.  
  148.     for( new i = 1; i <= get_maxplayers(); i++ )
  149.     {
  150.         //-------------------- If the player is not connected or yourself --------------------//
  151.         if( !is_user_connected( i ) || i == id ) continue
  152.  
  153.         num_to_str( i, data, charsmax( data ) )
  154.         menu_additem( menu, fmt( "%n", i ), data )
  155.     }
  156.  
  157.     //-------------------- Previous / Next / Exit --------------------//
  158.     menu_setprop( menu, MPROP_NEXTNAME, "next page" )
  159.     menu_setprop( menu, MPROP_BACKNAME, "previous page" )
  160.     menu_setprop( menu, MPROP_EXITNAME, "back" )
  161.  
  162.     menu_display( id, menu, page[ id ] )
  163.     return 1
  164. }
  165.  
  166. public sub_chooseplayer( id, menu, item )
  167. {
  168.     if( item == MENU_EXIT ) return AdminOptions( id )
  169.  
  170.     //-------------------- Get player info --------------------//
  171.     new data[ 6 ]
  172.     menu_item_getinfo( menu, item, _, data, charsmax( data ) )
  173.     player_menu_info( id, menu, menu, page[ id ] )
  174.  
  175.     //-------------------- If the player is not connected --------------------//
  176.     if( !is_user_connected( str_to_num( data ) ) ) return selectplayer( id )
  177.  
  178.     //-------------------- Remember player's data --------------------//
  179.     RememberPlayer[ id ] = str_to_num( data )
  180.  
  181.     return adminbrightness( id )
  182. }
  183.  
  184. //-------------------- Admin brightness menu --------------------//
  185. public adminbrightness( id )
  186. {
  187.     //-------------------- Access to the menu & prevent heap low --------------------//
  188.     if( ~get_user_flags( id ) & ADMIN_ACCESS || !is_user_connected( id ) ) return 0
  189.  
  190.     new output[ 90 ], player = typemenu[ id ] ? RememberPlayer[ id ] : id
  191.     new menu = menu_create( fmt( "\r[\w %s \r]\w Brightness adjuster for: \r%s", Prefix, typemenu[ id ] ? fmt( "%n", RememberPlayer[ id ] ) : "everyone" ), "sub_adminbrightness" )
  192.  
  193.     //-------------------- Organize the menu --------------------//
  194.     if( SLights[ player ] != 0 || specialeffect == false ) formatex( output, charsmax( output ), Effectlist[ SLights[ player ] ][ effectname ] )
  195.     else get_brightness_string( Lights[ player ][ 0 ], output )
  196.  
  197.     SLights[ player ] == 0 && Lights[ player ][ 0 ] == 'z' ? menu_addtext2( menu, "\r1. \dLight" ) : menu_additem( menu, "Light" )
  198.     SLights[ player ] == 0 && Lights[ player ][ 0 ] == 'a' ? menu_addtext2( menu, "\r2. \dDark" ) : menu_additem( menu, "Dark" )
  199.     SLights[ player ] == 0 && Lights[ player ][ 0 ] == 'm' ? menu_addtext2( menu, "\r3. \dNormal^n" ) : menu_additem( menu, "Normal^n" )
  200.  
  201.     SLights[ player ] != 0 || Lights[ player ][ 0 ] == 'z' ? menu_addtext2( menu, "\r4. \dCustom \r+" ) : menu_additem( menu, "Custom \r+" )
  202.     SLights[ player ] != 0 || Lights[ player ][ 0 ] == 'a' ? menu_addtext2( menu, "\r5. \dCustom \r-^n" ) : menu_additem( menu, "Custom \r-^n" )
  203.  
  204.     !specialeffect ? menu_addtext2( menu, "\d6. \dSpecial effects^n" ) : menu_additem( menu, fmt( "%sSpecial effects^n", SLights[ id ] != 0 ? "\y" : "\d" ) )
  205.  
  206.     menu_addtext( menu, fmt( "\r<<< %s%s \r>>>", SLights[ id ] != 0 ? "\y" : "\d", output ) )
  207.  
  208.     menu_setprop( menu, MPROP_EXITNAME, "back" )
  209.     menu_display( id, menu )
  210.     return 1
  211. }
  212.  
  213. public sub_adminbrightness( id, menu, item )
  214. {
  215.     if( item == MENU_EXIT ) return typemenu[ id ] ? selectplayer( id ) : AdminOptions( id )
  216.  
  217.     new player = typemenu[ id ] ? RememberPlayer[ id ] : id
  218.  
  219.     if( item == 0 ) Lights[ player ][ 0 ] = 'z', SLights[ player ] = 0
  220.     if( item == 1 ) Lights[ player ][ 0 ] = 'a', SLights[ player ] = 0
  221.     if( item == 2 ) Lights[ player ][ 0 ] = 'm', SLights[ player ] = 0
  222.     if( item == 3 && Lights[ player ][ 0 ]++ > 'z' ) Lights[ player ][ 0 ] = 'z'
  223.     if( item == 4 && Lights[ player ][ 0 ]-- < 'a' ) Lights[ player ][ 0 ] = 'a'
  224.     if( item == 5 )
  225.     {
  226.         //-------------------- Make sure the light set right - everyone --------------------//
  227.         if( !typemenu[ id ] )
  228.         {
  229.             SLights[ player ]++
  230.             for( new i = 1; i <= get_maxplayers(); i++ )
  231.             {
  232.                 if( !is_user_connected( i ) ) continue
  233.  
  234.                 if( SLights[ player ] >= charsmax( Effectlist ) )
  235.                 {
  236.                     SLights[ player ] = 0
  237.                     set_light( i, Lights[ player ][ 0 ] )
  238.                 }
  239.                 else SLights[ i ] = SLights[ player ], set_light( i, Effectlist[ SLights[ player ] ][ effectid ] )
  240.             }
  241.         }
  242.         //-------------------- Make sure the light set right - selected player --------------------//
  243.         else
  244.         {
  245.             if( SLights[ player ]++ >= charsmax( Effectlist ) )
  246.             {
  247.                 SLights[ player ] = 0
  248.                 set_light( player, Lights[ player ][ 0 ] )
  249.             }
  250.             else set_light( player, Effectlist[ SLights[ player ] ][ effectid ] )
  251.         }
  252.         return adminbrightness( id )
  253.     }
  254.  
  255.     if( !typemenu[ id ] )
  256.     {
  257.         for( new i = 1; i <= get_maxplayers(); i++ )
  258.         {
  259.             if( !is_user_connected( i ) ) continue
  260.  
  261.             Lights[ i ][ 0 ] = Lights[ player ][ 0 ]
  262.             set_light( i, Lights[ player ][ 0 ] )
  263.         }
  264.     }
  265.     else set_light( player, Lights[ player ][ 0 ] )
  266.  
  267.     return adminbrightness( id )
  268. }
  269.  
  270. //-------------------- Stocks - generate brightness as a string --------------------//
  271. stock get_brightness_string( input, output[] )
  272. {
  273.     new pos = 0
  274.     for( new i = 0; i < 26; i++ )
  275.     {
  276.         //------------- letters --------------//
  277.         if( letterprecentage ) pos += formatex( output[ pos ], 90 - pos, ( i == input - 'a' ) ? "\y%c\d" : "%c", 'a' + i )
  278.         //------------- precentage --------------//
  279.         else if( i == input - 'a' )
  280.         {
  281.             pos = formatex( output[ pos ], 90 - pos, "\y%d%%\d", ( ( input - 'a' ) * 100 ) / 25 )
  282.             break
  283.         }
  284.     }
  285.     output[ pos ] = EOS
  286. }
  287.  
  288. //-------------------- Stocks - set light --------------------//
  289. stock set_light( id, const light[] )
  290. {
  291.     message_begin( MSG_ONE_UNRELIABLE, SVC_LIGHTSTYLE, .player = id )
  292.     write_byte( 0 )
  293.     write_string( light )
  294.     message_end()
  295. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement