Advertisement
Rejack

Jailbreak - Last Request (API)

Sep 26th, 2020 (edited)
2,029
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 26.00 KB | None | 0 0
  1. #define USE_RULES   // DO NOT TOUCH
  2.  
  3. // Includes
  4.  
  5. #include < amxmodx >
  6. #include < cstrike >
  7. #include < hamsandwich >
  8. #include < fakemeta_util >
  9. #include < lastrequest_const >
  10. //#include < engine >
  11.  
  12. new const szVersion[ ]  = "1.0";
  13.  
  14. // Defines
  15.  
  16. //#define   USE_DEBUG
  17.  
  18. #define TASKID_COUNTDOWN    12348   // Pre battle taskid
  19. #define TASKID_MESSAGE      123471  // Battle message taskid
  20.  
  21. #define MINIMUM_COUNTDOWN   3
  22. #define MAXIMUM_COUNTDOWN   5
  23.  
  24. #define gIndex(%1,%2)   g_mIndex[ %1 ][ %2 ]
  25.  
  26. // Enums
  27.  
  28. enum _:GAME_DATA
  29. {
  30.     GAME_NAME[ 32 ],
  31.     bool: GAME_VICTIM,
  32.     bool: GAME_HAS_RULES,
  33.     RULES_CALLBACK
  34. };
  35.  
  36. enum _: g_mClientData
  37. {
  38.     g_mCategory,
  39.    
  40.     g_mVictim,
  41.     g_mBattle,
  42.     g_mHealth,
  43.     g_mCountdown,
  44.    
  45.     bool: bFreeze,
  46.     bool: bInfoMsg
  47. };
  48.  
  49. enum _:FWD_ID
  50. {
  51.     FWD_GAME_START,
  52.     FWD_GAME_END
  53. };
  54.  
  55. new const szCategories[ LR_CATEGORIES_ID ][ ] =
  56. {
  57.     "Custome Battles",
  58.     "Shot for Shot",
  59.     "Special Battles",
  60.     "First Battles"
  61. };
  62.  
  63. new Array: g_aCustomeGames;
  64. new Array: g_aShotGames;
  65. new Array: g_aSpecialGames;
  66. new Array: g_aFirstGames;
  67.  
  68. new g_iForwards[ FWD_ID ];
  69.  
  70. new szItem[ 128 ];
  71.  
  72. new g_mIndex[ 33 ][ g_mClientData ];
  73.  
  74. new g_iCountdown;
  75. new g_iGameId;
  76. new g_iCategoryId;
  77.  
  78. new g_iPrisoner;
  79. new g_iGuard;
  80.  
  81. new bool: bRules[ GAME_RULES ];
  82. new g_msgSetFOV;
  83.  
  84. public plugin_init()
  85. {
  86.     register_plugin( "Jailbreak: Last Request (API)", "1.0", "Rejack" );
  87.    
  88.     register_clcmd( "say /lr""cmdMainMenu" );
  89.     register_clcmd( "say /infomsg", "cmdInfoMsg" );
  90.     register_concmd( "set_health""cmdSetHealth" );
  91.    
  92.     g_msgSetFOV = get_user_msgid( "SetFOV" )
  93.    
  94.     register_event( "SetFOV","evSetFOV","b","1<90" );
  95.    
  96.     RegisterHam( Ham_TraceAttack, "player", "ForwardTraceAttack" );
  97.    
  98.     g_iForwards[ FWD_GAME_START ]   = CreateMultiForward( "FwdLrStarted", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_CELL );
  99.     g_iForwards[ FWD_GAME_END ] = CreateMultiForward( "FwdLrEnded", ET_IGNORE, FP_CELL, FP_CELL );
  100.    
  101.     g_aCustomeGames = ArrayCreate( GAME_DATA );
  102.     g_aShotGames    = ArrayCreate( GAME_DATA );
  103.     g_aSpecialGames = ArrayCreate( GAME_DATA );
  104.     g_aFirstGames   = ArrayCreate( GAME_DATA );
  105.    
  106.     if ( g_aCustomeGames == Invalid_Array || g_aShotGames == Invalid_Array || g_aSpecialGames == Invalid_Array || g_aFirstGames == Invalid_Array )
  107.         set_fail_state( "Couldn't create array, plugin shutting down." );
  108.    
  109.     #if defined USE_DEBUG
  110.    
  111.     set_task( 3.5, "taskDebugLoadedPlugins" );
  112.    
  113.     #endif
  114.    
  115. }
  116.  
  117. /* Client Side */
  118.  
  119. public cmdInfoMsg( const client )
  120. {
  121.     g_mIndex[ client ][ bInfoMsg ]  =   !g_mIndex[ client ][ bInfoMsg ];
  122.    
  123.     ColorPrint( client, "You^4 %s^1 the last-request^3 info message^1.", g_mIndex[ client ][ bInfoMsg ] ? "Disabled" : "Enabled" );
  124.    
  125.     return 1;
  126. }
  127.  
  128. public client_putinserver( client )
  129. {
  130.    
  131.     g_mIndex[ client ][ g_mCategory ]   = -1;
  132.    
  133.     g_mIndex[ client ][ g_mVictim ]     = 0;
  134.     g_mIndex[ client ][ g_mBattle ]     = -1;
  135.     g_mIndex[ client ][ g_mHealth ]     = 100;
  136.     g_mIndex[ client ][ g_mCountdown ]  = MINIMUM_COUNTDOWN;
  137.    
  138.     g_mIndex[ client ][ bFreeze ]       = false;
  139. }
  140.  
  141. public cmdSetHealth( const client )
  142. {
  143.     new szArgs[ 32 ];
  144.    
  145.     read_args( szArgs, charsmax( szArgs ) );
  146.    
  147.     remove_quotes( szArgs );
  148.    
  149.     if ( !is_str_num( szArgs ) )
  150.     {
  151.         ColorPrint( client, "You need to use^4 numbers^1 only." );
  152.        
  153.         client_cmd( client, "messagemode set_health" );
  154.        
  155.         return 1;
  156.     }
  157.    
  158.     static iCategory;
  159.    
  160.     iCategory   = gIndex( client, g_mCategory );
  161.    
  162.     if ( iCategory == -1 )
  163.         return 1;
  164.    
  165.     if ( iCategory != LR_CUSTOME_BATTLES && iCategory != LR_SHOT_FOR_SHOT )
  166.     {
  167.         ColorPrint( client, "You can't set the Health on this category^1." );
  168.        
  169.         return 1;
  170.     }
  171.    
  172.     static Health;
  173.    
  174.     Health  = str_to_num( szArgs );
  175.    
  176.     if ( iCategory == LR_CUSTOME_BATTLES && ( Health < CUSTOME_MIN_HP || Health > CUSTOME_MAX_HP ) ||
  177.     iCategory == LR_SHOT_FOR_SHOT && ( Health < SHOT_MIN_HP || Health > SHOT_MAX_HP ) )
  178.     {
  179.         switch ( iCategory )
  180.         {
  181.             case LR_CUSTOME_BATTLES:
  182.             {
  183.                 if ( Health < CUSTOME_MAX_HP )
  184.                     ColorPrint( client, "The maximum amount of health you can set is^4 %i Health^1.", CUSTOME_MAX_HP );
  185.                
  186.                 else if ( Health > CUSTOME_MIN_HP )
  187.                     ColorPrint( client, "The minimum amount of health you can set is^4 %i Health^1.", CUSTOME_MIN_HP );
  188.             }
  189.            
  190.             case LR_SHOT_FOR_SHOT:
  191.             {
  192.                 if ( Health < SHOT_MAX_HP )
  193.                     ColorPrint( client, "The maximum amount of health you can set is^4 %i Health^1.", SHOT_MAX_HP );
  194.                
  195.                 else if ( Health > SHOT_MIN_HP )
  196.                     ColorPrint( client, "The minimum amount of health you can set is^4 %i Health^1.", SHOT_MIN_HP );
  197.             }
  198.         }
  199.         client_cmd( client, "messagemode set_health" );
  200.        
  201.         return 1;
  202.     }
  203.    
  204.     g_mIndex[ client ][ g_mHealth ] = str_to_num( szArgs );
  205.    
  206.     return cmdSecondaryMenu( client );
  207. }
  208.  
  209. /* Natives & API */
  210.  
  211. public plugin_natives( )
  212. {
  213.     register_native( "register_custome_lr", "RegisterCustomeGame" );
  214.     register_native( "register_shot_lr",    "RegisterShotGame" );
  215.     register_native( "register_special_lr", "RegisterSpecialGame" );
  216.     register_native( "register_first_lr",   "RegisterFirstGame" );
  217.    
  218.     register_native( "set_rule",        "NativeSetRule" );
  219.     register_native( "get_rule",        "NativeGetRule" );
  220.    
  221.     register_native( "userOpenMenu",    "NativeOpenMenu" );
  222.     register_native( "userExitRules",   "NativeExitRules" );
  223. }
  224.  
  225. public NativeOpenMenu( const  iPlugin, const iParams )
  226. {
  227.     if ( !is_user_connected( get_param( 1 ) ) )
  228.         return 0;
  229.    
  230.     return cmdMainMenu( get_param( 1 ) );
  231. }
  232.  
  233. public NativeExitRules( const iPlugin, const iParams )
  234. {
  235.     static index;
  236.    
  237.     index   = get_param( 1 );
  238.    
  239.     if ( !is_user_connected( index ) )
  240.         return 0;
  241.    
  242.     return cmdSecondaryMenu( index );
  243. }
  244.  
  245. public NativeSetRule( const iPlugin, const iParams )
  246. {
  247.     bRules[ get_param( 1 ) ]    = bool: get_param( 2 );
  248.    
  249.     return 1;
  250. }
  251.  
  252. public NativeGetRule( const iPlugin, const iParams )
  253. {
  254.     return bRules[ get_param( 1 ) ];
  255. }
  256.  
  257. public RegisterCustomeGame( const iPlugin, const iParams )
  258. {
  259.     return RegisterGame( LR_CUSTOME_BATTLES, iParams, iPlugin );
  260. }
  261.  
  262. public RegisterShotGame( const iPlugin, const iParams )
  263. {
  264.     return RegisterGame( LR_SHOT_FOR_SHOT, iParams, iPlugin );
  265. }
  266.  
  267. public RegisterSpecialGame( const iPlugin, const iParams )
  268. {
  269.     return RegisterGame( LR_SPECIAL_BATTLES, iParams, iPlugin );
  270. }
  271.  
  272. public RegisterFirstGame( const iPlugin, const iParams )
  273. {
  274.     return RegisterGame( LR_FIRST_BATTLES, iParams, iPlugin );
  275. }
  276.  
  277. stock RegisterGame( const iCategory, const iParams, const iPlugin )
  278. {
  279.     if ( iParams < 2 )
  280.     {
  281.         log_error( AMX_ERR_PARAMS, "Wrong paremeters." );
  282.        
  283.         return -1;
  284.     }
  285.    
  286.     new aData[ GAME_DATA ];
  287.     static iPosition;
  288.    
  289.     get_string( 1, aData[ GAME_NAME ], 31 );
  290.    
  291.     aData[ GAME_VICTIM ]    = bool: get_param( 2 );
  292.     aData[ GAME_HAS_RULES ] = bool: get_param( 3 );
  293.    
  294.     if ( aData[ GAME_HAS_RULES ] )
  295.     {
  296.         if ( iParams < 4 )
  297.         {
  298.             log_error( AMX_ERR_PARAMS, "Wrong paremeters." );
  299.            
  300.             return -1;
  301.         }
  302.        
  303.         static iForward;
  304.         static szCallback[ 32 ];
  305.        
  306.         get_string( 4, szCallback, charsmax( szCallback ) );
  307.        
  308.         iForward    = CreateOneForward( iPlugin, szCallback, FP_CELL );
  309.        
  310.         if ( !szCallback[ 0 ] )
  311.         {
  312.             log_error( AMX_ERR_GENERAL, "Empty callback called in a new game (%s).", aData[ GAME_NAME ] );
  313.            
  314.             return -1;
  315.         }
  316.        
  317.         aData[ RULES_CALLBACK ] = iForward;
  318.     }
  319.    
  320.     switch ( iCategory )
  321.     {
  322.         case LR_CUSTOME_BATTLES:
  323.             iPosition   = ArraySize( g_aCustomeGames ),
  324.             ArrayPushArray( g_aCustomeGames, aData );
  325.        
  326.         case LR_SHOT_FOR_SHOT:
  327.             iPosition   = ArraySize( g_aShotGames ),
  328.             ArrayPushArray( g_aShotGames, aData );
  329.        
  330.         case LR_SPECIAL_BATTLES:
  331.             iPosition   = ArraySize( g_aSpecialGames ),
  332.             ArrayPushArray( g_aSpecialGames, aData );
  333.        
  334.         case LR_FIRST_BATTLES:
  335.             iPosition   = ArraySize( g_aFirstGames ),
  336.             ArrayPushArray( g_aFirstGames, aData );
  337.        
  338.         default:
  339.             return -1;
  340.     }
  341.    
  342.     #if defined USE_DEBUG  
  343.    
  344.     log_amx( "[LR API - DEBUG] Successfuly created a last request game: '%s' (#%i). [%s]", aData[ GAME_NAME ], iPosition, aData[ GAME_HAS_RULES ] ? "Special" : "Regular" );
  345.    
  346.     #endif
  347.    
  348.     return iPosition;
  349. }
  350.  
  351. /* Tasks */
  352.  
  353. #if defined USE_DEBUG
  354.  
  355. public taskDebugLoadedPlugins( ) // For debug purposes
  356. {
  357.     log_amx( "[LR API - DEBUG] Successfuly created '#%i' custome games.", ArraySize( g_aCustomeGames ) );
  358.     log_amx( "[LR API - DEBUG] Successfuly created '#%i' shot for shot games.", ArraySize( g_aShotGames ) );
  359.     log_amx( "[LR API - DEBUG] Successfuly created '#%i' special games.", ArraySize( g_aSpecialGames ) );
  360.     log_amx( "[LR API - DEBUG] Successfuly created '#%i' first games.", ArraySize( g_aFirstGames ) );
  361. }  
  362.  
  363. #endif
  364.  
  365. public taskCountdownBeforeBattle( )
  366. {
  367.     if ( g_iCountdown < 1 )
  368.     {
  369.         // Ended countdown start lr
  370.        
  371.         fm_set_user_freeze( g_iPrisoner, 0 );
  372.        
  373.         fm_set_user_freeze( g_iGuard, 0 );
  374.        
  375.         taskBattleMessage( );   // Start message
  376.        
  377.         if ( bRules[ bNoBunnyhop ] )    // No Bunnyhop rule
  378.         {
  379.             set_user_bunnyhop( g_iPrisoner, 0 );
  380.            
  381.             set_user_bunnyhop( g_iGuard, 0 );
  382.         }
  383.        
  384.         return 1;
  385.     }
  386.    
  387.     static Vox[ 32 ], aData[ GAME_DATA ];
  388.    
  389.     if ( g_iCategoryId != LR_FIRST_BATTLES )
  390.     {
  391.         num_to_word( g_iCountdown, Vox, charsmax( Vox ) );
  392.        
  393.         client_cmd( 0, "spk ^"vox/%s^"", Vox );
  394.     }
  395.    
  396.     switch ( g_iCategoryId )
  397.     {
  398.         case LR_CUSTOME_BATTLES:
  399.             ArrayGetArray( g_aCustomeGames, g_iGameId, aData );
  400.        
  401.         case LR_SHOT_FOR_SHOT:
  402.             ArrayGetArray( g_aShotGames, g_iGameId, aData );
  403.        
  404.         case LR_SPECIAL_BATTLES:
  405.             ArrayGetArray( g_aSpecialGames, g_iGameId, aData );
  406.        
  407.         case LR_FIRST_BATTLES:
  408.             ArrayGetArray( g_aFirstGames, g_iGameId, aData );
  409.        
  410.         default:
  411.             return 1;
  412.     }  
  413.    
  414.     set_hudmessage( 0, 255, 255, -1.0, 0.35, 0, 0.0, 1.0, 0.1, 0.1, 1 );
  415.     show_hudmessage( 0, "%s vs. %s^n%s - %s^nWill start in %i SECOND%s", szName( g_iPrisoner ), szName( g_iGuard ), szCategories[ g_iCategoryId ], aData[ GAME_NAME ], g_iCountdown, ( g_iCountdown < 2 ) ? "" : "s" );
  416.    
  417.     g_iCountdown--;
  418.    
  419.     set_task( 1.0, "taskCountdownBeforeBattle", TASKID_COUNTDOWN );
  420.    
  421.     return 1;
  422. }
  423.  
  424. public taskBattleMessage( )
  425. {
  426.     if ( g_iCategoryId < 0 || g_iGameId < 0 )       // No game
  427.         return 1;
  428.    
  429.     static aData[ GAME_DATA ];
  430.    
  431.     switch ( g_iCategoryId )
  432.     {
  433.         case LR_CUSTOME_BATTLES:
  434.             ArrayGetArray( g_aCustomeGames, g_iGameId, aData );
  435.        
  436.         case LR_SHOT_FOR_SHOT:
  437.             ArrayGetArray( g_aShotGames, g_iGameId, aData );
  438.        
  439.         case LR_SPECIAL_BATTLES:
  440.             ArrayGetArray( g_aSpecialGames, g_iGameId, aData );
  441.        
  442.         case LR_FIRST_BATTLES:
  443.             ArrayGetArray( g_aFirstGames, g_iGameId, aData );
  444.        
  445.         default:
  446.             return 1;
  447.     }
  448.     static szMsg[ 512 ], szBuffer[ 128 ];
  449.    
  450.     formatex( szMsg, charsmax( szMsg ), "%s Jailbreak         v%s", szPrefix, szVersion );
  451.    
  452.     add( szMsg, charsmax( szMsg ), "^n                        by Rejack" );
  453.    
  454.     formatex( szBuffer, charsmax( szBuffer ), "^nLast Request - %s", szCategories[ g_iCategoryId ] );
  455.    
  456.     add( szMsg, charsmax( szMsg ), szBuffer );
  457.    
  458.     formatex( szBuffer, charsmax( szBuffer ), "^n             %s", aData[ GAME_NAME ] );
  459.    
  460.     add( szMsg, charsmax( szMsg ), szBuffer );
  461.    
  462.     add( szMsg, charsmax( szMsg ), "^n__________________________^n" );
  463.    
  464.     static indexPrisoner, indexGuard;
  465.    
  466.     indexPrisoner   = find_player_index( );
  467.    
  468.     indexGuard  = gIndex( indexPrisoner, g_mVictim );
  469.    
  470.     if ( !is_user_connected( indexPrisoner ) || !is_user_connected( indexGuard ) )
  471.         return 1;
  472.    
  473.     add( szMsg, charsmax( szMsg ), "^n Participating Players:^n" );
  474.    
  475.     add( szMsg, charsmax( szMsg ), "^n   - GUARDS" );
  476.    
  477.     formatex( szBuffer, charsmax( szBuffer ), "^n        > %s (%i HP)", szName( indexGuard ), get_user_health( indexGuard ) );
  478.     add( szMsg, charsmax( szMsg ), szBuffer );
  479.    
  480.     add( szMsg, charsmax( szMsg ), "^n^n   - PRISONERS" );
  481.    
  482.     formatex( szBuffer, charsmax( szBuffer ), "^n        > %s (%i HP)", szName( indexPrisoner ), get_user_health( indexPrisoner ) );
  483.     add( szMsg, charsmax( szMsg ), szBuffer );
  484.    
  485.     static i, z, szSubBuffer[ 128 ];
  486.    
  487.     z   = 0;
  488.    
  489.     szBuffer    = "^n^n Game Rules:^n";
  490.    
  491.     for ( i = 0; i < GAME_RULES; i++ )
  492.     {
  493.         if ( bRules[ i ] )
  494.         {
  495.             formatex( szSubBuffer, charsmax( szSubBuffer ), "^n   > %s", szRules[ i ] );
  496.            
  497.             add( szBuffer, charsmax( szBuffer ), szSubBuffer );
  498.            
  499.             z++;
  500.         }
  501.     }
  502.    
  503.     if ( z < 1 )
  504.         szBuffer    = "^n^nNo Rules";
  505.    
  506.     add( szMsg, charsmax( szMsg ), szBuffer );
  507.    
  508.     szBuffer    = "^n^n^nIf you want to disable this message type '/infomsg'.";
  509.    
  510.     add( szMsg, charsmax( szMsg ), szBuffer );
  511.    
  512.     static Players[ 32 ], iNum;
  513.    
  514.     get_players( Players, iNum, "ch" );
  515.    
  516.     for ( i = 0; i < iNum; i++ )
  517.     {
  518.         if ( g_mIndex[ Players[ i ] ][ bInfoMsg ] )
  519.             continue;
  520.        
  521.         set_hudmessage( 0, 255, 255, 0.03, 0.1, 0, 0.0, 0.3, 0.1, 0.1, 1 );
  522.         show_hudmessage( Players[ i ], szMsg );
  523.     }
  524.    
  525.     set_task( 0.3, "taskBattleMessage", TASKID_MESSAGE );
  526.    
  527.     return 0;
  528. }
  529.        
  530. /* Events */
  531.  
  532. public evSetFOV( client )
  533. {
  534.     if ( bRules[ bNoZoom ] )
  535.     {
  536.         message_begin( MSG_ONE, g_msgSetFOV, { 0, 0, 0 }, client );
  537.         write_byte( 90 );
  538.         message_end();
  539.     }
  540.    
  541.     return 0;
  542. }
  543.  
  544. /* Forwards */
  545.  
  546. public ForwardTraceAttack( victim, attacker, Float: fDamage, Float: fDir[ 3 ], ptr, bits )
  547. {
  548.     if ( !bRules[ bHeadshot ] )
  549.         return 1;
  550.    
  551.     if ( !is_user_alive( victim ) )
  552.         return 1;
  553.        
  554.     if ( !is_user_alive( attacker ) )
  555.         return 1;
  556.    
  557.     if ( victim == attacker )
  558.         return 1;
  559.        
  560.     if ( get_tr2( ptr, TR_iHitgroup ) != HIT_HEAD )
  561.     {
  562.         new index;
  563.        
  564.         index   = gIndex( victim, g_mVictim )// if T get shot check
  565.        
  566.         if ( cs_get_user_team( attacker ) == CS_TEAM_CT ||  // if attacker is ct
  567.         attacker != index )                 // and the ct isnt the one participating the duel
  568.             return 1;
  569.        
  570.         return 4;
  571.     }
  572.    
  573.     return 1;
  574. }
  575.  
  576. stock find_player_index( )
  577. {
  578.     if ( g_iCategoryId < 0 || g_iGameId < 0 )       // No game
  579.         return -1;
  580.    
  581.     static Players[ 32 ], iNum, index, i;
  582.    
  583.     get_players( Players, iNum, "aceh", "TERRORIST" );
  584.    
  585.     for ( i = 0; i < iNum; i++ )
  586.     {
  587.         if ( gIndex( Players[ i ], g_mVictim ) < 1 )
  588.             continue;
  589.        
  590.         index   = Players[ i ];
  591.        
  592.         break;
  593.     }
  594.    
  595.     return index;
  596. }
  597.  
  598. /* Main Menu */
  599.  
  600. public cmdMainMenu( const client )
  601. {
  602.     if (                        // Nothing inside any array so no lrs
  603.     ArraySize( g_aCustomeGames ) < 1 &&
  604.     ArraySize( g_aShotGames ) < 1 &&
  605.     ArraySize( g_aSpecialGames ) &&
  606.     ArraySize( g_aFirstGames ) < 1
  607.     )
  608.         return 1;
  609.    
  610.     g_mIndex[ client ][ g_mCategory ]   = -1;
  611.    
  612.     static Menu;
  613.    
  614.     formatex( szItem, charsmax( szItem ), "\r[%s]\w Last Request Menu^n^nSelect a category!", szPrefix );
  615.    
  616.     Menu    = menu_create( szItem, "handlerMainMenu" );
  617.    
  618.     static i;
  619.    
  620.     for ( i = 0; i < sizeof ( szCategories ); i++ )
  621.     {
  622.         if (
  623.         i == LR_CUSTOME_BATTLES && ArraySize( g_aCustomeGames ) < 1 ||
  624.         i == LR_SHOT_FOR_SHOT && ArraySize( g_aShotGames ) < 1 ||
  625.         i == LR_SPECIAL_BATTLES && ArraySize( g_aSpecialGames ) < 1 ||
  626.         i == LR_FIRST_BATTLES && ArraySize( g_aFirstGames ) < 1
  627.         )
  628.             continue;
  629.        
  630.         menu_additem( Menu, szCategories[ i ] );
  631.     }
  632.    
  633.     menu_display( client, Menu );
  634.    
  635.     return 1;
  636. }
  637.  
  638. public handlerMainMenu( client, Menu, Item )
  639. {
  640.     if ( Item == MENU_EXIT )
  641.     {
  642.         menu_destroy( Menu );
  643.        
  644.         return 1;
  645.     }
  646.    
  647.     static mData[ 6 ], Trash;
  648.    
  649.     menu_item_getinfo( Menu, Item, Trash, mData, charsmax( mData ), _,_, Trash );
  650.    
  651.     g_mIndex[ client ][ g_mCategory ]   = Item;
  652.    
  653.     g_mIndex[ client ][ g_mVictim ]     = 0;
  654.     g_mIndex[ client ][ g_mBattle ]     = -1;
  655.     g_mIndex[ client ][ g_mHealth ]     = 100;
  656.     g_mIndex[ client ][ g_mCountdown ]  = MINIMUM_COUNTDOWN;
  657.    
  658.     g_mIndex[ client ][ bFreeze ]       = false;
  659.    
  660.     return cmdSecondaryMenu( client );
  661. }
  662.  
  663. /* Secondary Menu */
  664.  
  665. public cmdSecondaryMenu( const client )
  666. {
  667.     if ( gIndex( client, g_mCategory ) == -1 )
  668.         return cmdMainMenu( client );
  669.    
  670.     static Menu, szBuffer[ 128 ];
  671.    
  672.     formatex( szItem, charsmax( szItem ), "\r[%s]\w Last Request Menu^n^nCustomize your battle!", szPrefix );
  673.    
  674.     Menu    = menu_create( szItem, "handlerSecondaryMenu" );
  675.    
  676.     // 1. Selected victim
  677.     if ( gIndex( client, g_mVictim ) == 0 )
  678.         szBuffer    = "\r NONE";
  679.    
  680.     else
  681.         formatex( szBuffer, charsmax( szBuffer ), "\y %s", szName( gIndex( client, g_mVictim ) ) );
  682.    
  683.     formatex( szItem, charsmax( szItem ), "Selected victim: %s", szBuffer );
  684.    
  685.     menu_additem( Menu, szItem, "0" );
  686.    
  687.     // 2. Selected battle
  688.     if ( gIndex( client, g_mBattle ) == -1 )
  689.         szBuffer    = "\r NONE";
  690.    
  691.     else
  692.     {
  693.         static aData[ GAME_DATA ];
  694.        
  695.         switch ( gIndex( client, g_mCategory ) )
  696.         {
  697.             case LR_CUSTOME_BATTLES:
  698.                 ArrayGetArray( g_aCustomeGames, gIndex( client, g_mBattle ), aData );
  699.            
  700.             case LR_SHOT_FOR_SHOT:
  701.                 ArrayGetArray( g_aShotGames, gIndex( client, g_mBattle ), aData );
  702.            
  703.             case LR_SPECIAL_BATTLES:
  704.                 ArrayGetArray( g_aSpecialGames, gIndex( client, g_mBattle ), aData );
  705.            
  706.             case LR_FIRST_BATTLES:
  707.                 ArrayGetArray( g_aFirstGames, gIndex( client, g_mBattle ), aData );
  708.                
  709.         }
  710.        
  711.         formatex( szBuffer, charsmax( szBuffer ), "\y %s", aData[ GAME_NAME ] );
  712.     }
  713.    
  714.     formatex( szItem, charsmax( szItem ), "Selected battle: %s^n", szBuffer );
  715.    
  716.     menu_additem( Menu, szItem, "1" );
  717.    
  718.     if ( gIndex( client, g_mCategory ) != LR_SPECIAL_BATTLES && gIndex( client, g_mCategory ) != LR_FIRST_BATTLES )
  719.     {
  720.         // 3. Set Health
  721.         formatex( szItem, charsmax( szItem ), "Set health:\y %i\d HEALTH", gIndex( client, g_mHealth ) );
  722.        
  723.         switch ( gIndex( client, g_mCategory ) )
  724.         {
  725.             case LR_CUSTOME_BATTLES:
  726.                 formatex( szBuffer, charsmax( szBuffer ), "^n           \r*\w MAX:\y %i\d HEALTH^n           \r*\w MIN:\y %i\d HEALTH", CUSTOME_MAX_HP, CUSTOME_MIN_HP );
  727.                
  728.             case LR_SHOT_FOR_SHOT:
  729.                 formatex( szBuffer, charsmax( szBuffer ), "^n           \r*\w MAX:\y %i\d HEALTH^n           \r*\w MIN:\y %i\d HEALTH", SHOT_MAX_HP, SHOT_MIN_HP );
  730.         }
  731.         add( szItem, charsmax( szItem ), szBuffer );
  732.        
  733.         menu_additem( Menu, szItem, "2" );
  734.     }
  735.    
  736.     // 4. Countdown
  737.     formatex( szItem, charsmax( szItem ), "Countdown:\y %i\d SECONDS", gIndex( client, g_mCountdown ) );
  738.    
  739.     menu_additem( Menu, szItem, "3" );
  740.    
  741.     if ( gIndex( client, g_mCategory ) != LR_FIRST_BATTLES )
  742.     {
  743.         // 5. Freeze
  744.         formatex( szItem, charsmax( szItem ), "Freeze:%s^n", gIndex( client, bFreeze ) ? "\r Yes" : "\y No" );
  745.        
  746.         menu_additem( Menu, szItem, "4" );
  747.    
  748.         // 6. Select Rules
  749.         menu_additem( Menu, "Select rules^n", "5" );
  750.     }
  751.    
  752.     // 7. Start last-request
  753.     menu_additem( Menu, "\rStart last request", "6" );
  754.    
  755.     menu_setprop( Menu, MPROP_EXITNAME, "Back" );
  756.    
  757.     menu_display( client, Menu );
  758.    
  759.     return 1;
  760. }
  761.  
  762. public handlerSecondaryMenu( client, Menu, Item )
  763. {
  764.     if ( gIndex( client, g_mCategory ) == -1 )
  765.         return cmdMainMenu( client );
  766.    
  767.     if ( Item == MENU_EXIT )
  768.     {
  769.         menu_destroy( Menu );
  770.        
  771.         return cmdMainMenu( client );
  772.     }
  773.    
  774.     static mData[ 6 ], Trash;
  775.    
  776.     menu_item_getinfo( Menu, Item, Trash, mData, charsmax( mData ), _,_, Trash );
  777.    
  778.     switch ( str_to_num( mData ) )
  779.     {
  780.         case 0: // Selected victim
  781.             return cmdSelectVictim( client );
  782.        
  783.         case 1: // Selected battle
  784.             return cmdSelectBattle( client );
  785.        
  786.         case 2: // Set health
  787.         {
  788.             client_cmd( client, "messagemode set_health" );
  789.            
  790.             return 1;
  791.         }
  792.        
  793.         case 3: // Countdown
  794.         {
  795.             if ( gIndex( client, g_mCountdown ) >= MAXIMUM_COUNTDOWN )
  796.                 g_mIndex[ client ][ g_mCountdown ]  = MINIMUM_COUNTDOWN - 1;
  797.            
  798.             g_mIndex[ client ][ g_mCountdown ]++;
  799.         }
  800.        
  801.         case 4: // Freeze
  802.             g_mIndex[ client ][ bFreeze ]   = !g_mIndex[ client ][ bFreeze ];
  803.        
  804.         case 5: // Select rules
  805.         {
  806.             if ( gIndex( client, g_mVictim ) == 0 || gIndex( client, g_mBattle ) == -1 )
  807.             {
  808.                 ColorPrint( client, "You need to select a^3 victim^1 and a^4 battle^1 in order to select^3 rules^1." );
  809.                
  810.                 return cmdSecondaryMenu( client );
  811.             }
  812.            
  813.             static aData[ GAME_DATA ];
  814.            
  815.             switch ( gIndex( client, g_mCategory ) )
  816.             {
  817.                 case LR_CUSTOME_BATTLES:
  818.                     ArrayGetArray( g_aCustomeGames, gIndex( client, g_mBattle ), aData );
  819.                
  820.                 case LR_SHOT_FOR_SHOT:
  821.                     ArrayGetArray( g_aShotGames, gIndex( client, g_mBattle ), aData );
  822.                
  823.                 case LR_SPECIAL_BATTLES:
  824.                     ArrayGetArray( g_aSpecialGames, gIndex( client, g_mBattle ), aData );
  825.                    
  826.                 case LR_FIRST_BATTLES:
  827.                     ArrayGetArray( g_aFirstGames, gIndex( client, g_mBattle ), aData );
  828.             }
  829.                    
  830.            
  831.             if ( aData[ GAME_HAS_RULES ] )
  832.             {
  833.                 static ret;
  834.                
  835.                 ExecuteForward( aData[ RULES_CALLBACK ], ret, client );
  836.                
  837.                 return 1;
  838.             }
  839.            
  840.             return cmdSelectRules( client );
  841.         }
  842.        
  843.         case 6: // Start last-request
  844.         {
  845.             static g_iVictim;
  846.            
  847.             g_iVictim   = gIndex( client, g_mVictim );
  848.            
  849.             set_user_bunnyhop( client, 1 );
  850.             set_user_bunnyhop( g_iVictim , 1 );
  851.            
  852.             fm_set_user_godmode( client, 0 );
  853.             fm_set_user_godmode( g_iVictim, 0 );
  854.            
  855.             fm_set_user_noclip( client, 0 );
  856.             fm_set_user_noclip( g_iVictim, 0 );
  857.            
  858.             fm_set_user_gravity( client, 1.0 );
  859.             fm_set_user_gravity( g_iVictim, 1.0 );
  860.            
  861.             fm_set_user_health( client, gIndex( client, g_mHealth ) );
  862.             fm_set_user_health( g_iVictim, gIndex( client, g_mHealth ) );
  863.            
  864.             fm_set_user_armor( client, 0 );
  865.             fm_set_user_armor( g_iVictim, 0 );
  866.            
  867.             fm_strip_user_weapons( client );
  868.             fm_strip_user_weapons( g_iVictim );
  869.            
  870.             g_iCategoryId   = gIndex( client, g_mCategory );
  871.             g_iGameId   = gIndex( client, g_mBattle );
  872.             g_iCountdown    = gIndex( client, g_mCountdown );
  873.            
  874.             ExecuteForward( g_iForwards[ FWD_GAME_START ], Item, client, g_iVictim, g_iCategoryId, g_iGameId, g_iCountdown );
  875.            
  876.             g_iPrisoner = client;
  877.             g_iGuard    = g_iVictim;
  878.            
  879.             if ( g_iCategoryId == LR_FIRST_BATTLES )
  880.                 g_iCountdown    = 0;
  881.            
  882.             taskCountdownBeforeBattle( );
  883.            
  884.             if ( g_mIndex[ client ][ bFreeze ] )
  885.             {
  886.                 fm_set_user_freeze( client, 1 );
  887.                
  888.                 fm_set_user_freeze( g_iVictim, 1 );
  889.             }
  890.            
  891.             return 1;
  892.         }
  893.     }
  894.    
  895.     menu_destroy( Menu );
  896.    
  897.     return cmdSecondaryMenu( client );
  898. }
  899.  
  900. /* Select vicitm menu */
  901.  
  902. public cmdSelectVictim( const client )
  903. {
  904.     static Menu;
  905.    
  906.     formatex( szItem, charsmax( szItem ), "\r[%s]\w Last Request Menu^n^nSelect a victim!", szPrefix );
  907.    
  908.     Menu    = menu_create( szItem, "handlerSelectVictim" );
  909.    
  910.     static Players[ 32 ], mData[ 6 ];
  911.     static i, iNum, index;
  912.    
  913.     get_players( Players, iNum );
  914.    
  915.     for ( i = 0; i < iNum; i++ )
  916.     {
  917.         index   = Players[ i ];
  918.        
  919.         num_to_str( index, mData, charsmax( mData ) );
  920.        
  921.         menu_additem( Menu, szName( index ), mData );
  922.     }
  923.    
  924.     menu_setprop( Menu, MPROP_EXITNAME, "Back" );
  925.    
  926.     menu_display( client, Menu );
  927.    
  928.     return 1;
  929. }
  930.  
  931. public handlerSelectVictim( client, Menu, Item )
  932. {
  933.     if ( gIndex( client, g_mCategory ) == -1 )
  934.         return cmdMainMenu( client );
  935.    
  936.     if ( Item != MENU_EXIT )
  937.     {
  938.         static mData[ 6 ], Trash;
  939.        
  940.         menu_item_getinfo( Menu, Item, Trash, mData, charsmax( mData ), _,_, Trash );
  941.        
  942.         g_mIndex[ client ][ g_mVictim ] = str_to_num( mData );
  943.     }
  944.    
  945.     menu_destroy( Menu );
  946.    
  947.     return cmdSecondaryMenu( client );
  948. }
  949.  
  950. /* Select battle menu */
  951.  
  952. public cmdSelectBattle( const client )
  953. {
  954.     static iSize;
  955.    
  956.     switch ( gIndex( client, g_mCategory ) )
  957.     {
  958.         case LR_CUSTOME_BATTLES:
  959.             iSize   = ArraySize( g_aCustomeGames );
  960.        
  961.         case LR_SHOT_FOR_SHOT:
  962.             iSize   = ArraySize( g_aShotGames );
  963.        
  964.         case LR_SPECIAL_BATTLES:
  965.             iSize   = ArraySize( g_aSpecialGames );
  966.        
  967.         case LR_FIRST_BATTLES:
  968.             iSize   = ArraySize( g_aFirstGames );
  969.     }
  970.    
  971.     static Menu;
  972.    
  973.     formatex( szItem, charsmax( szItem ), "\r[%s]\w Last Request Menu^n^nSelect a battle!%s", szPrefix, ( iSize > 7 ) ? "^n^n\rPage:\d" : "" );
  974.    
  975.     Menu     = menu_create( szItem, "handlerSelectBattle" );
  976.    
  977.     static aData[ GAME_DATA ], mData[ 6 ];
  978.     static i;
  979.    
  980.     for ( i = 0; i < iSize; i++ )
  981.     {
  982.         switch ( gIndex( client, g_mCategory ) )
  983.         {
  984.             case LR_CUSTOME_BATTLES:
  985.                 ArrayGetArray( g_aCustomeGames, i, aData );
  986.            
  987.             case LR_SHOT_FOR_SHOT:
  988.                 ArrayGetArray( g_aShotGames, i, aData );
  989.            
  990.             case LR_SPECIAL_BATTLES:
  991.                 ArrayGetArray( g_aSpecialGames, i, aData );
  992.            
  993.             case LR_FIRST_BATTLES:
  994.                 ArrayGetArray( g_aFirstGames, i, aData );
  995.         }
  996.        
  997.         num_to_str( i, mData, charsmax( mData ) );
  998.        
  999.         menu_additem( Menu, aData[ GAME_NAME ], mData );
  1000.     }
  1001.    
  1002.     menu_setprop( Menu, MPROP_EXITNAME, "Back" );
  1003.    
  1004.     menu_display( client, Menu );
  1005.    
  1006.     return 1;
  1007. }
  1008.  
  1009. public handlerSelectBattle( client, Menu, Item )
  1010. {
  1011.     if ( gIndex( client, g_mCategory ) == -1 )
  1012.         return cmdMainMenu( client );
  1013.    
  1014.     if ( Item != MENU_EXIT )
  1015.     {
  1016.         static mData[ 6 ], Trash;
  1017.        
  1018.         menu_item_getinfo( Menu, Item, Trash, mData, charsmax( mData ), _,_, Trash );
  1019.        
  1020.         g_mIndex[ client ][ g_mBattle ] = str_to_num( mData );
  1021.     }
  1022.    
  1023.     menu_destroy( Menu );
  1024.    
  1025.     return cmdSecondaryMenu( client );
  1026. }
  1027.  
  1028. /* Select rules Menu */
  1029.  
  1030. public cmdSelectRules( const client )
  1031. {
  1032.     static Menu;
  1033.    
  1034.     formatex( szItem, charsmax( szItem ), "\r[%s]\w Last Request Menu^n^nSelect battle rules!", szPrefix );
  1035.    
  1036.     Menu     = menu_create( szItem, "handlerSelectRules" );
  1037.    
  1038.     static i;
  1039.    
  1040.     for ( i = 0; i < sizeof ( szRules ); i++ )
  1041.     {
  1042.         formatex( szItem, charsmax( szItem ), "%s:%s", szRules[ i ], bRules[ i ] ? "\r ON" : "\y OFF" );
  1043.        
  1044.         menu_additem( Menu, szItem );
  1045.     }
  1046.    
  1047.     menu_setprop( Menu, MPROP_EXITNAME, "Back" );
  1048.    
  1049.     menu_display( client, Menu );
  1050.    
  1051.     return 1;
  1052. }
  1053.  
  1054. public handlerSelectRules( client, Menu, Item )
  1055. {
  1056.     if ( Item != MENU_EXIT )
  1057.     {
  1058.         bRules[ Item ]  = !bRules[ Item ];
  1059.        
  1060.         return cmdSelectRules( client );
  1061.     }
  1062.    
  1063.     menu_destroy( Menu );
  1064.    
  1065.     return cmdSecondaryMenu( client );
  1066. }
  1067.  
  1068. /* Stocks */
  1069.  
  1070. stock ColorPrint( const index, const string[], any:... )
  1071. {
  1072.     new szMsg[ 512 ], Players[ 32 ], PNum = 1;
  1073.    
  1074.     static iLen; iLen = formatex( szMsg, charsmax( szMsg ), "^4[%s]^1 ", szPrefix );
  1075.    
  1076.     vformat( szMsg[ iLen ], charsmax( szMsg ) - iLen, string, 3 );
  1077.    
  1078.     if ( index )
  1079.         Players[ 0 ] = index;
  1080.    
  1081.     else
  1082.         get_players( Players, PNum, "ch" );
  1083.    
  1084.     for ( new i; i < PNum; i++ )
  1085.     {
  1086.         if( is_user_connected( Players[ i ] ) )
  1087.         {
  1088.             message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, Players[ i ] );
  1089.            
  1090.             write_byte( Players[ i ] );
  1091.            
  1092.             write_string( szMsg );
  1093.            
  1094.             message_end( );
  1095.         }
  1096.     }
  1097.    
  1098.     return 1;
  1099. }
  1100.  
  1101. stock szName( const index )
  1102. {
  1103.     static g_szName[ 32 ];
  1104.    
  1105.     get_user_name( index, g_szName, 31 );
  1106.    
  1107.     return g_szName;
  1108. }
  1109.  
  1110. stock fm_set_user_freeze( const index, freeze = 0 )
  1111. {
  1112.     if ( !is_user_alive( index ) )
  1113.         return -1;
  1114.    
  1115.     static iFlags;
  1116.    
  1117.     iFlags  = pev( index, pev_flags );
  1118.    
  1119.     switch ( freeze )
  1120.     {
  1121.         case 1:
  1122.             set_pev( index, pev_flags, iFlags | FL_FROZEN );
  1123.        
  1124.         default:
  1125.             set_pev( index, pev_flags, iFlags & ~FL_FROZEN );
  1126.     }
  1127.    
  1128.     return freeze;
  1129. }
  1130.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement