Rejack

Last Request API

Jan 15th, 2017 (edited)
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.88 KB | None | 0 0
  1. // Includes
  2.  
  3. #include < amxmodx >
  4. #include < fakemeta_util >
  5. #include < lastrequest_const >
  6.  
  7. // Defines
  8.  
  9. //#define   USE_DEBUG
  10.  
  11. #define MINIMUM_COUNTDOWN   3
  12. #define MAXIMUM_COUNTDOWN   5
  13. #define TASKID_COUNTDOWN    12348   // Don't touch
  14. #define MINIMUM_HEALTH      100
  15.  
  16. // Enums
  17.  
  18. enum _:GAME_DATA
  19. {
  20.     GAME_NAME[ 32 ],
  21.     bool: GAME_VICTIM
  22. };
  23.  
  24. new Array: g_aCustomeGames;
  25. new Array: g_aShotGames;
  26.  
  27. new szItem[ 128 ];
  28. new const szPrefix[ ]   = "AMXX";
  29.  
  30. enum _: g_mClientData
  31. {
  32.     g_mCategory,
  33.    
  34.     g_mVictim,
  35.     g_mBattle,
  36.     g_mHealth,
  37.     g_mCountdown,
  38.    
  39.     bool: bFreeze
  40. };
  41.  
  42. new g_mIndex[ 33 ][ g_mClientData ];
  43.  
  44. #define gIndex(%1,%2)   g_mIndex[ %1 ][ %2 ]
  45. new g_iCountdown;
  46. new g_iGameId;
  47. new g_iCategoryId;
  48.  
  49. enum _:FWD_ID
  50. {
  51.     FWD_GAME_START,
  52.     FWD_GAME_END
  53. };
  54.  
  55. new g_iForwards[ FWD_ID ];
  56.  
  57. public plugin_init()
  58. {
  59.     register_plugin( "Jailbreak: Last Request (API)", "1.0", "Rejack" );
  60.    
  61.     register_clcmd( "say /yan", "cmdMainMenu" );
  62.     register_concmd( "set_health",  "cmdSetHealth" );
  63.    
  64.     g_iForwards[ FWD_GAME_START ]   = CreateMultiForward( "FwdLrStarted", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_CELL );
  65.     g_iForwards[ FWD_GAME_END ] = CreateMultiForward( "FwdLrEnded", ET_IGNORE, FP_CELL, FP_CELL );
  66.    
  67.     g_aCustomeGames = ArrayCreate( GAME_DATA );
  68.    
  69.     if ( g_aCustomeGames == Invalid_Array )
  70.         set_fail_state( "Couldn't create array, plugin shutting down. (g_aGames)" );
  71.    
  72.     #if defined USE_DEBUG
  73.    
  74.     set_task( 3.5, "taskDebugLoadedPlugins" );
  75.    
  76.     #endif
  77.    
  78. }
  79.  
  80. public cmdSetHealth( const client )
  81. {
  82.     new szArgs[ 32 ];
  83.    
  84.     read_args( szArgs, charsmax( szArgs ) );
  85.    
  86.     remove_quotes( szArgs );
  87.    
  88.     if ( !is_str_num( szArgs ) )
  89.     {
  90.         ColorPrint( client, "You need to use^4 number^1 only." );
  91.        
  92.         client_cmd( client, "messagemode set_health" );
  93.        
  94.         return 1;
  95.     }
  96.    
  97.     g_mIndex[ client ][ g_mHealth ] = str_to_num( szArgs );
  98.    
  99.     return cmdSecondaryMenu( client );
  100. }
  101.  
  102. /* Natives & API */
  103.  
  104. public plugin_natives( )
  105. {
  106.     register_native( "register_custome_lr", "RegisterCustomeGame" );
  107.     register_native( "register_shot_lr",    "RegisterShotGame" );
  108. }
  109.  
  110. stock RegisterGame( const iCategory, const iParams )
  111. {
  112.     if ( iParams != 2 )
  113.     {
  114.         log_error( AMX_ERR_PARAMS, "Wrong paremeters." );
  115.        
  116.         return -1;
  117.     }
  118.    
  119.     static aData[ GAME_DATA ];
  120.     static iPosition;
  121.    
  122.     get_string( 1, aData[ GAME_NAME ], 31 );
  123.    
  124.     aData[ GAME_VICTIM ]    = bool: get_param( 2 );
  125.    
  126.     switch ( iCategory )
  127.     {
  128.         case LR_CUSTOME_BATTLES:
  129.             iPosition   = ArraySize( g_aCustomeGames ),
  130.             ArrayPushArray( g_aCustomeGames, aData );
  131.        
  132.         case LR_SHOT_FOR_SHOT:
  133.             iPosition   = ArraySize( g_aShotGames ),
  134.             ArrayPushArray( g_aShotGames, aData );
  135.        
  136.         default:
  137.             return -1;
  138.     }
  139.    
  140.     #if defined USE_DEBUG  
  141.    
  142.     log_amx( "[LR API - DEBUG] Successfuly created a last request game: '%s' (#%i).", aData[ GAME_NAME ], iPosition );
  143.    
  144.     #endif
  145.    
  146.     return iPosition;
  147. }
  148.    
  149.  
  150. public RegisterCustomeGame( const iPlugin, const iParams )
  151. {
  152.     return RegisterGame( LR_CUSTOME_BATTLES, iParams );
  153. }
  154.  
  155. public RegisterShotGame( const iPlugin, const iParams )
  156. {
  157.     return RegisterGame( LR_SHOT_FOR_SHOT, iParams );
  158. }
  159.  
  160. /* Tasks */
  161.  
  162. #if defined USE_DEBUG
  163.  
  164. public taskDebugLoadedPlugins( ) // For debug purposes
  165. {
  166.     log_amx( "[LR API - DEBUG] Successfuly created '#%i' custome games.", ArraySize( g_aCustomeGames ) );
  167. }  
  168.  
  169. #endif
  170.  
  171. enum _:CATEGORIES_DATA
  172. {
  173.     CATEGORY_ID,
  174.     CATEGORY_NAME[ 32 ]
  175. };
  176.  
  177. new szCategories[ LR_CATEGORIES_ID ][ CATEGORIES_DATA ] =
  178. {
  179.     { LR_CUSTOME_BATTLES,   "Custome Battles" },
  180.     { LR_SHOT_FOR_SHOT, "Shot for Shot" }
  181. };
  182.  
  183. public taskCountdownBeforeBattle( )
  184. {
  185.     if ( g_iCountdown < 1 )
  186.     {
  187.         // Ended countdown start lr
  188.        
  189.         return 1;
  190.     }
  191.    
  192.     static Vox[ 32 ], aData[ GAME_DATA ];
  193.    
  194.     num_to_word( g_iCountdown, Vox, charsmax( Vox ) );
  195.    
  196.     client_cmd( 0, "spk ^"vox/%s^"", Vox );
  197.    
  198.     ArrayGetArray( g_aCustomeGames, g_iGameId, aData );
  199.    
  200.     set_hudmessage( 0, 255, 255, -1.0, 0.35, 0, 0.0, 1.0, 0.1, 0.1, 1 );
  201.     show_hudmessage( 0, "%s - %s^nWill start in %i SECOND%s", szCategories[ g_iCategoryId ][ CATEGORY_NAME ], aData[ GAME_NAME ], g_iCountdown, ( g_iCountdown < 2 ) ? "" : "s" );
  202.    
  203.     g_iCountdown--;
  204.    
  205.     set_task( 1.0, "taskCountdownBeforeBattle", TASKID_COUNTDOWN );
  206.    
  207.     return 1;
  208. }
  209.    
  210. /* Main Menu */
  211.  
  212. public cmdMainMenu( const client )
  213. {
  214.     if ( ArraySize( g_aCustomeGames ) < 1/* && ArraySize( g_aShotGames ) < 1 */ )
  215.         return 1;
  216.    
  217.     static Menu;
  218.    
  219.     formatex( szItem, charsmax( szItem ), "\r[%s]\w Last Request Menu^n^nSelect a category!", szPrefix );
  220.    
  221.     Menu    = menu_create( szItem, "handlerMainMenu" );
  222.    
  223.     if ( ArraySize( g_aCustomeGames ) > 0 )
  224.         menu_additem( Menu, "Custome Battles", "0" );
  225.    
  226.     if ( ArraySize( g_aShotGames ) > 0 )
  227.         menu_additem( Menu, "Shot for Shot", "1" );
  228.    
  229.     menu_display( client, Menu );
  230.    
  231.     return 1;
  232. }
  233.  
  234. public handlerMainMenu( client, Menu, Item )
  235. {
  236.     if ( Item == MENU_EXIT )
  237.     {
  238.         menu_destroy( Menu );
  239.        
  240.         return 1;
  241.     }
  242.    
  243.     static mData[ 6 ], Trash;
  244.    
  245.     menu_item_getinfo( Menu, Item, Trash, mData, charsmax( mData ), _,_, Trash );
  246.    
  247.     g_mIndex[ client ][ g_mCategory ]   = str_to_num( mData );
  248.    
  249.     g_mIndex[ client ][ g_mVictim ]     = 0;
  250.     g_mIndex[ client ][ g_mBattle ]     = -1;
  251.     g_mIndex[ client ][ g_mHealth ]     = MINIMUM_HEALTH;
  252.     g_mIndex[ client ][ g_mCountdown ]  = MINIMUM_COUNTDOWN;
  253.    
  254.     g_mIndex[ client ][ bFreeze ]       = false;
  255.    
  256.     switch ( gIndex( client, g_mCategory ) )
  257.     {
  258.         case 0: // Custome battles
  259.         {
  260.             return cmdSecondaryMenu( client );
  261.         }
  262.     }
  263.    
  264.     return 1;
  265. }
  266.  
  267. /* Secondary Menu */
  268.  
  269. public cmdSecondaryMenu( const client )
  270. {
  271.     static Menu, szBuffer[ 128 ];
  272.    
  273.     formatex( szItem, charsmax( szItem ), "\r[%s]\w Last Request Menu^n^nCustomize your battle!", szPrefix );
  274.    
  275.     Menu    = menu_create( szItem, "handlerSecondaryMenu" );
  276.    
  277.     // 1. Selected victim
  278.     if ( gIndex( client, g_mVictim ) == 0 )
  279.         szBuffer    = "\r NONE";
  280.    
  281.     else
  282.         formatex( szBuffer, charsmax( szBuffer ), "\y %s", szName( gIndex( client, g_mVictim ) ) );
  283.    
  284.     formatex( szItem, charsmax( szItem ), "Selected victim: %s", szBuffer );
  285.    
  286.     menu_additem( Menu, szItem );
  287.    
  288.     // 2. Selected battle
  289.     if ( gIndex( client, g_mBattle ) == -1 )
  290.         szBuffer    = "\r NONE";
  291.    
  292.     else
  293.     {
  294.         static aData[ GAME_DATA ];
  295.        
  296.         ArrayGetArray( g_aCustomeGames, gIndex( client, g_mBattle ), aData );
  297.        
  298.         formatex( szBuffer, charsmax( szBuffer ), "\y %s", aData[ GAME_NAME ] );
  299.     }
  300.    
  301.     formatex( szItem, charsmax( szItem ), "Selected battle: %s^n", szBuffer );
  302.    
  303.     menu_additem( Menu, szItem );
  304.    
  305.     // 3. Set Health
  306.     formatex( szItem, charsmax( szItem ), "Set health:\y %i\d HEALTH", gIndex( client, g_mHealth ) );
  307.    
  308.     menu_additem( Menu, szItem );
  309.    
  310.     // 4. Countdown
  311.     formatex( szItem, charsmax( szItem ), "Countdown:\y %i\d SECONDS", gIndex( client, g_mCountdown ) );
  312.    
  313.     menu_additem( Menu, szItem );
  314.    
  315.     // 5. Freeze
  316.     formatex( szItem, charsmax( szItem ), "Freeze: %s^n", gIndex( client, bFreeze ) ? "\r Yes" : "\y No" );
  317.    
  318.     menu_additem( Menu, szItem );
  319.    
  320.     // 6. Select Rules
  321.     menu_additem( Menu, "Select rules^n" );
  322.    
  323.     // 7. Start last-request
  324.     menu_additem( Menu, "\rStart last request" );
  325.    
  326.     menu_setprop( Menu, MPROP_EXITNAME, "Back" );
  327.    
  328.     menu_display( client, Menu );
  329.    
  330.     return 1;
  331. }
  332.  
  333. public handlerSecondaryMenu( client, Menu, Item )
  334. {
  335.     if ( Item == MENU_EXIT )
  336.     {
  337.         menu_destroy( Menu );
  338.        
  339.         return cmdMainMenu( client );
  340.     }
  341.    
  342.     switch ( Item )
  343.     {
  344.         case 0: // Selected victim
  345.             return cmdSelectVictim( client );
  346.        
  347.         case 1: // Selected battle
  348.             return cmdSelectBattle( client );
  349.        
  350.         case 2: // Set health
  351.         {
  352.             client_cmd( client, "messagemode set_health" );
  353.            
  354.             return 1;
  355.         }
  356.        
  357.         case 3: // Countdown
  358.         {
  359.             if ( gIndex( client, g_mCountdown ) >= MAXIMUM_COUNTDOWN )
  360.                 g_mIndex[ client ][ g_mCountdown ]  = MINIMUM_COUNTDOWN - 1;
  361.            
  362.             g_mIndex[ client ][ g_mCountdown ]++;
  363.         }
  364.        
  365.         case 4: // Freeze
  366.             g_mIndex[ client ][ bFreeze ]   = !g_mIndex[ client ][ bFreeze ];
  367.        
  368.         case 5: // Select rules
  369.         {
  370.             if ( gIndex( client, g_mVictim ) == 0 || gIndex( client, g_mBattle ) == -1 )
  371.             {
  372.                 ColorPrint( client, "You need to select a^3 victim^1 and a^4 battle^1 in order to select^3 rules^1." );
  373.                
  374.                 return cmdSecondaryMenu( client );
  375.             }
  376.            
  377.             return cmdSelectRules( client );
  378.         }
  379.        
  380.         case 6: // Start last-request
  381.         {
  382.             static g_iVictim;
  383.            
  384.             g_iVictim   = gIndex( client, g_mVictim );
  385.            
  386.             fm_set_user_godmode( client, 0 );
  387.             fm_set_user_godmode( g_iVictim, 0 );
  388.            
  389.             fm_set_user_noclip( client, 0 );
  390.             fm_set_user_noclip( g_iVictim, 0 );
  391.            
  392.             fm_set_user_gravity( client, 1.0 );
  393.             fm_set_user_gravity( g_iVictim, 1.0 );
  394.            
  395.             fm_set_user_health( client, gIndex( client, g_mHealth ) );
  396.             fm_set_user_health( g_iVictim, gIndex( client, g_mHealth ) );
  397.            
  398.             fm_set_user_armor( client, 0 );
  399.             fm_set_user_armor( g_iVictim, 0 );
  400.            
  401.             fm_strip_user_weapons( client );
  402.             fm_strip_user_weapons( g_iVictim );
  403.            
  404.             g_iCategoryId   = gIndex( client, g_mCategory );
  405.             g_iGameId   = gIndex( client, g_mBattle );
  406.             g_iCountdown    = gIndex( client, g_mCountdown );
  407.            
  408.             ExecuteForward( g_iForwards[ FWD_GAME_START ], Item, client, g_mVictim, g_iCategoryId, g_iGameId, g_iCountdown );
  409.            
  410.             taskCountdownBeforeBattle( );
  411.            
  412.             return 1;
  413.         }
  414.     }
  415.    
  416.     menu_destroy( Menu );
  417.    
  418.     return cmdSecondaryMenu( client );
  419. }
  420.  
  421. /* Select vicitm menu */
  422.  
  423. public cmdSelectVictim( const client )
  424. {
  425.     static Menu;
  426.    
  427.     formatex( szItem, charsmax( szItem ), "\r[%s]\w Last Request Menu^n^nSelect a victim!", szPrefix );
  428.    
  429.     Menu    = menu_create( szItem, "handlerSelectVictim" );
  430.    
  431.     static Players[ 32 ], mData[ 6 ];
  432.     static i, iNum, index;
  433.    
  434.     get_players( Players, iNum, "ch" );
  435.    
  436.     for ( i = 0; i < iNum; i++ )
  437.     {
  438.         index   = Players[ i ];
  439.        
  440.         num_to_str( index, mData, charsmax( mData ) );
  441.        
  442.         menu_additem( Menu, szName( index ), mData );
  443.     }
  444.    
  445.     menu_setprop( Menu, MPROP_EXITNAME, "Back" );
  446.    
  447.     menu_display( client, Menu );
  448.    
  449.     return 1;
  450. }
  451.  
  452. public handlerSelectVictim( client, Menu, Item )
  453. {
  454.     if ( Item != MENU_EXIT )
  455.     {
  456.         static mData[ 6 ], Trash;
  457.        
  458.         menu_item_getinfo( Menu, Item, Trash, mData, charsmax( mData ), _,_, Trash );
  459.        
  460.         g_mIndex[ client ][ g_mVictim ] = str_to_num( mData );
  461.     }
  462.    
  463.     menu_destroy( Menu );
  464.    
  465.     return cmdSecondaryMenu( client );
  466. }
  467.  
  468. /* Select battle menu */
  469.  
  470. public cmdSelectBattle( const client )
  471. {
  472.     static Menu;
  473.    
  474.     formatex( szItem, charsmax( szItem ), "\r[%s]\w Last Request Menu^n^nSelect a battle!", szPrefix );
  475.    
  476.     Menu     = menu_create( szItem, "handlerSelectBattle" );
  477.    
  478.     static aData[ GAME_DATA ], mData[ 6 ];
  479.     static i;
  480.    
  481.     for ( i = 0; i < ArraySize( g_aCustomeGames ); i++ )
  482.     {
  483.         ArrayGetArray( g_aCustomeGames, i, aData );
  484.        
  485.         num_to_str( i, mData, charsmax( mData ) );
  486.        
  487.         menu_additem( Menu, aData[ GAME_NAME ], mData );
  488.     }
  489.    
  490.     menu_setprop( Menu, MPROP_EXITNAME, "Back" );
  491.    
  492.     menu_display( client, Menu );
  493.    
  494.     return 1;
  495. }
  496.  
  497. public handlerSelectBattle( client, Menu, Item )
  498. {
  499.     if ( Item != MENU_EXIT )
  500.     {
  501.         static mData[ 6 ], Trash;
  502.        
  503.         menu_item_getinfo( Menu, Item, Trash, mData, charsmax( mData ), _,_, Trash );
  504.        
  505.         g_mIndex[ client ][ g_mBattle ] = str_to_num( mData );
  506.     }
  507.    
  508.     menu_destroy( Menu );
  509.    
  510.     return cmdSecondaryMenu( client );
  511. }
  512.  
  513. /* Select rules Menu */
  514.  
  515. enum _:GAME_RULES
  516. {
  517.     bNoBunnyhop,
  518.     bNoZoom,
  519.     bNoPunch,
  520.     nHeadshot,
  521.     bNoDuck,
  522.     bNoJump
  523. };
  524.  
  525. new const szRules[ GAME_RULES ][ ]  =
  526. {
  527.     "No Bunnyhop",
  528.     "No Zoom",
  529.     "No Punch",
  530.     "Headshot",
  531.     "No Duck",
  532.     "No Jump"
  533. };
  534.  
  535. new bool: bRules[ GAME_RULES ];
  536.  
  537. public cmdSelectRules( const client )
  538. {
  539.     static Menu;
  540.    
  541.     formatex( szItem, charsmax( szItem ), "\r[%s]\w Last Request Menu^n^nSelect battle rules!", szPrefix );
  542.    
  543.     Menu     = menu_create( szItem, "handlerSelectRules" );
  544.    
  545.     static i;
  546.    
  547.     for ( i = 0; i < sizeof ( szRules ); i++ )
  548.     {
  549.         formatex( szItem, charsmax( szItem ), "%s:%s", szRules[ i ], bRules[ i ] ? "\r ON" : "\y OFF" );
  550.        
  551.         menu_additem( Menu, szItem );
  552.     }
  553.    
  554.     menu_setprop( Menu, MPROP_EXITNAME, "Back" );
  555.    
  556.     menu_display( client, Menu );
  557.    
  558.     return 1;
  559. }
  560.  
  561. public handlerSelectRules( client, Menu, Item )
  562. {
  563.     if ( Item != MENU_EXIT )
  564.     {
  565.         bRules[ Item ]  = !bRules[ Item ];
  566.        
  567.         return cmdSelectRules( client );
  568.     }
  569.    
  570.     menu_destroy( Menu );
  571.    
  572.     return cmdSecondaryMenu( client );
  573. }
  574.  
  575. /* Stocks */
  576.  
  577. stock ColorPrint( const index, const string[], any:... )
  578. {
  579.     new szMsg[ 512 ], Players[ 32 ], PNum = 1;
  580.    
  581.     static iLen; iLen = formatex( szMsg, charsmax( szMsg ), "^4[%s]^1 ", szPrefix );
  582.    
  583.     vformat( szMsg[ iLen ], charsmax( szMsg ) - iLen, string, 3 );
  584.    
  585.     if ( index )
  586.         Players[ 0 ] = index;
  587.    
  588.     else
  589.         get_players( Players, PNum, "ch" );
  590.    
  591.     for ( new i; i < PNum; i++ )
  592.     {
  593.         if( is_user_connected( Players[ i ] ) )
  594.         {
  595.             message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, Players[ i ] );
  596.            
  597.             write_byte( Players[ i ] );
  598.            
  599.             write_string( szMsg );
  600.            
  601.             message_end( );
  602.         }
  603.     }
  604.    
  605.     return 1;
  606. }
  607.  
  608. stock szName( const index )
  609. {
  610.     static g_szName[ 32 ];
  611.    
  612.     get_user_name( index, g_szName, 31 );
  613.    
  614.     return g_szName;
  615. }
Advertisement
Add Comment
Please, Sign In to add comment