ZMarket now remembers NVG purchases, and has a custom slot in the loadout menu.

Fixed minor display glitch. (wasn't using the file displayname)
This commit is contained in:
Greyscale 2009-07-06 21:32:34 -07:00
parent eca1aee679
commit 324dd1abe7
7 changed files with 93 additions and 28 deletions

View File

@ -736,6 +736,7 @@
// General // General
"weapontype" "All, Equipment" "weapontype" "All, Equipment"
"weaponslot" "5"
// Restrict (core) // Restrict (core)

View File

@ -683,7 +683,7 @@
"Weapons menu zmarket loadout title" "Weapons menu zmarket loadout title"
{ {
"en" "ZMarket\nMy Current Loadout:\nRebuy refers to these weapons" "en" "ZMarket\nMy Current Loadout:\nSelect weapon slot to clear.\nNote: Rebuy refers to these weapons."
} }
"Weapons menu zmarket loadout primary" "Weapons menu zmarket loadout primary"
@ -716,6 +716,12 @@
"en" "Explosive: {1}" "en" "Explosive: {1}"
} }
"Weapons menu zmarket loadout nvgs"
{
"#format" "{1:s}"
"en" "NVGs: {1}"
}
"Weapons menu zmarket loadout empty" "Weapons menu zmarket loadout empty"
{ {
"en" "(None)" "en" "(None)"

View File

@ -211,8 +211,8 @@ bool:ClassApplyNightVision(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER
nvgs = ClassGetNvgs(classindex, cachetype); nvgs = ClassGetNvgs(classindex, cachetype);
} }
ToolsClientNightVision(client, nvgs); ToolsSetClientNightVision(client, nvgs);
ToolsClientNightVision(client, nvgs, false); ToolsSetClientNightVision(client, nvgs, false);
return true; return true;
} }

View File

@ -78,6 +78,24 @@ stock ToolsSetClientLMV(client, Float:fLMV)
SetEntDataFloat(client, g_iToolsLMV, fLMV / 300.0, true); SetEntDataFloat(client, g_iToolsLMV, fLMV / 300.0, true);
} }
/**
* Get nightvision values on a client.
* @param client The client index.
* @param ownership If true, function will return the value of the client's ownership of nightvision.
* If false, function will return the value of the client's on/off state of the nightvision.
* @return True if aspect of nightvision is enabled on the client, false if not.
*/
stock bool:ToolsGetClientNightVision(client, bool:ownership = true)
{
// If ownership is true, then toggle the ownership of nightvision on client.
if (ownership)
{
return bool:GetEntData(client, g_iToolsHasNightVision, 1);
}
return bool:GetEntData(client, g_iToolsNightVisionOn, 1);
}
/** /**
* Control nightvision values on a client. * Control nightvision values on a client.
* @param client The client index. * @param client The client index.
@ -85,7 +103,7 @@ stock ToolsSetClientLMV(client, Float:fLMV)
* @param ownership If true, enable will toggle the client's ownership of nightvision. * @param ownership If true, enable will toggle the client's ownership of nightvision.
* If false, enable will toggle the client's on/off state of the nightvision. * If false, enable will toggle the client's on/off state of the nightvision.
*/ */
stock ToolsClientNightVision(client, bool:enable, bool:ownership = true) stock ToolsSetClientNightVision(client, bool:enable, bool:ownership = true)
{ {
// If ownership is true, then toggle the ownership of nightvision on client. // If ownership is true, then toggle the ownership of nightvision on client.
if (ownership) if (ownership)

View File

@ -231,7 +231,7 @@ public Action:RestrictBuyCommand(client, argc)
return Plugin_Handled; return Plugin_Handled;
} }
decl String:weapon[64]; decl String:weapon[WEAPONS_MAX_LENGTH];
GetCmdArg(1, weapon, sizeof(weapon)); GetCmdArg(1, weapon, sizeof(weapon));
ReplaceString(weapon, sizeof(weapon), "weapon_", ""); ReplaceString(weapon, sizeof(weapon), "weapon_", "");
@ -249,7 +249,11 @@ public Action:RestrictBuyCommand(client, argc)
// If weapon is restricted, then stop. // If weapon is restricted, then stop.
if (RestrictIsWeaponRestricted(index)) if (RestrictIsWeaponRestricted(index))
{ {
TranslationPrintToChat(client, "Weapon is restricted", weapon); // Get display name.
decl String:weapondisplay[WEAPONS_MAX_LENGTH];
WeaponsGetName(index, weapondisplay, sizeof(weapondisplay));
TranslationPrintToChat(client, "Weapon is restricted", weapondisplay);
// Block command. // Block command.
return Plugin_Handled; return Plugin_Handled;

View File

@ -31,7 +31,7 @@
#define WEAPONS_MAX_LENGTH 32 #define WEAPONS_MAX_LENGTH 32
/** /**
* Number of weapon slots (For CS:S) * Number of REAL weapon slots (For CS:S)
*/ */
#define WEAPONS_SLOTS_MAX 5 #define WEAPONS_SLOTS_MAX 5
@ -82,6 +82,7 @@ enum WeaponsSlot
Slot_Melee = 2, /** Melee (knife) weapon slot. */ Slot_Melee = 2, /** Melee (knife) weapon slot. */
Slot_Projectile = 3, /** Projectile (grenades, flashbangs, etc) weapon slot. */ Slot_Projectile = 3, /** Projectile (grenades, flashbangs, etc) weapon slot. */
Slot_Explosive = 4, /** Explosive (c4) weapon slot. */ Slot_Explosive = 4, /** Explosive (c4) weapon slot. */
Slot_NVGs = 5, /** NVGs (fake) equipment slot. */
} }
/** /**

View File

@ -75,7 +75,7 @@ ZMarketOnCookiesCreate()
decl String:rebuycookiedesc[64]; decl String:rebuycookiedesc[64];
// x = Weapon slot. // x = Weapon slot.
for (new x = 0; x < WEAPONS_SLOTS_MAX; x++) for (new x = 0; x < WEAPONS_SLOTS_MAX + 1; x++)
{ {
// Format cookie name and description. // Format cookie name and description.
Format(rebuycookiename, sizeof(rebuycookiename), "%s_%d", ZMARKET_COOKIE_REBUY, x); Format(rebuycookiename, sizeof(rebuycookiename), "%s_%d", ZMARKET_COOKIE_REBUY, x);
@ -388,10 +388,11 @@ bool:ZMarketMenuLoadout(client)
decl String:meleeweapon[WEAPONS_MAX_LENGTH]; decl String:meleeweapon[WEAPONS_MAX_LENGTH];
decl String:projectileweapon[WEAPONS_MAX_LENGTH]; decl String:projectileweapon[WEAPONS_MAX_LENGTH];
decl String:explosiveweapon[WEAPONS_MAX_LENGTH]; decl String:explosiveweapon[WEAPONS_MAX_LENGTH];
decl String:nvgsweapon[WEAPONS_MAX_LENGTH];
// Transfer cookie values into an array. // Transfer cookie values into an array.
new String:rebuyweapons[WeaponsSlot][WEAPONS_MAX_LENGTH]; new String:rebuyweapons[WeaponsSlot][WEAPONS_MAX_LENGTH];
ZMarketCookiesToArray(client, rebuyweapons, WEAPONS_SLOTS_MAX, sizeof(rebuyweapons[])); ZMarketCookiesToArray(client, rebuyweapons, WEAPONS_SLOTS_MAX + 1, sizeof(rebuyweapons[]));
// Return the display name for all the client's weapon classname's. // Return the display name for all the client's weapon classname's.
WeaponsClassnameToDisplay(rebuyweapons[Slot_Primary], sizeof(rebuyweapons[]), primaryweapon, sizeof(primaryweapon)); WeaponsClassnameToDisplay(rebuyweapons[Slot_Primary], sizeof(rebuyweapons[]), primaryweapon, sizeof(primaryweapon));
@ -399,6 +400,7 @@ bool:ZMarketMenuLoadout(client)
WeaponsClassnameToDisplay(rebuyweapons[Slot_Melee], sizeof(rebuyweapons[]), meleeweapon, sizeof(meleeweapon)); WeaponsClassnameToDisplay(rebuyweapons[Slot_Melee], sizeof(rebuyweapons[]), meleeweapon, sizeof(meleeweapon));
WeaponsClassnameToDisplay(rebuyweapons[Slot_Projectile], sizeof(rebuyweapons[]), projectileweapon, sizeof(projectileweapon)); WeaponsClassnameToDisplay(rebuyweapons[Slot_Projectile], sizeof(rebuyweapons[]), projectileweapon, sizeof(projectileweapon));
WeaponsClassnameToDisplay(rebuyweapons[Slot_Explosive], sizeof(rebuyweapons[]), explosiveweapon, sizeof(explosiveweapon)); WeaponsClassnameToDisplay(rebuyweapons[Slot_Explosive], sizeof(rebuyweapons[]), explosiveweapon, sizeof(explosiveweapon));
WeaponsClassnameToDisplay(rebuyweapons[Slot_NVGs], sizeof(rebuyweapons[]), nvgsweapon, sizeof(nvgsweapon));
// Get the empty translation. // Get the empty translation.
decl String:empty[64]; decl String:empty[64];
@ -426,11 +428,16 @@ bool:ZMarketMenuLoadout(client)
strcopy(explosiveweapon, sizeof(explosiveweapon), empty); strcopy(explosiveweapon, sizeof(explosiveweapon), empty);
} }
// Copy "Yes/No" to NVGs string.
decl String:nvgsbool[8];
ConfigBoolToSetting(bool:nvgsweapon[0], nvgsbool, sizeof(nvgsbool));
decl String:primary[64]; decl String:primary[64];
decl String:secondary[64]; decl String:secondary[64];
decl String:melee[64]; decl String:melee[64];
decl String:projectile[64]; decl String:projectile[64];
decl String:explosive[64]; decl String:explosive[64];
decl String:nvgs[64];
// Format all the lines of the menu. // Format all the lines of the menu.
Format(primary, sizeof(primary), "%t", "Weapons menu zmarket loadout primary", primaryweapon); Format(primary, sizeof(primary), "%t", "Weapons menu zmarket loadout primary", primaryweapon);
@ -438,13 +445,15 @@ bool:ZMarketMenuLoadout(client)
Format(melee, sizeof(melee), "%t", "Weapons menu zmarket loadout melee", meleeweapon); Format(melee, sizeof(melee), "%t", "Weapons menu zmarket loadout melee", meleeweapon);
Format(projectile, sizeof(projectile), "%t", "Weapons menu zmarket loadout projectile", projectileweapon); Format(projectile, sizeof(projectile), "%t", "Weapons menu zmarket loadout projectile", projectileweapon);
Format(explosive, sizeof(explosive), "%t", "Weapons menu zmarket loadout explosive", explosiveweapon); Format(explosive, sizeof(explosive), "%t", "Weapons menu zmarket loadout explosive", explosiveweapon);
Format(nvgs, sizeof(nvgs), "%t", "Weapons menu zmarket loadout nvgs", nvgsbool);
// Add formatted options to menu. // Add formatted options to menu.
AddMenuItem(menu_zmarket_loadout, primary, primary, ITEMDRAW_DISABLED); AddMenuItem(menu_zmarket_loadout, "0", primary, MenuGetItemDraw(!StrEqual(primaryweapon, empty)));
AddMenuItem(menu_zmarket_loadout, secondary, secondary, ITEMDRAW_DISABLED); AddMenuItem(menu_zmarket_loadout, "1", secondary, MenuGetItemDraw(!StrEqual(secondaryweapon, empty)));
AddMenuItem(menu_zmarket_loadout, melee, melee, ITEMDRAW_DISABLED); AddMenuItem(menu_zmarket_loadout, "2", melee, MenuGetItemDraw(!StrEqual(meleeweapon, empty)));
AddMenuItem(menu_zmarket_loadout, projectile, projectile, ITEMDRAW_DISABLED); AddMenuItem(menu_zmarket_loadout, "3", projectile, MenuGetItemDraw(!StrEqual(projectileweapon, empty)));
AddMenuItem(menu_zmarket_loadout, explosive, explosive, ITEMDRAW_DISABLED); AddMenuItem(menu_zmarket_loadout, "4", explosive, MenuGetItemDraw(!StrEqual(explosiveweapon, empty)));
AddMenuItem(menu_zmarket_loadout, "5", nvgs, MenuGetItemDraw(bool:nvgsweapon[0]));
// Set exit back button. // Set exit back button.
SetMenuExitBackButton(menu_zmarket_loadout, true); SetMenuExitBackButton(menu_zmarket_loadout, true);
@ -463,6 +472,15 @@ bool:ZMarketMenuLoadout(client)
*/ */
public ZMarketMenuLoadoutHandle(Handle:menu_zmarket_loadout, MenuAction:action, client, slot) public ZMarketMenuLoadoutHandle(Handle:menu_zmarket_loadout, MenuAction:action, client, slot)
{ {
// Client selected an option.
if (action == MenuAction_Select)
{
// Clear rebuy slot.
ZMarketSetRebuyCookie(client, WeaponsSlot:slot, "");
// Re-send menu.
ZMarketMenuLoadout(client);
}
// Client closed the menu. // Client closed the menu.
if (action == MenuAction_Cancel) if (action == MenuAction_Cancel)
{ {
@ -785,11 +803,19 @@ stock bool:ZMarketEquip(client, const String:weapon[], bool:rebuy = false)
return false; return false;
} }
// Copy the 'weapon' variable into a local variable for indexing.
decl String:weaponname[WEAPONS_MAX_LENGTH];
strcopy(weaponname, sizeof(weaponname), weapon);
// Get the display name for the weapon.
decl String:weapondisplay[WEAPONS_MAX_LENGTH];
WeaponsClassnameToDisplay(weaponname, sizeof(weaponname), weapondisplay, sizeof(weapondisplay));
// Check to make sure the weapon isn't restricted. // Check to make sure the weapon isn't restricted.
new bool:restricted = RestrictIsWeaponRestricted(weaponindex); new bool:restricted = RestrictIsWeaponRestricted(weaponindex);
if (restricted) if (restricted)
{ {
TranslationPrintToChat(client, "Weapon is restricted", weapon); TranslationPrintToChat(client, "Weapon is restricted", weapondisplay);
return false; return false;
} }
@ -799,7 +825,7 @@ stock bool:ZMarketEquip(client, const String:weapon[], bool:rebuy = false)
new purchasesleft = purchasemax - purchasecount; new purchasesleft = purchasemax - purchasecount;
if (purchasemax > 0 && purchasesleft <= 0) if (purchasemax > 0 && purchasesleft <= 0)
{ {
TranslationPrintToChat(client, "Weapons zmarket purchase max", weapon, purchasemax); TranslationPrintToChat(client, "Weapons zmarket purchase max", weapondisplay, purchasemax);
return false; return false;
} }
@ -824,11 +850,11 @@ stock bool:ZMarketEquip(client, const String:weapon[], bool:rebuy = false)
WeaponsGetClientWeapons(client, weapons); WeaponsGetClientWeapons(client, weapons);
// Check if client is buying the weapon or ammo for it. // Check if client is buying the weapon or ammo for it.
if (!hasweapon || slot == Slot_Invalid || slot == Slot_Projectile) if (!hasweapon || slot == Slot_Projectile || slot == Slot_NVGs)
{ {
// Check if the slot is valid and NOT a projectile (grenade). // If the item is a projectile or NVGs, then skip.
if (slot != Slot_Invalid && slot != Slot_Projectile) if (slot != Slot_Projectile && slot != Slot_NVGs)
{ {
// If there is already a weapon in the slot, then force client to drop it. // If there is already a weapon in the slot, then force client to drop it.
if (weapons[slot] > -1) if (weapons[slot] > -1)
@ -841,8 +867,8 @@ stock bool:ZMarketEquip(client, const String:weapon[], bool:rebuy = false)
// Format name into entity name. // Format name into entity name.
decl String:weaponentity[WEAPONS_MAX_LENGTH]; decl String:weaponentity[WEAPONS_MAX_LENGTH];
// If the slot is invalid, this means the item is not a usable weapon, it's equipment. // If this is the NVGs slot, then format "item_" in front instead of "weapon_".
if (slot == Slot_Invalid) if (slot == Slot_NVGs)
{ {
Format(weaponentity, sizeof(weaponentity), "item_%s", weapon); Format(weaponentity, sizeof(weaponentity), "item_%s", weapon);
} }
@ -860,10 +886,10 @@ stock bool:ZMarketEquip(client, const String:weapon[], bool:rebuy = false)
// Add 1 to the client's purchase count. // Add 1 to the client's purchase count.
ZMarketSetPurchaseCount(client, weapon, 1, true); ZMarketSetPurchaseCount(client, weapon, 1, true);
if (slot != Slot_Invalid && slot != Slot_Projectile) if (slot != Slot_Projectile && slot != Slot_NVGs)
{ {
// Tell client they bought a weapon. // Tell client they bought a weapon.
TranslationPrintToChat(client, "Weapons zmarket purchase", weapon); TranslationPrintToChat(client, "Weapons zmarket purchase", weapondisplay);
} }
} }
else if (!rebuy) else if (!rebuy)
@ -932,6 +958,18 @@ bool:ZMarketGetCurrentLoadout(client)
ZMarketSetRebuyCookie(client, WeaponsSlot:x, weaponname); ZMarketSetRebuyCookie(client, WeaponsSlot:x, weaponname);
} }
// Update nightvision ownership.
new bool:nightvision = ToolsGetClientNightVision(client);
if (!nightvision)
{
// Empty rebuy slot.
ZMarketSetRebuyCookie(client, Slot_NVGs, "");
}
else
{
ZMarketSetRebuyCookie(client, Slot_NVGs, "nvgs");
}
// Tell client their loadout has been updated. // Tell client their loadout has been updated.
TranslationPrintToChat(client, "Weapons zmarket get current loadout"); TranslationPrintToChat(client, "Weapons zmarket get current loadout");
@ -1035,10 +1073,10 @@ ZMarketRebuy(client, bool:autorebuy = false)
// Transfer cookie values into an array. // Transfer cookie values into an array.
new String:rebuyweapons[WeaponsSlot][WEAPONS_MAX_LENGTH]; new String:rebuyweapons[WeaponsSlot][WEAPONS_MAX_LENGTH];
ZMarketCookiesToArray(client, rebuyweapons, WEAPONS_SLOTS_MAX, sizeof(rebuyweapons[])); ZMarketCookiesToArray(client, rebuyweapons, WEAPONS_SLOTS_MAX + 1, sizeof(rebuyweapons[]));
// x = Weapon slot. // x = Weapon slot.
for (new x = 0; x < WEAPONS_SLOTS_MAX; x++) for (new x = 0; x < WEAPONS_SLOTS_MAX + 1; x++)
{ {
// If slot is empty, then stop. // If slot is empty, then stop.
if (!rebuyweapons[x][0]) if (!rebuyweapons[x][0])
@ -1048,9 +1086,6 @@ ZMarketRebuy(client, bool:autorebuy = false)
ZMarketEquip(client, rebuyweapons[x], true); ZMarketEquip(client, rebuyweapons[x], true);
} }
// Copy values back to cookies.
ZMarketArrayToCookies(client, rebuyweapons, WEAPONS_SLOTS_MAX, sizeof(rebuyweapons));
} }
/** /**