Junior Member
06-07-2021
, 03:20
Re: [Help] Custom Buy Menu separate to categories
#4
Quote:
Originally Posted by
Supremache
I tried to optimizing original codes:
Spoiler
PHP Code:
#include < amxmodx > #include < zombieplaguenightmare > native zp_register_extra_iteem ( const Name [] , Cost , MinPlayers , Vip , LimitInMap , LimitInRound , LimitForAllMap , LimitForAllRound , Team ) forward zp_extra_item_selecteed ( Player , Item ) /*================================== Pistols ==================================*/ native give_balrog1 ( Player ) native give_infinity ( Player ) native give_janus1 ( Player ) //native give_gunslinger(Player) /*================================== Shotguns ==================================*/ native give_spas12 ( Player ) native give_triplebarrel ( Player ) native give_balrog11 ( Player ) // Admin /*================================== Automated Rifles ==================================*/ native give_g11 ( Player ) native give_cv80 ( Player ) native give_balrog3 ( Player ) native give_balrog5 ( Player ) native give_cartblue ( Player ) native give_skull3 ( Player ) native give_skull4 ( Player ) native give_plasma ( Player ) //Admin /*================================== Sniper Rifles ==================================*/ native give_bow ( Player ) native give_m95 ( Player ) /*================================== Heavy Machiene Guns ==================================*/ native give_janus7 ( Player ) /*================================== Extra Equipment ==================================*/ native give_at4 ( Player ) native give_spear ( Player ) native give_chainsaw ( Player ) native give_bazooka ( Player ) /*================================== Settings ==================================*/ enum _ : eSettings { Name [ 32 ], // Item Name Cost , // Item Cost MinPlayers , // Item Min Players Vip , // Item VIP Only pLimitMap , // Item Personal Limit Map pLimitRound , // Item Personal Limit Round gLimitMap , // Item Global Limit Map gRoundLimit // Item Global Round Limit }; new const g_ItemsData [ ][ eSettings ] = { { "Balrog11" , 20000 , 0 , 1 , 0 , 0 , 0 , 0 }, { "PlasmaGun" , 10000 , 0 , 1 , 0 , 0 , 0 , 0 }, { "Dual Infinity" , 800 , 0 , 0 , 0 , 0 , 0 , 0 }, { "Janus1" , 1000 , 0 , 0 , 0 , 0 , 0 , 0 }, { "Balrog3" , 1500 , 0 , 0 , 0 , 0 , 0 , 0 }, { "Balrog5" , 3000 , 0 , 0 , 0 , 0 , 0 , 0 }, { "Skull3" , 15000 , 0 , 0 , 0 , 0 , 0 , 0 }, { "Skull4" , 10000 , 0 , 0 , 0 , 0 , 0 , 0 }, { "Janus7" , 50000 , 0 , 1 , 0 , 0 , 0 , 0 }, { "AT4" , 30000 , 0 , 0 , 0 , 0 , 0 , 0 }, { "Bow" , 5000 , 0 , 0 , 0 , 0 , 0 , 0 }, { "CV80" , 3200 , 0 , 0 , 0 , 0 , 0 , 0 }, { "G11" , 2000 , 0 , 0 , 0 , 0 , 0 , 0 }, { "Spas12" , 2000 , 0 , 0 , 0 , 0 , 0 , 0 }, { "TripleBarrel" , 1700 , 0 , 0 , 0 , 0 , 0 , 0 }, { "M95" , 2200 , 0 , 0 , 0 , 0 , 0 , 0 }, { "Spear" , 7000 , 0 , 0 , 0 , 0 , 0 , 0 }, { "Cart Blue" , 6500 , 0 , 0 , 0 , 0 , 0 , 0 }, { "ChainSaw" , 10000 , 0 , 0 , 0 , 0 , 0 , 0 }, { "Bazooka" , 50000 , 2 , 0 , 0 , 0 , 0 , 0 }, { "Balrog-I" , 1000 , 0 , 1 , 0 , 2 , 0 , 0 } } new g_iItem public plugin_init () { for(new i = 0 ; i <= charsmax ( g_ItemsData ); i ++) g_iItem = zp_register_extra_iteem ( g_ItemsData [ i ][ Name ], g_ItemsData [ i ][ Cost ], g_ItemsData [ i ][ MinPlayers ], g_ItemsData [ i ][ Vip ], g_ItemsData [ i ][ pLimitMap ], g_ItemsData [ i ][ pLimitRound ], g_ItemsData [ i ][ gLimitMap ], g_ItemsData [ i ][ gRoundLimit ], ZP_TEAM_HUMAN ) } public zp_extra_item_selecteed ( id , Item ) { for(new i = 0 ; i <= charsmax ( g_ItemsData ); i ++) if( Item == g_iItem ) GiveWeapon ( id , i ) ; } public GiveWeapon ( Player , Weapon ) { switch( Weapon ) { case 1 : give_balrog11 ( Player ) ; case 2 : give_plasma ( Player ) ; case 3 : give_infinity ( Player ) ; case 4 : give_janus1 ( Player ) ; case 5 : give_balrog3 ( Player ) ; case 6 : give_balrog5 ( Player ) ; case 7 : give_skull3 ( Player ) ; case 8 : give_skull4 ( Player ) ; case 9 : give_janus7 ( Player ) ; case 10 : give_at4 ( Player ) ; case 11 : give_bow ( Player ) ; case 12 : give_cv80 ( Player ) ; case 13 : give_g11 ( Player ) ; case 14 : give_spas12 ( Player ) ; case 15 : give_triplebarrel ( Player ) ; case 16 : give_m95 ( Player ) ; case 17 : give_spear ( Player ) ; case 18 : give_cartblue ( Player ) ; case 19 : give_chainsaw ( Player ) ; case 20 : give_bazooka ( Player ); } }
Example:
PHP Code:
new g_iItem [ 3 ] public plugin_init () { g_iItem [ 0 ] = zp_register_extra_iteem ( "Pistols Shop" . 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) g_iItem [ 1 ] = zp_register_extra_iteem ( "Shotguns Shop" . 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) g_iItem [ 2 ] = zp_register_extra_iteem ( "Snipers Shop" . 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) } public zp_extra_item_selecteed ( id , Item ) { if( Item == g_iItem [ 0 ] ) PistolsMenu ( id ) if( Item == g_iItem [ 1 ] ) ShotgunsMenu ( id ) if( Item == g_iItem [ 2 ] ) SnipersMenu ( id ) } public PistolsMenu ( id ) { // Great the menu } public ShotgunsMenu ( id ) { // Great the menu } public SnipersMenu ( id ) { // Great the menu }
Thank you so much you legend! Thank you for the optimization. I just want to ask about the menu, how should I put the items in them?
Like this?
PHP Code:
public PistolsMenu ( id ) { new PMenu PMenu = menu_create ( "Choose your pistol" , "WeaponMenuHand" ) new Buffer [ 64 ] , Name [ 32 ] new Item , team menu_setprop ( PMenu , MPROP_NUMBER_COLOR , "\r" ); for( Item = 0 ; Item < ArraySize ( ItemName ); Item ++) { team = ArrayGetCell ( ItemTeam , Item ) if (( zp_get_user_zombie ( Player ) && ! zp_get_user_nemesis ( Player ) && ! zpnm_get_user_assassin ( Player ) && !( team & ZP_TEAM_ZOMBIE )) || (! zp_get_user_zombie ( Player ) && ! zp_get_user_survivor ( Player ) && ! zpnm_get_user_sniper ( Player ) && !( team & ZP_TEAM_HUMAN )) || ( zp_get_user_nemesis ( Player ) || ( zpnm_get_user_assassin ( Player ) && !( team & ZP_TEAM_NEMESIS )) && !( team & ZP_TEAM_ASSASSIN )) || ( zp_get_user_survivor ( Player ) && !( team & ZP_TEAM_SURVIVOR ))) continue ArrayGetString ( ItemName , Item , Name , charsmax ( Name )) if( zp_get_user_ammo_packs ( Player ) < ArrayGetCell ( ItemCost , Item )) { formatex ( Buffer , charsmax ( Buffer ), "\d%s %d$ \w[\dUnavailable\w]" , Name , ArrayGetCell ( ItemCost , Item )) } else if( ArrayGetCell ( ItemMinPlayers , Item ) && get_playersnum () < ArrayGetCell ( ItemMinPlayers , Item )) { formatex ( Buffer , charsmax ( Buffer ), "\d%s %d$ \w[\rMin Players: \y%d\w]" , Name , ArrayGetCell ( ItemCost , Item ) , ArrayGetCell ( ItemMinPlayers , Item )) } else if( ArrayGetCell ( ItemVip , Item ) && ArrayGetCell ( ItemVip , Item ) && !( get_user_flags ( Player ) & VIP )) { formatex ( Buffer , charsmax ( Buffer ), "\d%s %d$ \w[\rV.I.P Only\w]" , Name , ArrayGetCell ( ItemCost , Item )) } else if( ArrayGetCell ( ItemLimitInMapP , Item ) && ArrayGetCell ( ItemLimitInMapP , Item ) == g_LimitInMap [ Player ][ Item ]) { formatex ( Buffer , charsmax ( Buffer ), "\d%s %d$ \w[\rMap Limit: \y%d\w]" , Name , ArrayGetCell ( ItemCost , Item ) , ArrayGetCell ( ItemLimitInMapP , Item )) } else if( ArrayGetCell ( ItemLimitInRound , Item ) && ArrayGetCell ( ItemLimitInRound , Item ) == g_LimitInRound [ Player ][ Item ]) { formatex ( Buffer , charsmax ( Buffer ), "\d%s %d$ \w[\rRound Limit: \y%d\w]" , Name , ArrayGetCell ( ItemCost , Item ) , ArrayGetCell ( ItemLimitInRound , Item )) } else if( ArrayGetCell ( LimitForAllMap , Item ) && ArrayGetCell ( LimitForAllMap , Item ) == g_LimitAllMap ) { formatex ( Buffer , charsmax ( Buffer ), "\d%s %d$ \w[\rOut of Stock\w]" , Name , ArrayGetCell ( ItemCost , Item )) } else if( ArrayGetCell ( LimitForAllRound , Item ) && ArrayGetCell ( LimitForAllRound , Item ) == g_LimitAllRound ) { formatex ( Buffer , charsmax ( Buffer ), "\d%s %d$ \w[\rOut of Stock\w]" , Name , ArrayGetCell ( ItemCost , Item )) } else { formatex ( Buffer , charsmax ( Buffer ), "\w%s \y[%d$]" , Name , ArrayGetCell ( ItemCost , Item )) } menu_additem ( PMenu , Buffer ) menu_setprop ( PMenu , MPROP_NEXTNAME , "Next" ) menu_setprop ( PMenu , MPROP_BACKNAME , "Back" ) menu_setprop ( PMenu , MPROP_EXITNAME , "Exit" ) } if ( pev_valid ( Player ) == 2 ) set_pdata_int ( Player , 205 , 0 , 5 ) menu_display ( Player , PMenu , 0 ) return PLUGIN_HANDLED } public PMenuHand ( Player , Menu , Item ) { if(! is_user_connected ( Player ) || ! is_user_alive ( Player )) return PLUGIN_HANDLED if( zp_get_user_zombie ( Player )) return PLUGIN_HANDLED if( Item == MENU_EXIT ) { menu_destroy ( PMenu ) return PLUGIN_HANDLED } new Cost = ArrayGetCell ( ItemCost , Item ) if( zp_get_user_ammo_packs ( Player ) < Cost ) { client_print ( Player , print_center , "Not enough money" ) return PLUGIN_HANDLED } if( ArrayGetCell ( ItemMinPlayers , Item ) && get_playersnum () < ArrayGetCell ( ItemMinPlayers , Item )) { client_print ( Player , print_center , "Need more players" ) return PLUGIN_HANDLED } if( ArrayGetCell ( ItemVip , Item ) && ArrayGetCell ( ItemVip , Item ) && !( get_user_flags ( Player ) & VIP )) { client_print ( Player , print_center , "You need to be V.I.P" ) return PLUGIN_HANDLED } if( ArrayGetCell ( ItemLimitInMapP , Item ) && ArrayGetCell ( ItemLimitInMapP , Item ) == g_LimitInMap [ Player ][ Item ]) { client_print ( Player , print_center , "Weapon map limit reached: [%d]" , ArrayGetCell ( ItemLimitInMapP , Item )) return PLUGIN_HANDLED } if( ArrayGetCell ( ItemLimitInRound , Item ) && ArrayGetCell ( ItemLimitInRound , Item ) == g_LimitInRound [ Player ][ Item ]) { client_print ( Player , print_center , "Weapon round limit reached: [%d]" , ArrayGetCell ( ItemLimitInRound , Item )) return PLUGIN_HANDLED } if( ArrayGetCell ( LimitForAllMap , Item ) && ArrayGetCell ( LimitForAllMap , Item ) == g_LimitAllMap ) { client_print ( Player , print_center , "This weapon will be available next map." ) return PLUGIN_HANDLED } if( ArrayGetCell ( LimitForAllRound , Item ) && ArrayGetCell ( LimitForAllRound , Item ) == g_LimitAllRound ) { client_print ( Player , print_center , "This item will be available next round." ) return PLUGIN_HANDLED } if( ArrayGetCell ( ItemLimitInMapP , Item ) && ArrayGetCell ( ItemLimitInMapP , Item ) > g_LimitInMap [ Item ][ Player ]) g_LimitInMap [ Player ][ Item ] ++ if( ArrayGetCell ( ItemLimitInRound , Item ) && ArrayGetCell ( ItemLimitInRound , Item ) > g_LimitInRound [ Item ][ Player ]) g_LimitInRound [ Player ][ Item ] ++ if( ArrayGetCell ( LimitForAllMap , Item ) && ArrayGetCell ( LimitForAllMap , Item ) > g_LimitAllMap ) g_LimitAllMap ++ if( ArrayGetCell ( LimitForAllRound , Item ) && ArrayGetCell ( LimitForAllRound , Item ) > g_LimitAllRound ) g_LimitAllRound ++ ExecuteForward ( g_Item , g_End , Player , Item ) zp_set_user_ammo_packs ( Player , zp_get_user_ammo_packs ( Player ) - Cost ) return PLUGIN_HANDLED }
And if I do it like this all items will get displayed in pistol menu
Last edited by YankoNL; 06-07-2021 at 03:22 .