2009-05-29 08:43:15 +02:00
/*
* ============================================================================
*
2009-07-05 08:49:23 +02:00
* Zombie : Reloaded
2009-05-29 08:43:15 +02:00
*
2009-06-12 05:51:26 +02:00
* File : zmarket . inc
* Type : Module
* Description : ZMarket module , provides menu of weapons to buy from .
2009-06-05 05:58:48 +02:00
*
2013-01-12 08:47:36 +01:00
* Copyright ( C ) 2009 - 2013 Greyscale , Richard Helgeby
2009-06-05 05:58:48 +02:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2009-05-29 08:43:15 +02:00
*
* ============================================================================
*/
2009-06-21 21:24:24 +02:00
/**
* @ section Name of the cookies for ZMarket rebuy / auto - rebuy data .
*/
#define ZMARKET_COOKIE_AUTOREBUY "zr_zmarket_autorebuy"
#define ZMARKET_COOKIE_REBUY "zr_zmarket_rebuy"
/**
* @ endsection
*/
2016-02-12 04:16:59 +01:00
/**
* Slots saved for auto - rebuy
*/
#define ZMARKET_REBUY_WEAPONS_SLOTS_MAX 1
2009-06-05 05:58:48 +02:00
/**
* Array to store the client ' s current weapon type within menu .
*/
new g_iZMarketCurType [ MAXPLAYERS + 1 ];
/**
* Array handle to store the amount of purchases left for a weapon .
*/
new Handle : g_hZMarketPurchaseCount [ MAXPLAYERS + 1 ];
2012-02-26 23:07:24 +01:00
/**
* Whether weapons has been bought automatically . Used to prevent double rebuy
* when cookies are loaded after the player was spawned .
*/
new bool : g_bZMarketWeaponsBought [ MAXPLAYERS + 1 ];
2009-10-08 19:47:23 +02:00
/**
* Cookie handle array for weapon loadouts .
*/
2016-02-12 04:16:59 +01:00
new Handle : g_hZMarketLoadoutCookie [ ZMARKET_REBUY_WEAPONS_SLOTS_MAX + 1 ];
new bool : g_bZMarketCommandInitialized = false ;
2009-10-08 19:47:23 +02:00
2009-05-29 08:43:15 +02:00
/**
2009-06-17 23:32:46 +02:00
* Create commands specific to ZMarket .
2009-05-29 08:43:15 +02:00
*/
2009-06-17 23:32:46 +02:00
ZMarketOnCommandsCreate ()
2009-05-29 08:43:15 +02:00
{
2009-06-17 23:32:46 +02:00
// Register ZMarket command.
RegConsoleCmd ( SAYHOOKS_KEYWORD_ZMARKET , ZMarketCommand , " Opens custom buymenu. " );
2016-02-12 04:16:59 +01:00
g_bZMarketCommandInitialized = false ;
2009-05-29 08:43:15 +02:00
}
2009-06-21 21:24:24 +02:00
ZMarketOnCookiesCreate ()
{
2009-07-07 07:09:54 +02:00
decl String : rebuycookiename [ 32 ];
decl String : rebuycookiedesc [ 64 ];
2016-02-06 00:47:47 +01:00
2009-07-07 07:09:54 +02:00
// x = Weapon slot.
2016-02-12 04:16:59 +01:00
for ( new x = 0 ; x < ZMARKET_REBUY_WEAPONS_SLOTS_MAX + 1 ; x ++ )
2009-06-21 21:24:24 +02:00
{
2009-07-07 07:09:54 +02:00
// Format cookie name and description.
Format ( rebuycookiename , sizeof ( rebuycookiename ), " %s_%d " , ZMARKET_COOKIE_REBUY , x );
Format ( rebuycookiedesc , sizeof ( rebuycookiedesc ), " Current loadout weapon for slot %d " , x );
2016-02-06 00:47:47 +01:00
2009-10-10 18:26:27 +02:00
// Create loadout cookie handle if it doesn't exist.
if ( g_hZMarketLoadoutCookie [ x ] == INVALID_HANDLE )
2009-10-08 19:47:23 +02:00
{
2009-10-10 18:26:27 +02:00
g_hZMarketLoadoutCookie [ x ] = RegClientCookie ( rebuycookiename , rebuycookiedesc , CookieAccess_Protected );
2009-10-08 19:47:23 +02:00
}
2009-06-21 21:24:24 +02:00
}
}
2016-02-12 04:16:59 +01:00
ZMarketLoad ()
{
// Do not register commands multiple times
if ( g_bZMarketCommandInitialized )
return ;
decl String : zmarketcommand [ CONFIG_MAX_LENGTH ];
decl String : weaponname [ WEAPONS_MAX_LENGTH ];
new size = GetArraySize ( arrayWeapons );
for ( new weaponindex = 0 ; weaponindex < size ; weaponindex ++ )
{
WeaponsGetZMarketCommand ( weaponindex , zmarketcommand , sizeof ( zmarketcommand ));
if ( zmarketcommand [ 0 ])
{
WeaponsGetName ( weaponindex , weaponname , sizeof ( weaponname ));
2018-02-10 20:40:22 +01:00
if ( FindCharInString ( zmarketcommand , ',' ) != - 1 )
{
int idx ;
int lastidx ;
while (( idx = FindCharInString ( zmarketcommand [ lastidx ], ',' )) != - 1 )
{
char out [ 16 ];
char fmt [ 8 ];
Format ( fmt , sizeof ( fmt ), " %%.%ds " , idx );
Format ( out , sizeof ( out ), fmt , zmarketcommand [ lastidx ]);
RegConsoleCmd ( out , ZMarketBuyCommand , weaponname );
lastidx += ++ idx ;
if ( FindCharInString ( zmarketcommand [ lastidx ], ',' ) == - 1 && zmarketcommand [ lastidx + 1 ] != '\0' )
RegConsoleCmd ( zmarketcommand [ lastidx ], ZMarketBuyCommand , weaponname );
}
}
else
{
RegConsoleCmd ( zmarketcommand , ZMarketBuyCommand , weaponname );
}
2016-02-12 04:16:59 +01:00
}
}
g_bZMarketCommandInitialized = true ;
}
public Action : ZMarketBuyCommand ( client , argc )
{
decl String : command [ CONFIG_MAX_LENGTH ];
decl String : zmarketcommand [ CONFIG_MAX_LENGTH ];
decl String : weaponname [ WEAPONS_MAX_LENGTH ];
GetCmdArg ( 0 , command , sizeof ( command ));
new size = GetArraySize ( arrayWeapons );
for ( new weaponindex = 0 ; weaponindex < size ; weaponindex ++ )
{
WeaponsGetZMarketCommand ( weaponindex , zmarketcommand , sizeof ( zmarketcommand ));
2018-02-10 20:40:22 +01:00
if ( FindCharInString ( zmarketcommand , ',' ) != - 1 )
2016-02-12 04:16:59 +01:00
{
2018-02-10 20:40:22 +01:00
int idx ;
int lastidx ;
while (( idx = FindCharInString ( zmarketcommand [ lastidx ], ',' )) != - 1 )
{
if ( ! strncmp ( command , zmarketcommand [ lastidx ], idx ))
{
WeaponsGetName ( weaponindex , weaponname , sizeof ( weaponname ));
ZMarketEquip ( client , weaponname );
return Plugin_Handled ;
}
lastidx += ++ idx ;
if ( FindCharInString ( zmarketcommand [ lastidx ], ',' ) == - 1 && zmarketcommand [ lastidx + 1 ] != '\0' )
{
if ( ! strncmp ( command , zmarketcommand [ lastidx ], idx ))
{
WeaponsGetName ( weaponindex , weaponname , sizeof ( weaponname ));
ZMarketEquip ( client , weaponname );
return Plugin_Handled ;
}
}
}
}
else
{
if ( StrEqual ( command , zmarketcommand ))
{
WeaponsGetName ( weaponindex , weaponname , sizeof ( weaponname ));
ZMarketEquip ( client , weaponname );
return Plugin_Handled ;
}
2016-02-12 04:16:59 +01:00
}
}
return Plugin_Handled ;
}
2009-06-05 05:58:48 +02:00
/**
* Client is joining the server .
2016-02-06 00:47:47 +01:00
*
* @ param client The client index .
2009-06-05 05:58:48 +02:00
*/
ZMarketClientInit ( client )
{
// If purchase count data exists, then destroy before creating again.
if ( g_hZMarketPurchaseCount [ client ] != INVALID_HANDLE )
{
CloseHandle ( g_hZMarketPurchaseCount [ client ]);
}
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Create a new array handle to store purchase count data for client.
g_hZMarketPurchaseCount [ client ] = CreateTrie ();
2016-02-06 00:47:47 +01:00
2012-02-26 23:07:24 +01:00
// No weapons bought automatically.
g_bZMarketWeaponsBought [ client ] = false ;
2010-02-20 02:41:24 +01:00
}
/**
* Called once a client ' s saved cookies have been loaded from the database .
2016-02-06 00:47:47 +01:00
*
2016-02-12 04:16:59 +01:00
* @ param client Client index .
2010-02-20 02:41:24 +01:00
*/
ZMarketOnCookiesCached ( client )
{
2012-02-26 23:07:24 +01:00
// Rebuy wapons (if auto-rebuy is enabled, and not bought already).
if ( ! g_bZMarketWeaponsBought [ client ])
{
ZMarketCheckRebuy ( client );
2009-06-21 21:24:24 +02:00
}
2009-06-05 05:58:48 +02:00
}
/**
* Client is leaving the server .
2016-02-06 00:47:47 +01:00
*
2009-06-05 05:58:48 +02:00
* @ param client The client index .
*/
ZMarketOnClientDisconnect ( client )
{
// Destroy ZMarket array data for client.
2009-06-16 05:57:40 +02:00
if ( g_hZMarketPurchaseCount [ client ] != INVALID_HANDLE )
{
CloseHandle ( g_hZMarketPurchaseCount [ client ]);
}
2016-02-06 00:47:47 +01:00
2009-06-16 05:57:40 +02:00
// Reset handle.
2009-06-05 05:58:48 +02:00
g_hZMarketPurchaseCount [ client ] = INVALID_HANDLE ;
}
/**
* Client is spawning into the game .
2016-02-06 00:47:47 +01:00
*
2009-06-05 05:58:48 +02:00
* @ param client The client index .
*/
2009-06-21 21:24:24 +02:00
ZMarketOnClientSpawnPost ( client )
2009-06-05 05:58:48 +02:00
{
// Reset purchase counts for client.
ZMarketResetPurchaseCount ( client );
2016-02-06 00:47:47 +01:00
2012-02-26 23:07:24 +01:00
// Rebuy if auto-rebuy is enabled.
ZMarketCheckRebuy ( client );
}
/**
* Rebuys weapons if auto - rebuy is enabled and player is a human ( alive ) .
*
* @ param client The client index .
*/
ZMarketCheckRebuy ( client )
{
2009-06-21 21:24:24 +02:00
// If client hasn't spawned into the game yet, then stop.
2012-02-27 01:49:04 +01:00
if ( ! IsClientConnected ( client ) || ! IsClientInGame ( client ) || ! IsPlayerAlive ( client ))
2009-06-21 21:24:24 +02:00
{
return ;
}
2016-02-06 00:47:47 +01:00
2009-06-26 02:10:45 +02:00
// If client is a zombie, then stop.
if ( InfectIsClientInfected ( client ))
{
return ;
}
2016-02-06 00:47:47 +01:00
2016-02-12 04:16:59 +01:00
// Give default/prefered spawn weapons
ZMarketRebuy ( client , true );
g_bZMarketWeaponsBought [ client ] = true ;
2009-06-05 05:58:48 +02:00
}
/**
* Reset the purchase count ( s ) for a client .
2016-02-06 00:47:47 +01:00
*
2009-06-05 05:58:48 +02:00
* @ param client The client index .
*/
ZMarketResetPurchaseCount ( client )
{
// Clear out the trie of all data.
2010-08-06 15:42:22 +02:00
if ( g_hZMarketPurchaseCount [ client ] != INVALID_HANDLE )
{
ClearTrie ( g_hZMarketPurchaseCount [ client ]);
}
2009-06-05 05:58:48 +02:00
}
/**
* Set the purchases left for a client of a weapon .
2016-02-06 00:47:47 +01:00
*
2009-06-05 05:58:48 +02:00
* @ param client The client index .
* @ param weapon The weapon name .
* @ param value The amount of purchases left for the weapon .
*/
ZMarketSetPurchaseCount ( client , const String : weapon [], value , bool : add = false )
{
// Initialize variable (value is 0)
new purchasemax ;
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// If we are adding, then update variable with current ammo value.
if ( add )
{
purchasemax = ZMarketGetPurchaseCount ( client , weapon );
}
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Set value in client's trie.
SetTrieValue ( g_hZMarketPurchaseCount [ client ], weapon , purchasemax + value );
}
/**
* Get the purchases left for a client of a weapon .
2016-02-06 00:47:47 +01:00
*
2009-06-05 05:58:48 +02:00
* @ param client The client index .
* @ param weapon The weapon name .
* @ param return The amount of purchases left for the weapon .
*/
ZMarketGetPurchaseCount ( client , const String : weapon [])
{
// Get value in client's trie.
new value ;
GetTrieValue ( g_hZMarketPurchaseCount [ client ], weapon , value );
return value ;
}
/**
2009-06-19 05:41:54 +02:00
* Sends main ZMarket menu to client .
2016-02-06 00:47:47 +01:00
*
2009-06-05 05:58:48 +02:00
* @ param client The client index .
* @ return True if the menu was sent successfully , false if not .
*/
2009-06-19 05:41:54 +02:00
bool : ZMarketMenuMain ( client )
2009-06-05 05:58:48 +02:00
{
2009-06-08 06:05:50 +02:00
// If weapons module is disabled, then stop.
new bool : weapons = GetConVarBool ( g_hCvarsList [ CVAR_WEAPONS ]);
if ( ! weapons )
{
// Telle client feature is disabled.
TranslationPrintToChat ( client , " Feature is disabled " );
return false ;
}
2016-02-06 00:47:47 +01:00
2009-06-08 06:05:50 +02:00
// If ZMarket module is disabled, then stop.
2009-06-05 05:58:48 +02:00
new bool : zmarket = GetConVarBool ( g_hCvarsList [ CVAR_WEAPONS_ZMARKET ]);
if ( ! zmarket )
{
// Telle client feature is disabled.
TranslationPrintToChat ( client , " Feature is disabled " );
return false ;
}
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Create menu handle.
2009-06-19 05:41:54 +02:00
new Handle : menu_zmarket_main = CreateMenu ( ZMarketMenuMainHandle );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Set translation target as client.
SetGlobalTransTarget ( client );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// If rebuy is enabled, then add it to the menu.
new bool : zmarketrebuy = GetConVarBool ( g_hCvarsList [ CVAR_WEAPONS_ZMARKET_REBUY ]);
new bool : zmarketrebuyauto = GetConVarBool ( g_hCvarsList [ CVAR_WEAPONS_ZMARKET_REBUY_AUTO ]);
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
// Add "Get Current Loadout" option.
2009-07-28 02:02:49 +02:00
decl String : title [ MENU_LINE_TITLE_LENGTH ];
2009-07-27 22:25:23 +02:00
decl String : getloadout [ MENU_LINE_REG_LENGTH ];
2016-02-12 04:16:59 +01:00
decl String : editloadout [ MENU_LINE_REG_LENGTH ];
2009-07-27 22:25:23 +02:00
decl String : rebuy [ MENU_LINE_REG_LENGTH ];
decl String : weaponslist [ MENU_LINE_REG_LENGTH ];
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
// Format menu options.
2009-07-28 02:02:49 +02:00
Format ( title , sizeof ( title ), " %t \n " , " Weapons menu zmarket main title " );
2009-06-19 05:41:54 +02:00
Format ( getloadout , sizeof ( getloadout ), " %t " , " Weapons menu zmarket main get loadout " );
2016-02-12 04:16:59 +01:00
Format ( editloadout , sizeof ( editloadout ), " %t " , " Weapons menu zmarket main edit loadout " );
2009-06-19 05:41:54 +02:00
Format ( rebuy , sizeof ( rebuy ), " %t " , " Weapons menu zmarket main rebuy " );
Format ( weaponslist , sizeof ( weaponslist ), " %t " , " Weapons menu zmarket main weapons list " );
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
// Add formatted options to menu.
2009-07-28 02:02:49 +02:00
SetMenuTitle ( menu_zmarket_main , title );
2009-06-19 05:41:54 +02:00
AddMenuItem ( menu_zmarket_main , " Get Loadout " , getloadout , MenuGetItemDraw ( zmarketrebuy || zmarketrebuyauto ));
2016-02-12 04:16:59 +01:00
AddMenuItem ( menu_zmarket_main , " Edit Loadout " , editloadout , MenuGetItemDraw ( zmarketrebuy || zmarketrebuyauto ));
2009-06-19 05:41:54 +02:00
AddMenuItem ( menu_zmarket_main , " Rebuy " , rebuy , MenuGetItemDraw ( zmarketrebuy || zmarketrebuyauto ));
AddMenuItem ( menu_zmarket_main , " Weapons List " , weaponslist );
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
// Set exit back button.
SetMenuExitBackButton ( menu_zmarket_main , true );
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
DisplayMenu ( menu_zmarket_main , client , MENU_TIME_FOREVER );
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
// Menu sent successfully.
return true ;
}
/**
* Called when client selects option in the main ZMarket menu , and handles it .
2016-02-06 00:47:47 +01:00
*
2009-06-19 05:41:54 +02:00
* @ param menu_zmarket_main Handle of the menu being used .
* @ param action The action done on the menu ( see menus . inc , enum MenuAction ) .
* @ param client The client index .
* @ param slot The slot index selected ( starting from 0 ) .
2016-02-06 00:47:47 +01:00
*/
2009-06-19 05:41:54 +02:00
public ZMarketMenuMainHandle ( Handle : menu_zmarket_main , MenuAction : action , client , slot )
{
// Client selected an option.
if ( action == MenuAction_Select )
{
switch ( slot )
{
// Get loadout.
case 0 :
{
// Gets a client's current loadout.
ZMarketGetCurrentLoadout ( client );
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
// Resend menu.
ZMarketMenuMain ( client );
}
2016-02-12 04:16:59 +01:00
// Edit loadout.
2009-06-19 05:41:54 +02:00
case 1 :
{
2016-02-12 04:16:59 +01:00
// Send the weapon loadout edit menu.
2009-06-19 05:41:54 +02:00
ZMarketMenuLoadout ( client );
}
// Rebuy.
case 2 :
{
// Force client to rebuy weapons.
ZMarketRebuy ( client );
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
// Resend menu.
ZMarketMenuMain ( client );
}
// Weapons list.
2016-02-12 04:16:59 +01:00
case 3 :
2009-06-19 05:41:54 +02:00
{
// Send the weapon types list.
ZMarketMenuTypes ( client );
}
}
}
// Client closed the menu.
if ( action == MenuAction_Cancel )
{
// Client hit "Back" button.
if ( slot == MenuCancel_ExitBack )
{
2009-06-22 06:08:26 +02:00
ZMenuMain ( client );
2009-06-19 05:41:54 +02:00
}
}
// Client hit "Exit" button.
else if ( action == MenuAction_End )
2009-06-05 05:58:48 +02:00
{
2009-06-19 05:41:54 +02:00
CloseHandle ( menu_zmarket_main );
2009-06-05 05:58:48 +02:00
}
2009-06-19 05:41:54 +02:00
}
/**
* Sends list of weapons in a client ' s loadout to the client .
2016-02-06 00:47:47 +01:00
*
2009-06-19 05:41:54 +02:00
* @ param client The client index .
*/
bool : ZMarketMenuLoadout ( client )
{
// Create menu handle.
new Handle : menu_zmarket_loadout = CreateMenu ( ZMarketMenuLoadoutHandle );
2016-02-06 00:47:47 +01:00
2009-06-21 21:24:24 +02:00
// Transfer cookie values into an array.
2016-02-12 04:16:59 +01:00
new String : rebuyweapons [ ZMARKET_REBUY_WEAPONS_SLOTS_MAX + 1 ][ WEAPONS_MAX_LENGTH ];
ZMarketCookiesToArray ( client , rebuyweapons , sizeof ( rebuyweapons ), sizeof ( rebuyweapons []));
2016-02-06 00:47:47 +01:00
2009-07-28 02:02:49 +02:00
SetGlobalTransTarget ( client );
2016-02-06 00:47:47 +01:00
2009-08-25 22:07:10 +02:00
// x = Rebuy weapon slot.
for ( new x = 0 ; x < sizeof ( rebuyweapons ); x ++ )
2009-06-19 05:41:54 +02:00
{
2016-02-12 04:16:59 +01:00
// If the client doesn't have a weapon in this slot, then set the weapon to the default translation.
2009-08-25 22:07:10 +02:00
if ( ! rebuyweapons [ x ][ 0 ])
{
2016-02-12 04:16:59 +01:00
// Get default weapon for this slot
decl String : weaponname [ WEAPONS_MAX_LENGTH ];
switch ( x )
{
case Slot_Primary :
{
GetConVarString ( g_hCvarsList [ CVAR_WEAPONS_ZMARKET_REBUY_PRIMARY ], weaponname , sizeof ( weaponname ));
}
case Slot_Secondary :
{
GetConVarString ( g_hCvarsList [ CVAR_WEAPONS_ZMARKET_REBUY_SECONDARY ], weaponname , sizeof ( weaponname ));
}
}
Format ( rebuyweapons [ x ], sizeof ( rebuyweapons []), " %t " , " Weapons menu zmarket loadout default " , weaponname );
2009-08-25 22:07:10 +02:00
}
2009-06-05 05:58:48 +02:00
}
2016-02-06 00:47:47 +01:00
2009-08-23 17:03:14 +02:00
decl String : title [ MENU_LINE_HUGE_LENGTH ];
2009-07-27 22:25:23 +02:00
decl String : primary [ MENU_LINE_REG_LENGTH ];
decl String : secondary [ MENU_LINE_REG_LENGTH ];
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
// Format all the lines of the menu.
2009-07-28 02:02:49 +02:00
Format ( title , sizeof ( title ), " %t \n " , " Weapons menu zmarket loadout title " );
2009-08-25 22:07:10 +02:00
Format ( primary , sizeof ( primary ), " %t " , " Weapons menu zmarket loadout primary " , rebuyweapons [ Slot_Primary ]);
Format ( secondary , sizeof ( secondary ), " %t " , " Weapons menu zmarket loadout secondary " , rebuyweapons [ Slot_Secondary ]);
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
// Add formatted options to menu.
2009-07-28 02:02:49 +02:00
SetMenuTitle ( menu_zmarket_loadout , title );
2016-02-12 04:16:59 +01:00
AddMenuItem ( menu_zmarket_loadout , " 0 " , primary );
AddMenuItem ( menu_zmarket_loadout , " 1 " , secondary );
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
// Set exit back button.
SetMenuExitBackButton ( menu_zmarket_loadout , true );
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
// Send menu to client.
DisplayMenu ( menu_zmarket_loadout , client , MENU_TIME_FOREVER );
}
/**
* Allow the user to press the " Back " button to go to main ZMarket menu .
2016-02-06 00:47:47 +01:00
*
2009-06-19 05:41:54 +02:00
* @ param menu_zmarket_loadout Handle of the menu being used .
* @ param action The action done on the menu ( see menus . inc , enum MenuAction ) .
* @ param client The client index .
* @ param slot The slot index selected ( starting from 0 ) .
2016-02-06 00:47:47 +01:00
*/
2009-06-19 05:41:54 +02:00
public ZMarketMenuLoadoutHandle ( Handle : menu_zmarket_loadout , MenuAction : action , client , slot )
{
2009-07-07 06:32:34 +02:00
// Client selected an option.
if ( action == MenuAction_Select )
{
2016-02-12 04:16:59 +01:00
// Open correct submenu for weapon type
switch ( slot )
{
case 0 :
{
g_iZMarketCurType [ client ] = _ : Slot_Primary ;
ZMarketMenuLoadoutWeapons ( client , Slot_Primary );
}
case 1 :
{
g_iZMarketCurType [ client ] = _ : Slot_Secondary ;
ZMarketMenuLoadoutWeapons ( client , Slot_Secondary );
}
}
2009-07-07 06:32:34 +02:00
}
2009-06-19 05:41:54 +02:00
// Client closed the menu.
if ( action == MenuAction_Cancel )
{
// Client hit "Back" button.
if ( slot == MenuCancel_ExitBack )
{
ZMarketMenuMain ( client );
}
}
// Client hit "Exit" button.
else if ( action == MenuAction_End )
{
CloseHandle ( menu_zmarket_loadout );
}
}
2016-02-12 04:16:59 +01:00
ZMarketMenuLoadoutWeapons ( client , WeaponsSlot : slot )
{
// Create menu handle.
new Handle : menu_zmarket_loadout_weapons = CreateMenu ( ZMarketMenuLoadoutWeaponsHandle );
// Set translation target as client.
SetGlobalTransTarget ( client );
decl String : title [ MENU_LINE_TITLE_LENGTH ];
Format ( title , sizeof ( title ), " %t \n " , " Weapons menu zmarket loadout weapons title " );
SetMenuTitle ( menu_zmarket_loadout_weapons , title );
decl String : weaponname [ WEAPONS_MAX_LENGTH ];
decl String : weapondisplay [ MENU_LINE_REG_LENGTH ];
// Get default weapon for this slot
switch ( slot )
{
case Slot_Primary :
{
GetConVarString ( g_hCvarsList [ CVAR_WEAPONS_ZMARKET_REBUY_PRIMARY ], weaponname , sizeof ( weaponname ));
}
case Slot_Secondary :
{
GetConVarString ( g_hCvarsList [ CVAR_WEAPONS_ZMARKET_REBUY_SECONDARY ], weaponname , sizeof ( weaponname ));
}
}
// First item = Server default weapon
Format ( weapondisplay , sizeof ( weapondisplay ), " %t " , " Weapons menu zmarket loadout default " , weaponname );
AddMenuItem ( menu_zmarket_loadout_weapons , " " , weapondisplay );
new size = GetArraySize ( arrayWeapons );
for ( new weaponindex = 0 ; weaponindex < size ; weaponindex ++ )
{
// Get weapons slot
new WeaponsSlot : wslot = WeaponsGetSlot ( weaponindex );
// Does it match with the slot we want?
if ( wslot != slot )
continue ;
2019-03-09 13:54:06 +01:00
WeaponsGetName ( weaponindex , weaponname , sizeof ( weaponname ), ( g_Game == Game_CSGO ));
2016-02-12 04:16:59 +01:00
// Get restricted status on the weapon.
new bool : restricted = RestrictIsWeaponRestricted ( weaponindex );
// If weapon is restricted then format "[]" around it.
strcopy ( weapondisplay , sizeof ( weapondisplay ), weaponname );
if ( restricted )
{
Format ( weapondisplay , sizeof ( weapondisplay ), " [%s] " , weaponname );
}
// Disable weapon if it's restricted.
AddMenuItem ( menu_zmarket_loadout_weapons , weaponname , weapondisplay , MenuGetItemDraw ( ! restricted ));
}
// Set exit back button.
SetMenuExitBackButton ( menu_zmarket_loadout_weapons , true );
DisplayMenu ( menu_zmarket_loadout_weapons , client , MENU_TIME_FOREVER );
}
/**
* Called when client selects a weapon in the loadout weapons menu , and handles it .
*
* @ param menu_zmarket_loadout_weapons Handle of the menu being used .
* @ param action The action done on the menu ( see menus . inc , enum MenuAction ) .
* @ param client The client index .
* @ param slot The slot index selected ( starting from 0 ) .
*/
public ZMarketMenuLoadoutWeaponsHandle ( Handle : menu_zmarket_loadout_weapons , MenuAction : action , client , slot )
{
// Client selected an option.
if ( action == MenuAction_Select )
{
// Get name of selected weapon.
decl String : weapon [ WEAPONS_MAX_LENGTH ];
GetMenuItem ( menu_zmarket_loadout_weapons , slot , weapon , sizeof ( weapon ));
// Update cookie with new weapon.
ZMarketSetRebuyCookie ( client , WeaponsSlot : g_iZMarketCurType [ client ], weapon );
// Open loadout menu.
ZMarketMenuLoadout ( client );
}
// Client closed the menu.
if ( action == MenuAction_Cancel )
{
// Client hit "Back" button.
if ( slot == MenuCancel_ExitBack )
{
ZMarketMenuLoadout ( client );
}
}
// Client hit "Exit" button.
else if ( action == MenuAction_End )
{
CloseHandle ( menu_zmarket_loadout_weapons );
}
}
2009-06-19 05:41:54 +02:00
/**
* Sends weapon type list to client .
2016-02-06 00:47:47 +01:00
*
2009-06-19 05:41:54 +02:00
* @ param client The client index .
*/
ZMarketMenuTypes ( client )
{
// Create menu handle.
new Handle : menu_zmarket_types = CreateMenu ( ZMarketMenuTypesHandle );
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
// Set translation target as client.
2009-08-23 17:03:14 +02:00
SetGlobalTransTarget ( client );
2016-02-06 00:47:47 +01:00
2009-07-28 02:02:49 +02:00
decl String : title [ MENU_LINE_TITLE_LENGTH ];
Format ( title , sizeof ( title ), " %t \n " , " Weapons menu zmarket types title " );
SetMenuTitle ( menu_zmarket_types , title );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
decl String : typename [ WEAPONS_MAX_LENGTH ];
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// x = Array index.
new size = GetArraySize ( arrayWeaponTypes );
for ( new x = 0 ; x < size ; x ++ )
{
// Get name of type.
RestrictWeaponTypeGetName ( x , typename , sizeof ( typename ));
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Add item to menu.
AddMenuItem ( menu_zmarket_types , typename , typename );
}
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// If there are no weapons, add an "(Empty)" line.
if ( size == 0 )
{
2009-07-28 02:02:49 +02:00
SetGlobalTransTarget ( client );
2016-02-06 00:47:47 +01:00
2009-07-27 22:25:23 +02:00
decl String : empty [ MENU_LINE_SMALL_LENGTH ];
2009-06-05 05:58:48 +02:00
Format ( empty , sizeof ( empty ), " %t " , " Menu empty " );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
AddMenuItem ( menu_zmarket_types , " empty " , empty , ITEMDRAW_DISABLED );
}
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Set exit back button.
SetMenuExitBackButton ( menu_zmarket_types , true );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
DisplayMenu ( menu_zmarket_types , client , MENU_TIME_FOREVER );
}
/**
* Called when client selects option in the weapons list menu , and handles it .
2016-02-06 00:47:47 +01:00
*
2009-06-05 05:58:48 +02:00
* @ param menu_zmarket_types Handle of the menu being used .
* @ param action The action done on the menu ( see menus . inc , enum MenuAction ) .
* @ param client The client index .
* @ param slot The slot index selected ( starting from 0 ) .
2016-02-06 00:47:47 +01:00
*/
2009-06-05 05:58:48 +02:00
public ZMarketMenuTypesHandle ( Handle : menu_zmarket_types , MenuAction : action , client , slot )
{
// Client selected an option.
if ( action == MenuAction_Select )
{
decl String : weapontype [ WEAPONS_MAX_LENGTH ];
GetMenuItem ( menu_zmarket_types , slot , weapontype , sizeof ( weapontype ));
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Get weapon index.
new weapontypeindex = RestrictTypeToIndex ( weapontype );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// If weapon type index is -1, then something went very wrong.
if ( weapontypeindex == - 1 )
{
// Resend menu.
ZMarketMenuTypes ( client );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
return ;
}
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Menu slot index is = weapon type index.
g_iZMarketCurType [ client ] = weapontypeindex ;
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Send weapons of the selected type in a menu to client.
ZMarketMenuTypeWeapons ( client );
}
// Client closed the menu.
if ( action == MenuAction_Cancel )
{
// Client hit "Back" button.
if ( slot == MenuCancel_ExitBack )
{
2009-06-19 05:41:54 +02:00
ZMarketMenuMain ( client );
2009-06-05 05:58:48 +02:00
}
}
// Client hit "Exit" button.
else if ( action == MenuAction_End )
{
CloseHandle ( menu_zmarket_types );
}
}
/**
* Sends a list of weapons of a certain type in a menu to the client .
2016-02-06 00:47:47 +01:00
*
2009-06-05 05:58:48 +02:00
* @ param client The client index .
*/
ZMarketMenuTypeWeapons ( client )
{
// Create menu handle.
new Handle : menu_zmarket_typeweapons = CreateMenu ( ZMarketMenuTypeWeaponsHandle );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Get name of current weapon type.
decl String : typename [ WEAPONS_MAX_LENGTH ];
RestrictWeaponTypeGetName ( g_iZMarketCurType [ client ], typename , sizeof ( typename ));
2016-02-06 00:47:47 +01:00
2009-07-28 02:02:49 +02:00
decl String : title [ MENU_LINE_TITLE_LENGTH ];
2009-06-05 05:58:48 +02:00
decl String : typeweapon [ WEAPONS_MAX_LENGTH ];
2009-07-27 22:25:23 +02:00
decl String : typeweapondisplay [ MENU_LINE_REG_LENGTH ];
2009-08-25 22:07:10 +02:00
decl String : typeweaponentity [ WEAPONS_MAX_LENGTH ];
2009-07-27 22:25:23 +02:00
decl String : display [ MENU_LINE_BIG_LENGTH ];
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Get an array populated with all weapons of the given type.
new Handle : arrayTypeWeapons ;
new count = RestrictGetTypeWeapons ( g_iZMarketCurType [ client ], arrayTypeWeapons );
2016-02-06 00:47:47 +01:00
2009-07-28 02:02:49 +02:00
SetGlobalTransTarget ( client );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// x = Array index.
for ( new x = 0 ; x < count ; x ++ )
{
// Get weapon index to check restricted status of.
new weaponindex = GetArrayCell ( arrayTypeWeapons , x );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Get name of weapon.
2019-03-09 13:54:06 +01:00
WeaponsGetName ( weaponindex , typeweapon , sizeof ( typeweapon ), ( g_Game == Game_CSGO ));
2016-02-06 00:47:47 +01:00
2009-08-25 22:07:10 +02:00
// Get entity name of weapon.
WeaponsGetEntity ( weaponindex , typeweaponentity , sizeof ( typeweaponentity ));
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Check if client is buying the weapon or ammo for it, and get the price of the item.
2009-08-25 22:07:10 +02:00
new bool : hasweapon = WeaponsClientHasWeapon ( client , typeweaponentity );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// DO ITEM PRICE STUFF HERE.
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
new itemprice ;
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Do appropriate formatting for the type of item client is buying.
new WeaponsSlot : slot = WeaponsGetSlot ( weaponindex );
2009-07-27 22:35:00 +02:00
if ( ! hasweapon || slot == Slot_Projectile )
2009-06-05 05:58:48 +02:00
{
// Get the weapon price.
itemprice = WeaponsGetZMarketPrice ( weaponindex );
}
else
{
// Get the weapon's ammo price.
itemprice = WeaponsGetAmmoPrice ( weaponindex );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Tell client they are buying ammo.
2019-03-09 13:44:42 +01:00
Format ( typeweapondisplay , sizeof ( typeweapondisplay ), " %s %t " , typeweapon , " Weapons menu zmarket types weapon ammo " );
2009-06-05 05:58:48 +02:00
}
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// If the itemprice is invalid, then set to known integer to be later replaced.
if ( itemprice < 0 )
{
itemprice = - 1 ;
}
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// DO RESTRICTED WEAPON STUFF HERE.
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Get restricted status on the weapon.
new bool : restricted = RestrictIsWeaponRestricted ( weaponindex );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// If weapon is restricted then format "[]" around it.
2019-03-09 13:44:42 +01:00
strcopy ( typeweapondisplay , sizeof ( typeweapondisplay ), typeweapon );
2009-06-05 05:58:48 +02:00
if ( restricted )
{
2019-03-09 13:44:42 +01:00
Format ( typeweapondisplay , sizeof ( typeweapondisplay ), " [%s] " , typeweapon );
2009-06-05 05:58:48 +02:00
}
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// DO PURCHASE MAX STUFF HERE.
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Get the purchase count information for this weapon.
new purchasemax = WeaponsGetZMarketPurchaseMax ( weaponindex );
new purchasecount = ZMarketGetPurchaseCount ( client , typeweapon );
new purchasesleft = purchasemax - purchasecount ;
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// If the purchases left for the weapon goes below 0, fix it.
if ( purchasesleft < 0 )
{
purchasesleft = 0 ;
}
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// If max purchases is disabled for the weapon, then set as known integer to be later replaced.
2018-01-15 00:37:00 +01:00
if ( purchasemax < 0 )
2009-06-05 05:58:48 +02:00
{
purchasesleft = - 1 ;
}
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Format all the information together.
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Format price onto the menu entry.
Format ( display , sizeof ( display ), " %t " , " Weapons menu zmarket types weapon info " , typeweapondisplay , itemprice , purchasesleft );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Remove the known invalid number from the string, and replace with N/A, and remove currency symbol.
ReplaceString ( display , sizeof ( display ), " $ -1 " , " N/A " );
ReplaceString ( display , sizeof ( display ), " -1 " , " N/A " );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Disable option if it isn't toggleable.
new bool : itemdraw = (( itemprice > - 1 ) && ! restricted && ( purchasemax <= 0 || purchasesleft > 0 ));
AddMenuItem ( menu_zmarket_typeweapons , typeweapon , display , MenuGetItemDraw ( itemdraw ));
}
2016-02-06 00:47:47 +01:00
2009-07-28 02:02:49 +02:00
Format ( title , sizeof ( title ), " %t \n " , " Weapons menu zmarket types weapon type title " , typename );
SetMenuTitle ( menu_zmarket_typeweapons , title );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Destroy the array handle.
CloseHandle ( arrayTypeWeapons );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Set menu back button.
SetMenuExitBackButton ( menu_zmarket_typeweapons , true );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Display menu to client.
DisplayMenu ( menu_zmarket_typeweapons , client , MENU_TIME_FOREVER );
}
/**
* Called when client selects option in the weapon group menu , and handles it .
2016-02-06 00:47:47 +01:00
*
2009-06-05 05:58:48 +02:00
* @ param menu_zmarket_typeweapons Handle of the menu being used .
* @ param action The action done on the menu ( see menus . inc , enum MenuAction ) .
* @ param client The client index .
* @ param slot The slot index selected ( starting from 0 ) .
2016-02-06 00:47:47 +01:00
*/
2009-06-05 05:58:48 +02:00
public ZMarketMenuTypeWeaponsHandle ( Handle : menu_zmarket_typeweapons , MenuAction : action , client , slot )
{
// Client selected an option.
if ( action == MenuAction_Select )
{
// Get name of current weapon type.
decl String : typename [ WEAPONS_MAX_LENGTH ];
RestrictWeaponTypeGetName ( g_iZMarketCurType [ client ], typename , sizeof ( typename ));
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
decl String : typeweapon [ WEAPONS_MAX_LENGTH ];
GetMenuItem ( menu_zmarket_typeweapons , slot , typeweapon , sizeof ( typeweapon ));
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Equip weapon on client.
ZMarketEquip ( client , typeweapon );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Open types menu.
ZMarketMenuTypes ( client );
}
// Client closed the menu.
if ( action == MenuAction_Cancel )
{
// Client hit "Back" button.
if ( slot == MenuCancel_ExitBack )
{
ZMarketMenuTypes ( client );
}
}
// Client hit "Exit" button.
else if ( action == MenuAction_End )
{
CloseHandle ( menu_zmarket_typeweapons );
}
}
/**
* Equip a weapon on a client .
2016-02-06 00:47:47 +01:00
*
2009-06-05 05:58:48 +02:00
* @ param client The client index .
2009-06-21 21:24:24 +02:00
* @ param weapon The weapon to equip . ( must be in weapons config file )
2016-02-12 04:16:59 +01:00
* @ param rebuy ( Optional ) If client is rebuying , ammo and cash will be ignored .
2009-06-05 05:58:48 +02:00
*/
stock bool : ZMarketEquip ( client , const String : weapon [], bool : rebuy = false )
{
2016-02-12 04:16:59 +01:00
// if zombie hasn't spawned yet we're always rebuying:
2021-05-24 11:55:34 +02:00
new bool : zmarketfreespawn = GetConVarBool ( g_hCvarsList [ CVAR_WEAPONS_ZMARKET_FREESPAWN ]);
if ( zmarketfreespawn && ! InfectHasZombieSpawned ())
2016-02-12 04:16:59 +01:00
rebuy = true ;
2009-06-21 21:43:28 +02:00
// Get weapon index.
new weaponindex = WeaponsNameToIndex ( weapon );
2016-02-06 00:47:47 +01:00
2009-06-21 21:43:28 +02:00
// If weapon index is -1, then something went very wrong.
if ( weaponindex == - 1 )
2009-06-05 05:58:48 +02:00
{
2009-06-21 21:43:28 +02:00
LogEvent ( false , LogType_Error , LOG_CORE_EVENTS , LogModule_Weapons , " ZMarket Equip " , " Invalid weapon (%s) selected from the ZMarket menu. " , weapon );
2009-06-05 05:58:48 +02:00
return false ;
}
2016-02-06 00:47:47 +01:00
2009-06-21 22:56:48 +02:00
// Get slot index of the weapon being purchased.
new WeaponsSlot : slot = WeaponsGetSlot ( weaponindex );
2016-02-06 00:47:47 +01:00
2016-02-12 04:16:59 +01:00
// If client is dead, then stop.
if ( ! IsPlayerAlive ( client ))
2009-06-05 05:58:48 +02:00
{
2016-02-12 04:16:59 +01:00
TranslationPrintToChat ( client , " Must be alive " );
return false ;
}
2016-02-06 00:47:47 +01:00
2016-02-12 04:16:59 +01:00
// If client is a zombie, then stop.
if ( InfectIsClientInfected ( client ))
{
TranslationPrintToChat ( client , " Must be human " );
2009-06-05 05:58:48 +02:00
return false ;
}
2016-02-06 00:47:47 +01:00
2009-06-21 21:43:28 +02:00
new bool : zmarketbuyzone = GetConVarBool ( g_hCvarsList [ CVAR_WEAPONS_ZMARKET_BUYZONE ]);
2010-02-14 17:03:19 +01:00
if ( ! rebuy && zmarketbuyzone && ! WeaponsIsClientInBuyZone ( client ))
2009-06-05 05:58:48 +02:00
{
2016-02-12 04:16:59 +01:00
TranslationPrintToChat ( client , " Must be in buyzone " );
2009-06-05 05:58:48 +02:00
return false ;
}
2016-02-06 00:47:47 +01:00
2009-08-25 22:07:10 +02:00
// Get entity name of the weapon.
decl String : weaponentity [ WEAPONS_MAX_LENGTH ];
WeaponsGetEntity ( weaponindex , weaponentity , sizeof ( weaponentity ));
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Get the appropriate price of the item being purchased.
2009-08-25 22:07:10 +02:00
new bool : hasweapon = WeaponsClientHasWeapon ( client , weaponentity );
2009-07-27 22:35:00 +02:00
new itemprice = ( hasweapon && slot != Slot_Projectile ) ? WeaponsGetAmmoPrice ( weaponindex ) : WeaponsGetZMarketPrice ( weaponindex );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// If the weapon price is below 0, then something went wrong.
if ( itemprice < 0 )
{
return false ;
}
2016-02-06 00:47:47 +01:00
2009-07-07 06:32:34 +02:00
// Get the display name for the weapon.
decl String : weapondisplay [ WEAPONS_MAX_LENGTH ];
2019-03-10 19:59:04 +01:00
WeaponsGetName ( weaponindex , weapondisplay , sizeof ( weapondisplay ), ( g_Game == Game_CSGO ));
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Check to make sure the weapon isn't restricted.
new bool : restricted = RestrictIsWeaponRestricted ( weaponindex );
if ( restricted )
{
2009-07-07 06:32:34 +02:00
TranslationPrintToChat ( client , " Weapon is restricted " , weapondisplay );
2009-06-05 05:58:48 +02:00
return false ;
}
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Get the purchase count information for this weapon.
new purchasemax = WeaponsGetZMarketPurchaseMax ( weaponindex );
new purchasecount = ZMarketGetPurchaseCount ( client , weapon );
new purchasesleft = purchasemax - purchasecount ;
2018-01-15 00:37:00 +01:00
if ( ! rebuy && purchasemax >= 0 && purchasesleft <= 0 )
2009-06-05 05:58:48 +02:00
{
2009-07-07 06:32:34 +02:00
TranslationPrintToChat ( client , " Weapons zmarket purchase max " , weapondisplay , purchasemax );
2009-06-05 05:58:48 +02:00
return false ;
}
2016-02-06 00:47:47 +01:00
2009-08-25 22:07:10 +02:00
// If the slot is a projectile, then get information we need to compare later.
if ( slot == Slot_Projectile )
{
2009-08-26 09:07:01 +02:00
// Get the grenade type the client is trying to buy.
new WeaponAmmoGrenadeType : grenadetype = WeaponAmmoEntityToGrenadeType ( weaponentity );
2016-02-06 00:47:47 +01:00
2009-08-26 09:07:01 +02:00
if ( grenadetype == GrenadeType_Invalid )
{
2009-10-27 22:53:03 +01:00
LogEvent ( false , LogType_Error , LOG_GAME_EVENTS , LogModule_Weapons , " Grenades " , " Client \" %L \" attempted to buy weapon entity \" %s \" marked as a projectile. Check your weapon config. " , client , weaponentity );
2009-08-26 09:07:01 +02:00
return false ;
}
2016-02-06 00:47:47 +01:00
2009-08-25 22:07:10 +02:00
// How many grenades does the client currently have?
2009-08-26 09:07:01 +02:00
new grenadecount = WeaponAmmoGetGrenadeCount ( client , grenadetype );
2016-02-06 00:47:47 +01:00
2009-08-26 09:07:01 +02:00
// How many grenades can the client hold?
new grenadelimit = WeaponAmmoGetGrenadeLimit ( grenadetype );
2016-02-06 00:47:47 +01:00
2009-08-25 22:07:10 +02:00
// If client is at, or exceeds the grenade limit, then stop.
if ( grenadecount >= grenadelimit )
{
2009-08-26 09:07:01 +02:00
// Client can't carry any more of this type of grenade.
TranslationPrintToChat ( client , " Weapons zmarket grenade max " , grenadelimit );
2009-08-25 22:07:10 +02:00
return false ;
}
}
2016-02-06 00:47:47 +01:00
2016-02-12 04:16:59 +01:00
if ( ! rebuy )
2009-07-02 10:12:41 +02:00
{
2016-02-12 04:16:59 +01:00
// Get client's current money.
new cash = AccountGetClientCash ( client );
2016-02-06 00:47:47 +01:00
2016-02-12 04:16:59 +01:00
// If client doesn't have enough money, tell them, resend menu, and then stop.
if ( cash < itemprice )
{
TranslationPrintToChat ( client , " Weapons zmarket not enough money " );
return false ;
}
2016-02-06 00:47:47 +01:00
2016-02-12 04:16:59 +01:00
// Set client's new cash after purchase.
AccountSetClientCash ( client , cash - itemprice );
}
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Get a list of the client's current weapons.
new weapons [ WeaponsSlot ];
WeaponsGetClientWeapons ( client , weapons );
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// Check if client is buying the weapon or ammo for it.
2009-07-07 06:32:34 +02:00
if ( ! hasweapon || slot == Slot_Projectile || slot == Slot_NVGs )
2009-06-05 05:58:48 +02:00
{
2017-07-05 23:00:50 +02:00
int oldclip = - 1 ;
2009-07-07 06:32:34 +02:00
// If the item is a projectile or NVGs, then skip.
if ( slot != Slot_Projectile && slot != Slot_NVGs )
2009-06-05 05:58:48 +02:00
{
// If there is already a weapon in the slot, then force client to drop it.
if ( weapons [ slot ] > - 1 )
{
2017-07-05 23:00:50 +02:00
oldclip = GetEntProp ( weapons [ slot ], Prop_Send , " m_iClip1 " );
2016-02-12 04:16:59 +01:00
if ( rebuy )
{
// Kill weapon right away to decrease amount of entities on roundstart.
RemoveEdict ( weapons [ slot ]);
}
else
{
// Force client to drop the weapon.
WeaponsForceClientDrop ( client , weapons [ slot ]);
}
2009-06-05 05:58:48 +02:00
}
}
2016-02-06 00:47:47 +01:00
2017-07-05 23:00:50 +02:00
int entity = INVALID_ENT_REFERENCE ;
2015-10-31 00:45:13 +01:00
if ( StrEqual ( weaponentity , " item_kevlar " ))
{
SetEntProp ( client , Prop_Send , " m_ArmorValue " , 100 );
2016-02-12 04:16:59 +01:00
SetEntProp ( client , Prop_Send , " m_bHasHelmet " , 1 );
2015-10-31 00:45:13 +01:00
}
else
{
// Give client the weapon.
2017-07-05 23:00:50 +02:00
entity = GivePlayerItem ( client , weaponentity );
2015-10-31 00:45:13 +01:00
}
2016-02-06 00:47:47 +01:00
2009-08-25 22:07:10 +02:00
if ( ! rebuy )
2009-06-16 20:51:34 +02:00
{
2016-02-12 04:16:59 +01:00
// Add 1 to the client's purchase count.
ZMarketSetPurchaseCount ( client , weapon , 1 , true );
// If client isn't rebuying the weapon, then tell them the weapon has been purchased.
2009-07-07 06:32:34 +02:00
TranslationPrintToChat ( client , " Weapons zmarket purchase " , weapondisplay );
2017-07-05 23:00:50 +02:00
2017-08-03 21:15:54 +02:00
new bool : zmarketnorefill = GetConVarBool ( g_hCvarsList [ CVAR_WEAPONS_ZMARKET_NOREFILL ]);
if ( IsValidEntity ( entity ) && ! WeaponsIsClientInBuyZone ( client ) && zmarketnorefill )
2017-07-05 23:00:50 +02:00
{
int newclip = 0 ;
if ( oldclip != - 1 )
{
newclip = GetEntProp ( entity , Prop_Send , " m_iClip1 " );
if ( newclip > oldclip )
newclip = oldclip ;
}
SetEntProp ( entity , Prop_Send , " m_iClip1 " , newclip );
}
2009-06-16 20:51:34 +02:00
}
2009-06-05 05:58:48 +02:00
}
else if ( ! rebuy )
{
// Get ammo type and stop if it's invalid.
decl String : weaponammo [ WEAPONS_MAX_LENGTH ];
WeaponsGetAmmoType ( weaponindex , weaponammo , sizeof ( weaponammo ));
if ( ! weaponammo [ 0 ])
{
return false ;
}
2016-02-06 00:47:47 +01:00
2010-06-29 21:14:51 +02:00
// Prevent exploit by refilling ammo by re-buying weapon.
// Current clip amounts are stored, ammo is refilled, and then clips are reset.
2016-02-06 00:47:47 +01:00
2010-06-29 21:14:51 +02:00
new prim_clip ;
new sec_clip ;
2016-02-06 00:47:47 +01:00
2010-06-29 21:14:51 +02:00
if ( weapons [ Slot_Primary ] > 0 )
{
prim_clip = WeaponAmmoGetAmmo ( weapons [ Slot_Primary ], true );
}
if ( weapons [ Slot_Secondary ] > 0 )
{
sec_clip = WeaponAmmoGetAmmo ( weapons [ Slot_Secondary ], true );
}
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
GivePlayerItem ( client , weaponammo );
2016-02-06 00:47:47 +01:00
2010-06-29 21:14:51 +02:00
if ( weapons [ Slot_Primary ] > 0 )
{
WeaponAmmoSetAmmo ( weapons [ Slot_Primary ], true , prim_clip );
}
if ( weapons [ Slot_Secondary ] > 0 )
{
WeaponAmmoSetAmmo ( weapons [ Slot_Secondary ], true , sec_clip );
}
2009-06-05 05:58:48 +02:00
}
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
return true ;
}
2009-06-19 05:41:54 +02:00
/**
* Gets the client ' s current weapons and puts them in the rebuy cache .
2016-02-06 00:47:47 +01:00
*
2009-06-19 05:41:54 +02:00
* @ param client The client index .
* @ return True if the menu sent successfully , false if not .
*/
bool : ZMarketGetCurrentLoadout ( client )
{
2016-02-12 04:16:59 +01:00
// If client is dead, then stop.
2009-06-19 05:41:54 +02:00
if ( ! IsPlayerAlive ( client ))
{
TranslationPrintToChat ( client , " Must be alive " );
return false ;
}
2016-02-06 00:47:47 +01:00
2016-02-12 04:16:59 +01:00
// If client is a zombie, then stop.
if ( InfectIsClientInfected ( client ))
2009-06-19 05:41:54 +02:00
{
TranslationPrintToChat ( client , " Must be human " );
return false ;
}
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
// Get all of client's current weapons.
new weapons [ WeaponsSlot ];
WeaponsGetClientWeapons ( client , weapons );
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
decl String : weaponname [ WEAPONS_MAX_LENGTH ];
2009-08-25 22:07:10 +02:00
decl String : weaponentity [ WEAPONS_MAX_LENGTH ];
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
// x = Weapon slot.
2016-02-12 04:16:59 +01:00
for ( new x = 0 ; x < ZMARKET_REBUY_WEAPONS_SLOTS_MAX + 1 ; x ++ )
2009-06-19 05:41:54 +02:00
{
// If slot is empty, then clear this slot in rebuy cache and stop.
if ( weapons [ x ] == - 1 )
{
// Empty rebuy slot.
2009-06-21 21:24:24 +02:00
ZMarketSetRebuyCookie ( client , WeaponsSlot : x , " " );
2009-06-19 05:41:54 +02:00
continue ;
}
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
// Get the name of the weapon.
2009-08-25 22:07:10 +02:00
GetEdictClassname ( weapons [ x ], weaponentity , sizeof ( weaponentity ));
2016-02-06 00:47:47 +01:00
2009-08-25 22:07:10 +02:00
// Get the entity name of the weapon.
WeaponsEntityToDisplay ( weaponentity , weaponname , sizeof ( weaponname ));
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
// Copy the name to the rebuy cache.
2009-06-21 21:24:24 +02:00
ZMarketSetRebuyCookie ( client , WeaponsSlot : x , weaponname );
2009-06-19 05:41:54 +02:00
}
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
// Tell client their loadout has been updated.
TranslationPrintToChat ( client , " Weapons zmarket get current loadout " );
2016-02-06 00:47:47 +01:00
2009-06-19 05:41:54 +02:00
return true ;
}
2009-06-21 21:24:24 +02:00
/**
* Transfer array values to rebuy cookies .
2016-02-06 00:47:47 +01:00
*
2009-06-21 21:24:24 +02:00
* @ param client The client index .
* @ param rebuyweapons The string array to copy results from .
* @ param maxweapons The max amount of weapons in the array .
* @ param maxlen The max length of each cookie result .
*/
2016-02-12 04:16:59 +01:00
stock ZMarketArrayToCookies ( client , String : rebuyweapons [ ZMARKET_REBUY_WEAPONS_SLOTS_MAX + 1 ][], maxweapons , maxlen )
2009-06-21 21:24:24 +02:00
{
decl String : rebuycookiename [ 32 ];
new Handle : rebuycookie ;
2016-02-06 00:47:47 +01:00
2009-06-21 21:24:24 +02:00
// x = Weapon slot.
for ( new x = 0 ; x < maxweapons ; x ++ )
{
// Format cookie name.
Format ( rebuycookiename , sizeof ( rebuycookiename ), " %s_%d " , ZMARKET_COOKIE_REBUY , x );
2016-02-06 00:47:47 +01:00
2009-06-21 21:24:24 +02:00
// Find cookie handle, and retrieve its value.
rebuycookie = FindClientCookie ( rebuycookiename );
SetClientCookie ( client , rebuycookie , rebuyweapons [ x ]);
2009-10-25 00:08:53 +02:00
CloseHandle ( rebuycookie );
2009-06-21 21:24:24 +02:00
}
}
/**
* Transfer rebuy cookies to an array for easier access .
2016-02-06 00:47:47 +01:00
*
2009-06-21 21:24:24 +02:00
* @ param client The client index .
* @ param rebuyweapons The string array to copy results to
* @ param maxweapons The max amount of weapons in the array .
* @ param maxlen The max length of each cookie result .
*/
2016-02-12 04:16:59 +01:00
stock ZMarketCookiesToArray ( client , String : rebuyweapons [ ZMARKET_REBUY_WEAPONS_SLOTS_MAX + 1 ][], maxweapons , maxlen )
2009-06-21 21:24:24 +02:00
{
decl String : rebuycookiename [ 32 ];
new Handle : rebuycookie ;
2016-02-06 00:47:47 +01:00
2009-06-21 21:24:24 +02:00
// x = Weapon slot.
for ( new x = 0 ; x < maxweapons ; x ++ )
{
// Format cookie name.
Format ( rebuycookiename , sizeof ( rebuycookiename ), " %s_%d " , ZMARKET_COOKIE_REBUY , x );
2016-02-06 00:47:47 +01:00
2009-06-21 21:24:24 +02:00
// Find cookie handle, and retrieve its value.
rebuycookie = FindClientCookie ( rebuycookiename );
GetClientCookie ( client , rebuycookie , rebuyweapons [ x ], maxlen );
2009-10-25 00:08:53 +02:00
CloseHandle ( rebuycookie );
2009-06-21 21:24:24 +02:00
}
}
/**
* Set a weapon slot cookie given the slot and value .
2016-02-06 00:47:47 +01:00
*
2009-06-21 21:24:24 +02:00
* @ param client The client index .
* @ param slot The weapon slot to set value to .
* @ param value The value ( weaponname ) of the slot .
*/
stock ZMarketSetRebuyCookie ( client , WeaponsSlot : slot , const String : value [])
{
// Format cookie name.
decl String : rebuycookiename [ 32 ];
Format ( rebuycookiename , sizeof ( rebuycookiename ), " %s_%d " , ZMARKET_COOKIE_REBUY , _ : slot );
2016-02-06 00:47:47 +01:00
2009-06-21 21:24:24 +02:00
// Find cookie handle, and retrieve its value.
new Handle : rebuycookie = FindClientCookie ( rebuycookiename );
2009-07-05 08:49:23 +02:00
if ( rebuycookie == INVALID_HANDLE )
{
return ;
}
2016-02-06 00:47:47 +01:00
2009-07-05 08:49:23 +02:00
// Set weapon to cookie.
2009-06-21 21:24:24 +02:00
SetClientCookie ( client , rebuycookie , value );
2009-10-25 00:08:53 +02:00
CloseHandle ( rebuycookie );
2009-06-21 21:24:24 +02:00
}
2009-06-05 05:58:48 +02:00
/**
* Force a client to rebuy their weapons .
2016-02-06 00:47:47 +01:00
*
2009-06-05 05:58:48 +02:00
* @ param client The client index .
*/
2009-06-21 21:24:24 +02:00
ZMarketRebuy ( client , bool : autorebuy = false )
2009-06-05 05:58:48 +02:00
{
2011-04-24 23:28:52 +02:00
// If client is dead, then stop.
if ( ! IsPlayerAlive ( client ))
{
TranslationPrintToChat ( client , " Must be alive " );
return ;
}
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// If client is a zombie, then stop.
if ( InfectIsClientInfected ( client ))
{
TranslationPrintToChat ( client , " Must be human " );
return ;
}
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
new bool : zmarketbuyzone = GetConVarBool ( g_hCvarsList [ CVAR_WEAPONS_ZMARKET_BUYZONE ]);
2010-02-14 17:03:19 +01:00
if ( ! autorebuy && zmarketbuyzone && ! WeaponsIsClientInBuyZone ( client ))
2009-06-05 05:58:48 +02:00
{
TranslationPrintToChat ( client , " Weapons zmarket buyzone " );
return ;
}
2016-02-06 00:47:47 +01:00
2009-06-21 21:24:24 +02:00
// Transfer cookie values into an array.
2016-02-12 04:16:59 +01:00
new String : rebuyweapons [ ZMARKET_REBUY_WEAPONS_SLOTS_MAX + 1 ][ WEAPONS_MAX_LENGTH ];
ZMarketCookiesToArray ( client , rebuyweapons , sizeof ( rebuyweapons ), sizeof ( rebuyweapons []));
2016-02-06 00:47:47 +01:00
2009-06-05 05:58:48 +02:00
// x = Weapon slot.
2016-02-12 04:16:59 +01:00
for ( new x = 0 ; x < ZMARKET_REBUY_WEAPONS_SLOTS_MAX + 1 ; x ++ )
2009-06-05 05:58:48 +02:00
{
2016-02-12 04:16:59 +01:00
// If slot is empty, then use the default value.
2009-06-21 22:56:48 +02:00
if ( ! rebuyweapons [ x ][ 0 ])
{
2016-02-12 04:16:59 +01:00
switch ( x )
{
case Slot_Primary :
{
GetConVarString ( g_hCvarsList [ CVAR_WEAPONS_ZMARKET_REBUY_PRIMARY ], rebuyweapons [ x ], sizeof ( rebuyweapons []));
}
case Slot_Secondary :
{
GetConVarString ( g_hCvarsList [ CVAR_WEAPONS_ZMARKET_REBUY_SECONDARY ], rebuyweapons [ x ], sizeof ( rebuyweapons []));
}
}
2009-06-21 22:56:48 +02:00
}
2016-02-06 00:47:47 +01:00
2017-08-07 23:50:39 +02:00
if ( ! RestrictIsWeaponRestricted ( WeaponsNameToIndex ( rebuyweapons [ x ])))
ZMarketEquip ( client , rebuyweapons [ x ], autorebuy );
2009-06-05 05:58:48 +02:00
}
2016-02-12 04:16:59 +01:00
if ( autorebuy )
2009-06-22 06:08:26 +02:00
{
2016-02-12 04:16:59 +01:00
// Always equip kevlar and hegrenade
2017-08-07 23:50:39 +02:00
if ( ! RestrictIsWeaponRestricted ( WeaponsNameToIndex ( " Kevlar Vest " )))
ZMarketEquip ( client , " Kevlar Vest " , autorebuy );
if ( ! RestrictIsWeaponRestricted ( WeaponsNameToIndex ( " HEGrenade " )))
ZMarketEquip ( client , " HEGrenade " , autorebuy );
if ( ! RestrictIsWeaponRestricted ( WeaponsNameToIndex ( " Smokegrenade " )))
ZMarketEquip ( client , " Smokegrenade " , autorebuy );
2017-08-23 17:23:43 +02:00
if ( g_Game == Game_CSGO )
{
if ( ! RestrictIsWeaponRestricted ( WeaponsNameToIndex ( " Healthshot " )))
ZMarketEquip ( client , " Healthshot " , autorebuy );
if ( ! RestrictIsWeaponRestricted ( WeaponsNameToIndex ( " TAGrenade " )))
ZMarketEquip ( client , " TAGrenade " , autorebuy );
}
2009-06-22 06:08:26 +02:00
}
}
2009-06-17 23:32:46 +02:00
/**
* Command callback ( zmarket )
* Opens custom buymenu .
2016-02-06 00:47:47 +01:00
*
2009-06-17 23:32:46 +02:00
* @ param client The client index .
* @ param argc Argument count .
*/
public Action : ZMarketCommand ( client , argc )
{
// If client is console, then stop and tell them this feature is for players only.
if ( ZRIsConsole ( client ))
{
TranslationPrintToServer ( " Must be player " );
return Plugin_Handled ;
}
2016-02-06 00:47:47 +01:00
2009-06-17 23:32:46 +02:00
// Send ZMarket menu.
2009-06-19 05:41:54 +02:00
ZMarketMenuMain ( client );
2016-02-06 00:47:47 +01:00
2009-06-17 23:32:46 +02:00
// This stops the "Unknown command" message in client's console.
return Plugin_Handled ;
}