Updated ZMarket to distribute grenades correctly. Still need to update the loadout to support multiple nades, to support multiple flashbangs and Grenade Pack fully. As of now the market allows you to buy 3 grenades but they don't show in the loadout as 3.

Worked more on the voice API, need to figure out why they are reversed. The cvar to disable it now should work, because it doesn't quite work right.
Changed Gangsta Glock back to Glock :P
This commit is contained in:
Greyscale 2009-08-26 00:07:01 -07:00
parent 34c6f853ff
commit 0c2230ad45
7 changed files with 263 additions and 73 deletions

View File

@ -27,7 +27,7 @@
"weapons" // Counter-Strike: Source weapons
{
"Gangsta Glock"
"Glock"
{
// General

View File

@ -1,4 +1,15 @@
"Phrases"
// =======================================
// CHANGELOG
// =======================================
// RECORD ALLLLL CHANGES TO THIS FILE HERE.
//
// 8/25/09 5:15 PM
// Added phrase "Weapons zmarket grenade max" Line 588.
//
//
//
"Phrases"
{
// ===========================
// General (base)
@ -575,6 +586,12 @@
"en" "Weapon @green{1} @defaulthas a purchase limit of @green{2}@default. Wait until you respawn to try again."
}
"Weapons zmarket grenade max"
{
"#format" "{1:d}"
"en" "You may only carry {1} grenade(s) of this type."
}
"Weapons zmarket auto-rebuy toggle on"
{
"en" "Auto-rebuy has been enabled, your loadout will be automatically purchased for you each time you spawn."

View File

@ -75,6 +75,7 @@ SEffectsClientInit(client)
SEffectsOnRoundStart()
{
// Forward event to sub-modules.
VoiceOnRoundStart();
AmbientSoundsOnRoundStart();
}
@ -84,6 +85,7 @@ SEffectsOnRoundStart()
SEffectsOnRoundEnd()
{
// Forward event to sub-modules.
VoiceOnRoundEnd();
AmbientSoundsOnRoundEnd();
}

View File

@ -25,6 +25,43 @@
* ============================================================================
*/
/**
* Updates every round with the value of the cvar.
*/
new bool:g_bVoice;
/**
* The round is starting.
*/
VoiceOnRoundStart()
{
new bool:voice = GetConVarBool(g_hCvarsList[CVAR_VOICE]);
// If the cvar has changed, then reset the voice permissions.
if (g_bVoice != voice)
{
VoiceReset();
}
// Update g_bVoice with new value.
g_bVoice = voice;
}
/**
* The round is ending.
*/
VoiceOnRoundEnd()
{
// If voice module is disabled, then stop.
if (!g_bVoice)
{
return;
}
// Allow everyone to listen/speak with each other.
VoiceAllTalk();
}
/**
* Client is spawning into the game.
*
@ -58,6 +95,26 @@ VoiceOnClientHuman(client)
VoiceUpdateClient(client);
}
/**
* Set the receiver ability to listen to the sender.
* Note: This function is from sdktools_voice, it fails if iSender is muted.
*
* @param iReceiver The listener index.
* @param iSender The sender index.
* @return True if successful otherwise false.
*/
stock bool:VoiceSetClientListening(iReceiver, iSender, bool:bListen)
{
// If the sender is muted, then return false.
if (VoiceIsClientMuted(iSender))
{
return false;
}
SetClientListening(iReceiver, iSender, bListen);
return true;
}
/**
* Allow all clients to listen and speak with each other.
*/
@ -87,8 +144,8 @@ stock VoiceAllTalk()
continue;
}
// Receiver (x) can now hear the sender (y).
SetClientListening(x, y, true);
// Receiver (x) can now hear the sender (y), only if sender isn't muted.
VoiceSetClientListening(x, y, true);
}
}
}
@ -113,9 +170,9 @@ stock VoiceSetClientTeam(client, bool:zombie)
// Client can only listen/speak if the sender is on their team.
new bool:canlisten = (zombie == InfectIsClientInfected(x));
// (Dis)allow clients to listen/speak with each other.
SetClientListening(client, x, canlisten);
SetClientListening(x, client, canlisten);
// (Dis)allow clients to listen/speak with each other, don't touch if the sender is muted.
VoiceSetClientListening(client, x, canlisten);
VoiceSetClientListening(x, client, canlisten);
}
}
@ -126,6 +183,49 @@ stock VoiceSetClientTeam(client, bool:zombie)
*/
stock VoiceUpdateClient(client)
{
// If voice module is disabled, then stop.
if (!g_bVoice)
{
return;
}
// Set the client's listening/speaking status to their current team.
VoiceSetClientTeam(client, InfectIsClientInfected(client));
}
/**
* This function returns if the client is muted.
*
* @param client The client index.
* @return True if the client is muted, false if not.
*/
stock bool:VoiceIsClientMuted(client)
{
// Return true if the mute flag isn't on the client.
return bool:(GetClientListeningFlags(client) & VOICE_MUTED);
}
/**
* Reset voice listening/speaking permissions back to normal according to sv_alltalk.
*/
stock VoiceReset()
{
// Is alltalk enabled?
new bool:alltalk = GetConVarBool(FindConVar("sv_alltalk"));
// Determine new voice flags based off of alltalk.
new voiceflags = alltalk ? VOICE_SPEAKALL | VOICE_LISTENALL : VOICE_TEAM | VOICE_LISTENTEAM;
// x = Client index.
for (new x = 1; x <= MaxClients; x++)
{
// If client isn't in-game, then stop.
if (!IsClientInGame(x))
{
continue;
}
// Apply new voice flags.
SetClientListeningFlags(x, voiceflags);
}
}

View File

@ -25,6 +25,30 @@
* ============================================================================
*/
/**
* @section Grenade Pack plugin information.
*/
#define GRENADE_PACK_FILENAME "grenadepack.smx"
#define GRENADE_PACK_CVAR_LIMIT "gp_limit"
/**
* @endsection
*/
/**
* @section Defines for ZMarket grenade limits, supporting the Grenade Pack plugin.
*/
#define WEAPONAMMO_HEGRENADE_LIMIT 1
#define WEAPONAMMO_FLASHBANG_LIMIT 2
#define WEAPONAMMO_SMOKEGRENADE_LIMIT 1
/**
* @endsection
*/
/**
* Variable to store if Grenade Pack is loaded and running.
*/
new bool:g_bGrenadePack;
/**
* @section Variables to store ammo offset values.
*/
@ -40,11 +64,21 @@ new g_iToolsAmmo;
*/
enum WeaponAmmoGrenadeType
{
GrenadeType_Invalid = -1, /** Invalid grenade slot. */
GrenadeType_HEGrenade = 11, /** HEGrenade slot */
GrenadeType_Flashbang = 12, /** Flashbang slot. */
GrenadeType_Smokegrenade = 13, /** Smokegrenade slot. */
}
/**
* All plugins have finished loading.
*/
WeaponAmmoOnAllPluginsLoaded()
{
// Check if "Grenade Pack" is loaded
g_bGrenadePack = ZMarketIsGPLoaded();
}
/**
* Find ammo-reserve-specific offsets here.
*/
@ -64,7 +98,7 @@ WeaponAmmoOnOffsetsFound()
LogEvent(false, LogType_Fatal, LOG_CORE_EVENTS, LogModule_Weapons, "Offsets", "Offset \"CBaseCombatWeapon::m_iClip2\" was not found.");
}
// If offset "m_iClip2" can't be found, then stop the plugin.
// If offset "m_iAmmo" can't be found, then stop the plugin.
g_iToolsAmmo = FindSendPropInfo("CBasePlayer", "m_iAmmo");
if (g_iToolsAmmo == -1)
{
@ -144,4 +178,90 @@ stock WeaponAmmoSetGrenadeCount(client, WeaponAmmoGrenadeType:type, value, bool:
stock WeaponAmmoGetGrenadeCount(client, WeaponAmmoGrenadeType:type)
{
return GetEntData(client, g_iToolsAmmo + (_:type * 4));
}
/**
* Takes a weapon entity and returns an entry in enum WeaponAmmoGrenadeType.
*
* @param weaponentity The weapon entity to find entry for.
* @return An entry in WeaponAmmoGrenadeType.
*/
stock WeaponAmmoGrenadeType:WeaponAmmoEntityToGrenadeType(const String:weaponentity[])
{
if (StrEqual(weaponentity, "weapon_hegrenade"))
{
return GrenadeType_HEGrenade;
}
else if (StrEqual(weaponentity, "weapon_flashbang"))
{
return GrenadeType_Flashbang;
}
else if (StrEqual(weaponentity, "weapon_smokegrenade"))
{
return GrenadeType_Smokegrenade;
}
return GrenadeType_Invalid;
}
/**
* Returns the max amount of this type of grenades the client is allowed to carry.
*
* @param weaponentity The weapon entity to get the limit for.
* @return The grenade limit, -1 if an unhandled grenade entity was given.
*/
stock WeaponAmmoGetGrenadeLimit(WeaponAmmoGrenadeType:grenadetype)
{
switch(grenadetype)
{
case GrenadeType_HEGrenade:
{
// Attempt to find a cvar provided by an outside plugin.
new Handle:gplimit = FindConVar(GRENADE_PACK_CVAR_LIMIT);
// If Grenade Pack is loaded and the cvar was found, then get the value of the outside cvar, if not return CS:S default.
return (g_bGrenadePack && gplimit != INVALID_HANDLE) ? GetConVarInt(gplimit) : WEAPONAMMO_HEGRENADE_LIMIT;
}
case GrenadeType_Flashbang:
{
return WEAPONAMMO_FLASHBANG_LIMIT;
}
case GrenadeType_Smokegrenade:
{
return WEAPONAMMO_SMOKEGRENADE_LIMIT;
}
}
return -1;
}
/**
* Returns true if plugin "Grenade Pack" is found and running.
*/
stock bool:ZMarketIsGPLoaded()
{
new Handle:hPlugins = GetPluginIterator();
new Handle:hPlugin;
decl String:strPlugin[PLATFORM_MAX_PATH];
while (MorePlugins(hPlugins))
{
// Read the next plugin.
hPlugin = ReadPlugin(hPlugins);
GetPluginFilename(hPlugin, strPlugin, sizeof(strPlugin));
if (!StrEqual(strPlugin, GRENADE_PACK_FILENAME, false))
{
continue;
}
// Plugin was found, now return true only if it is running.
return (GetPluginStatus(hPlugin) == Plugin_Running);
}
// Done iterating, close handle.
CloseHandle(hPlugins);
// Plugin wasn't found.
return false;
}

View File

@ -112,7 +112,7 @@ WeaponsInit()
WeaponsOnAllPluginsLoaded()
{
// Forward event to sub-modules.
ZMarketOnAllPluginsLoaded();
WeaponAmmoOnAllPluginsLoaded();
}
/**

View File

@ -34,18 +34,6 @@
* @endsection
*/
/**
* @section Defines for ZMarket grenade limits, supporting the Grenade Pack plugin.
*/
#define GRENADE_PACK_FILENAME "grenadepack.smx"
#define GRENADE_PACK_LIMIT "gp_limit"
#define GRENADE_CSS_LIMIT 1
/**
* Variable to store if Grenade Pack is loaded and running.
*/
new bool:g_bGrenadePack;
/**
* Variable to store buyzone offset value.
*/
@ -66,21 +54,6 @@ new Handle:g_hZMarketPurchaseCount[MAXPLAYERS + 1];
*/
new Handle:g_hZMarketAutoRebuyCookie = INVALID_HANDLE;
/**
* All plugins have finished loading.
*/
ZMarketOnAllPluginsLoaded()
{
// Check if "Grenade Pack" is loaded
g_bGrenadePack = ZMarketIsGPLoaded();
// DEBUG
if (g_bGrenadePack)
{
PrintToServer("GRENADE PACK IS LOADEDDD!!!!!!!!!");
}
}
/**
* Create commands specific to ZMarket.
*/
@ -850,17 +823,26 @@ stock bool:ZMarketEquip(client, const String:weapon[], bool:rebuy = false)
// If the slot is a projectile, then get information we need to compare later.
if (slot == Slot_Projectile)
{
// How many grenades does the client currently have?
new grenadecount = WeaponAmmoGetGrenadeCount(client, GrenadeType_HEGrenade);
// Get the grenade type the client is trying to buy.
new WeaponAmmoGrenadeType:grenadetype = WeaponAmmoEntityToGrenadeType(weaponentity);
// What is the current grenade limit?
new Handle:gplimit = FindConVar(GRENADE_PACK_LIMIT);
new grenadelimit = (gplimit != INVALID_HANDLE) ? GetConVarInt(gplimit) : GRENADE_CSS_LIMIT;
if (grenadetype == GrenadeType_Invalid)
{
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);
return false;
}
// How many grenades does the client currently have?
new grenadecount = WeaponAmmoGetGrenadeCount(client, grenadetype);
// How many grenades can the client hold?
new grenadelimit = WeaponAmmoGetGrenadeLimit(grenadetype);
// If client is at, or exceeds the grenade limit, then stop.
if (grenadecount >= grenadelimit)
{
// TRANSLATION HERE
// Client can't carry any more of this type of grenade.
TranslationPrintToChat(client, "Weapons zmarket grenade max", grenadelimit);
return false;
}
}
@ -1178,35 +1160,4 @@ stock bool:ZMarketIsClientInBuyZone(client)
{
// Return if client is in buyzone.
return bool:GetEntData(client, g_iToolsInBuyZone);
}
/**
* Returns true if plugin "Grenade Pack" is found and running.
*/
stock bool:ZMarketIsGPLoaded()
{
new Handle:hPlugins = GetPluginIterator();
new Handle:hPlugin;
decl String:strPlugin[PLATFORM_MAX_PATH];
while (MorePlugins(hPlugins))
{
// Read the next plugin.
hPlugin = ReadPlugin(hPlugins);
GetPluginFilename(hPlugin, strPlugin, sizeof(strPlugin));
if (!StrEqual(strPlugin, GRENADE_PACK_FILENAME, false))
{
continue;
}
// Plugin was found, now return true only if it is running.
return (GetPluginStatus(hPlugin) == Plugin_Running);
}
// Done iterating, close handle.
CloseHandle(hPlugins);
// Plugin wasn't found.
return false;
}