Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Includes
- #include < amxmodx >
- #include < fakemeta_util >
- #include < lastrequest_const >
- // Defines
- //#define USE_DEBUG
- #define MINIMUM_COUNTDOWN 3
- #define MAXIMUM_COUNTDOWN 5
- #define TASKID_COUNTDOWN 12348 // Don't touch
- #define MINIMUM_HEALTH 100
- // Enums
- enum _:GAME_DATA
- {
- GAME_NAME[ 32 ],
- bool: GAME_VICTIM
- };
- new Array: g_aCustomeGames;
- new Array: g_aShotGames;
- new szItem[ 128 ];
- new const szPrefix[ ] = "AMXX";
- enum _: g_mClientData
- {
- g_mCategory,
- g_mVictim,
- g_mBattle,
- g_mHealth,
- g_mCountdown,
- bool: bFreeze
- };
- new g_mIndex[ 33 ][ g_mClientData ];
- #define gIndex(%1,%2) g_mIndex[ %1 ][ %2 ]
- new g_iCountdown;
- new g_iGameId;
- new g_iCategoryId;
- enum _:FWD_ID
- {
- FWD_GAME_START,
- FWD_GAME_END
- };
- new g_iForwards[ FWD_ID ];
- public plugin_init()
- {
- register_plugin( "Jailbreak: Last Request (API)", "1.0", "Rejack" );
- register_clcmd( "say /yan", "cmdMainMenu" );
- register_concmd( "set_health", "cmdSetHealth" );
- g_iForwards[ FWD_GAME_START ] = CreateMultiForward( "FwdLrStarted", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_CELL );
- g_iForwards[ FWD_GAME_END ] = CreateMultiForward( "FwdLrEnded", ET_IGNORE, FP_CELL, FP_CELL );
- g_aCustomeGames = ArrayCreate( GAME_DATA );
- if ( g_aCustomeGames == Invalid_Array )
- set_fail_state( "Couldn't create array, plugin shutting down. (g_aGames)" );
- #if defined USE_DEBUG
- set_task( 3.5, "taskDebugLoadedPlugins" );
- #endif
- }
- public cmdSetHealth( const client )
- {
- new szArgs[ 32 ];
- read_args( szArgs, charsmax( szArgs ) );
- remove_quotes( szArgs );
- if ( !is_str_num( szArgs ) )
- {
- ColorPrint( client, "You need to use^4 number^1 only." );
- client_cmd( client, "messagemode set_health" );
- return 1;
- }
- g_mIndex[ client ][ g_mHealth ] = str_to_num( szArgs );
- return cmdSecondaryMenu( client );
- }
- /* Natives & API */
- public plugin_natives( )
- {
- register_native( "register_custome_lr", "RegisterCustomeGame" );
- register_native( "register_shot_lr", "RegisterShotGame" );
- }
- stock RegisterGame( const iCategory, const iParams )
- {
- if ( iParams != 2 )
- {
- log_error( AMX_ERR_PARAMS, "Wrong paremeters." );
- return -1;
- }
- static aData[ GAME_DATA ];
- static iPosition;
- get_string( 1, aData[ GAME_NAME ], 31 );
- aData[ GAME_VICTIM ] = bool: get_param( 2 );
- switch ( iCategory )
- {
- case LR_CUSTOME_BATTLES:
- iPosition = ArraySize( g_aCustomeGames ),
- ArrayPushArray( g_aCustomeGames, aData );
- case LR_SHOT_FOR_SHOT:
- iPosition = ArraySize( g_aShotGames ),
- ArrayPushArray( g_aShotGames, aData );
- default:
- return -1;
- }
- #if defined USE_DEBUG
- log_amx( "[LR API - DEBUG] Successfuly created a last request game: '%s' (#%i).", aData[ GAME_NAME ], iPosition );
- #endif
- return iPosition;
- }
- public RegisterCustomeGame( const iPlugin, const iParams )
- {
- return RegisterGame( LR_CUSTOME_BATTLES, iParams );
- }
- public RegisterShotGame( const iPlugin, const iParams )
- {
- return RegisterGame( LR_SHOT_FOR_SHOT, iParams );
- }
- /* Tasks */
- #if defined USE_DEBUG
- public taskDebugLoadedPlugins( ) // For debug purposes
- {
- log_amx( "[LR API - DEBUG] Successfuly created '#%i' custome games.", ArraySize( g_aCustomeGames ) );
- }
- #endif
- enum _:CATEGORIES_DATA
- {
- CATEGORY_ID,
- CATEGORY_NAME[ 32 ]
- };
- new szCategories[ LR_CATEGORIES_ID ][ CATEGORIES_DATA ] =
- {
- { LR_CUSTOME_BATTLES, "Custome Battles" },
- { LR_SHOT_FOR_SHOT, "Shot for Shot" }
- };
- public taskCountdownBeforeBattle( )
- {
- if ( g_iCountdown < 1 )
- {
- // Ended countdown start lr
- return 1;
- }
- static Vox[ 32 ], aData[ GAME_DATA ];
- num_to_word( g_iCountdown, Vox, charsmax( Vox ) );
- client_cmd( 0, "spk ^"vox/%s^"", Vox );
- ArrayGetArray( g_aCustomeGames, g_iGameId, aData );
- set_hudmessage( 0, 255, 255, -1.0, 0.35, 0, 0.0, 1.0, 0.1, 0.1, 1 );
- 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" );
- g_iCountdown--;
- set_task( 1.0, "taskCountdownBeforeBattle", TASKID_COUNTDOWN );
- return 1;
- }
- /* Main Menu */
- public cmdMainMenu( const client )
- {
- if ( ArraySize( g_aCustomeGames ) < 1/* && ArraySize( g_aShotGames ) < 1 */ )
- return 1;
- static Menu;
- formatex( szItem, charsmax( szItem ), "\r[%s]\w Last Request Menu^n^nSelect a category!", szPrefix );
- Menu = menu_create( szItem, "handlerMainMenu" );
- if ( ArraySize( g_aCustomeGames ) > 0 )
- menu_additem( Menu, "Custome Battles", "0" );
- if ( ArraySize( g_aShotGames ) > 0 )
- menu_additem( Menu, "Shot for Shot", "1" );
- menu_display( client, Menu );
- return 1;
- }
- public handlerMainMenu( client, Menu, Item )
- {
- if ( Item == MENU_EXIT )
- {
- menu_destroy( Menu );
- return 1;
- }
- static mData[ 6 ], Trash;
- menu_item_getinfo( Menu, Item, Trash, mData, charsmax( mData ), _,_, Trash );
- g_mIndex[ client ][ g_mCategory ] = str_to_num( mData );
- g_mIndex[ client ][ g_mVictim ] = 0;
- g_mIndex[ client ][ g_mBattle ] = -1;
- g_mIndex[ client ][ g_mHealth ] = MINIMUM_HEALTH;
- g_mIndex[ client ][ g_mCountdown ] = MINIMUM_COUNTDOWN;
- g_mIndex[ client ][ bFreeze ] = false;
- switch ( gIndex( client, g_mCategory ) )
- {
- case 0: // Custome battles
- {
- return cmdSecondaryMenu( client );
- }
- }
- return 1;
- }
- /* Secondary Menu */
- public cmdSecondaryMenu( const client )
- {
- static Menu, szBuffer[ 128 ];
- formatex( szItem, charsmax( szItem ), "\r[%s]\w Last Request Menu^n^nCustomize your battle!", szPrefix );
- Menu = menu_create( szItem, "handlerSecondaryMenu" );
- // 1. Selected victim
- if ( gIndex( client, g_mVictim ) == 0 )
- szBuffer = "\r NONE";
- else
- formatex( szBuffer, charsmax( szBuffer ), "\y %s", szName( gIndex( client, g_mVictim ) ) );
- formatex( szItem, charsmax( szItem ), "Selected victim: %s", szBuffer );
- menu_additem( Menu, szItem );
- // 2. Selected battle
- if ( gIndex( client, g_mBattle ) == -1 )
- szBuffer = "\r NONE";
- else
- {
- static aData[ GAME_DATA ];
- ArrayGetArray( g_aCustomeGames, gIndex( client, g_mBattle ), aData );
- formatex( szBuffer, charsmax( szBuffer ), "\y %s", aData[ GAME_NAME ] );
- }
- formatex( szItem, charsmax( szItem ), "Selected battle: %s^n", szBuffer );
- menu_additem( Menu, szItem );
- // 3. Set Health
- formatex( szItem, charsmax( szItem ), "Set health:\y %i\d HEALTH", gIndex( client, g_mHealth ) );
- menu_additem( Menu, szItem );
- // 4. Countdown
- formatex( szItem, charsmax( szItem ), "Countdown:\y %i\d SECONDS", gIndex( client, g_mCountdown ) );
- menu_additem( Menu, szItem );
- // 5. Freeze
- formatex( szItem, charsmax( szItem ), "Freeze: %s^n", gIndex( client, bFreeze ) ? "\r Yes" : "\y No" );
- menu_additem( Menu, szItem );
- // 6. Select Rules
- menu_additem( Menu, "Select rules^n" );
- // 7. Start last-request
- menu_additem( Menu, "\rStart last request" );
- menu_setprop( Menu, MPROP_EXITNAME, "Back" );
- menu_display( client, Menu );
- return 1;
- }
- public handlerSecondaryMenu( client, Menu, Item )
- {
- if ( Item == MENU_EXIT )
- {
- menu_destroy( Menu );
- return cmdMainMenu( client );
- }
- switch ( Item )
- {
- case 0: // Selected victim
- return cmdSelectVictim( client );
- case 1: // Selected battle
- return cmdSelectBattle( client );
- case 2: // Set health
- {
- client_cmd( client, "messagemode set_health" );
- return 1;
- }
- case 3: // Countdown
- {
- if ( gIndex( client, g_mCountdown ) >= MAXIMUM_COUNTDOWN )
- g_mIndex[ client ][ g_mCountdown ] = MINIMUM_COUNTDOWN - 1;
- g_mIndex[ client ][ g_mCountdown ]++;
- }
- case 4: // Freeze
- g_mIndex[ client ][ bFreeze ] = !g_mIndex[ client ][ bFreeze ];
- case 5: // Select rules
- {
- if ( gIndex( client, g_mVictim ) == 0 || gIndex( client, g_mBattle ) == -1 )
- {
- ColorPrint( client, "You need to select a^3 victim^1 and a^4 battle^1 in order to select^3 rules^1." );
- return cmdSecondaryMenu( client );
- }
- return cmdSelectRules( client );
- }
- case 6: // Start last-request
- {
- static g_iVictim;
- g_iVictim = gIndex( client, g_mVictim );
- fm_set_user_godmode( client, 0 );
- fm_set_user_godmode( g_iVictim, 0 );
- fm_set_user_noclip( client, 0 );
- fm_set_user_noclip( g_iVictim, 0 );
- fm_set_user_gravity( client, 1.0 );
- fm_set_user_gravity( g_iVictim, 1.0 );
- fm_set_user_health( client, gIndex( client, g_mHealth ) );
- fm_set_user_health( g_iVictim, gIndex( client, g_mHealth ) );
- fm_set_user_armor( client, 0 );
- fm_set_user_armor( g_iVictim, 0 );
- fm_strip_user_weapons( client );
- fm_strip_user_weapons( g_iVictim );
- g_iCategoryId = gIndex( client, g_mCategory );
- g_iGameId = gIndex( client, g_mBattle );
- g_iCountdown = gIndex( client, g_mCountdown );
- ExecuteForward( g_iForwards[ FWD_GAME_START ], Item, client, g_mVictim, g_iCategoryId, g_iGameId, g_iCountdown );
- taskCountdownBeforeBattle( );
- return 1;
- }
- }
- menu_destroy( Menu );
- return cmdSecondaryMenu( client );
- }
- /* Select vicitm menu */
- public cmdSelectVictim( const client )
- {
- static Menu;
- formatex( szItem, charsmax( szItem ), "\r[%s]\w Last Request Menu^n^nSelect a victim!", szPrefix );
- Menu = menu_create( szItem, "handlerSelectVictim" );
- static Players[ 32 ], mData[ 6 ];
- static i, iNum, index;
- get_players( Players, iNum, "ch" );
- for ( i = 0; i < iNum; i++ )
- {
- index = Players[ i ];
- num_to_str( index, mData, charsmax( mData ) );
- menu_additem( Menu, szName( index ), mData );
- }
- menu_setprop( Menu, MPROP_EXITNAME, "Back" );
- menu_display( client, Menu );
- return 1;
- }
- public handlerSelectVictim( client, Menu, Item )
- {
- if ( Item != MENU_EXIT )
- {
- static mData[ 6 ], Trash;
- menu_item_getinfo( Menu, Item, Trash, mData, charsmax( mData ), _,_, Trash );
- g_mIndex[ client ][ g_mVictim ] = str_to_num( mData );
- }
- menu_destroy( Menu );
- return cmdSecondaryMenu( client );
- }
- /* Select battle menu */
- public cmdSelectBattle( const client )
- {
- static Menu;
- formatex( szItem, charsmax( szItem ), "\r[%s]\w Last Request Menu^n^nSelect a battle!", szPrefix );
- Menu = menu_create( szItem, "handlerSelectBattle" );
- static aData[ GAME_DATA ], mData[ 6 ];
- static i;
- for ( i = 0; i < ArraySize( g_aCustomeGames ); i++ )
- {
- ArrayGetArray( g_aCustomeGames, i, aData );
- num_to_str( i, mData, charsmax( mData ) );
- menu_additem( Menu, aData[ GAME_NAME ], mData );
- }
- menu_setprop( Menu, MPROP_EXITNAME, "Back" );
- menu_display( client, Menu );
- return 1;
- }
- public handlerSelectBattle( client, Menu, Item )
- {
- if ( Item != MENU_EXIT )
- {
- static mData[ 6 ], Trash;
- menu_item_getinfo( Menu, Item, Trash, mData, charsmax( mData ), _,_, Trash );
- g_mIndex[ client ][ g_mBattle ] = str_to_num( mData );
- }
- menu_destroy( Menu );
- return cmdSecondaryMenu( client );
- }
- /* Select rules Menu */
- enum _:GAME_RULES
- {
- bNoBunnyhop,
- bNoZoom,
- bNoPunch,
- nHeadshot,
- bNoDuck,
- bNoJump
- };
- new const szRules[ GAME_RULES ][ ] =
- {
- "No Bunnyhop",
- "No Zoom",
- "No Punch",
- "Headshot",
- "No Duck",
- "No Jump"
- };
- new bool: bRules[ GAME_RULES ];
- public cmdSelectRules( const client )
- {
- static Menu;
- formatex( szItem, charsmax( szItem ), "\r[%s]\w Last Request Menu^n^nSelect battle rules!", szPrefix );
- Menu = menu_create( szItem, "handlerSelectRules" );
- static i;
- for ( i = 0; i < sizeof ( szRules ); i++ )
- {
- formatex( szItem, charsmax( szItem ), "%s:%s", szRules[ i ], bRules[ i ] ? "\r ON" : "\y OFF" );
- menu_additem( Menu, szItem );
- }
- menu_setprop( Menu, MPROP_EXITNAME, "Back" );
- menu_display( client, Menu );
- return 1;
- }
- public handlerSelectRules( client, Menu, Item )
- {
- if ( Item != MENU_EXIT )
- {
- bRules[ Item ] = !bRules[ Item ];
- return cmdSelectRules( client );
- }
- menu_destroy( Menu );
- return cmdSecondaryMenu( client );
- }
- /* Stocks */
- stock ColorPrint( const index, const string[], any:... )
- {
- new szMsg[ 512 ], Players[ 32 ], PNum = 1;
- static iLen; iLen = formatex( szMsg, charsmax( szMsg ), "^4[%s]^1 ", szPrefix );
- vformat( szMsg[ iLen ], charsmax( szMsg ) - iLen, string, 3 );
- if ( index )
- Players[ 0 ] = index;
- else
- get_players( Players, PNum, "ch" );
- for ( new i; i < PNum; i++ )
- {
- if( is_user_connected( Players[ i ] ) )
- {
- message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, Players[ i ] );
- write_byte( Players[ i ] );
- write_string( szMsg );
- message_end( );
- }
- }
- return 1;
- }
- stock szName( const index )
- {
- static g_szName[ 32 ];
- get_user_name( index, g_szName, 31 );
- return g_szName;
- }
Advertisement
Add Comment
Please, Sign In to add comment