Good Little Panda
|
08-28-2009
, 00:16
Re: RemovePlayerItem for specific grenade?
|
#5
|
Thanks, that makes a bit more sense. Here's what I have so far. I just tested the plugin, it doesn't seem to set the player's grenade value to 0.
PHP Code:
#pragma semicolon 1
#include <sourcemod> #include <cstrike> #include <sdktools> #include <colors>
#define SLOT_HEGRENADE 11 #define SLOT_FBGRENADE 12 #define SLOT_SMGRENADE 13
public Plugin:myinfo = { name = "{HoM} Anti Nade Spam", author = "Panda", description = "Nade spam protection for {HoM} servers.", version = "1.0", url = "www.heirsofmortality.com" }
enum GrenadeData { numHE, numSG, numFB };
new p_Clients[MAXPLAYERS+1][GrenadeData]; new g_iToolsAmmo;
new Handle:p_Enabled; new Handle:p_TotalGrenade; new Handle:p_TotalSmoke; new Handle:p_TotalFlash;
public OnPluginStart() { g_iToolsAmmo = FindSendPropInfo("CBasePlayer", "m_iAmmo"); if (g_iToolsAmmo == -1) { SetFailState("Offset \"CBasePlayer::m_iAmmo\" was not found."); } p_Enabled = CreateConVar("sm_nadespam_enable", "1", "Determines whether or not Anti-Nade-Spam protection is active."); p_TotalGrenade = CreateConVar("sm_nadespam_numHE", "1", "The number of High-Explosive Grenades players are allowed to use in total."); p_TotalSmoke = CreateConVar("sm_nadespam_numSG", "1", "The number of Flash Bangs players are allowed to use."); p_TotalFlash = CreateConVar("sm_nadespam_numFB", "0", "The number of Smoke Grenades players are allowed to use."); AutoExecConfig(true); HookEvent("player_spawn", OnPlayerSpawn); HookEvent("item_pickup", OnItemPickup); }
public Action:OnItemPickup(Handle:event, const String:name[], bool:dontBroadcast) { if(GetConVarInt(p_Enabled) == 1) { decl String:p_tempWeapon[64]; GetEventString(event, "item", p_tempWeapon, sizeof(p_tempWeapon)); if(strcmp(p_tempWeapon, "hegrenade") == 0) { new p_Client = GetClientOfUserId(GetEventInt(event,"userid"));
if(GetConVarInt(p_TotalGrenade) > 0) { if(p_Clients[p_Client][numHE] >= GetConVarInt(p_TotalGrenade)) { if(GetConVarInt(p_TotalGrenade) == 1) CPrintToChat(p_Client, "{lightgreen}{HoM}: {default}You are only allowed to use %d HE Grenade per round!", GetConVarInt(p_TotalGrenade)); else CPrintToChat(p_Client, "{lightgreen}{HoM}: {default}You are only allowed to use %d HE Grenades per round!", GetConVarInt(p_TotalGrenade));
WeaponAmmoSetGrenadeCount(p_Client, SLOT_HEGRENADE, 0, false); return Plugin_Handled; } else { ++p_Clients[p_Client][numHE]; return Plugin_Continue; } } else { WeaponAmmoSetGrenadeCount(p_Client, SLOT_HEGRENADE, 0, false); return Plugin_Handled; } } if(strcmp(p_tempWeapon, "smokegrenade") == 0) { new p_Client = GetClientOfUserId(GetEventInt(event,"userid")); if(GetConVarInt(p_TotalSmoke) > 0) { if(p_Clients[p_Client][numSG] >= GetConVarInt(p_TotalSmoke)) { if(GetConVarInt(p_TotalSmoke) == 1) CPrintToChat(p_Client, "{lightgreen}{HoM}: {default}You are only allowed to use %d Smoke Grenade per round!", GetConVarInt(p_TotalSmoke)); else CPrintToChat(p_Client, "{lightgreen}{HoM}: {default}You are only allowed to use %d Smoke Grenades per round!", GetConVarInt(p_TotalSmoke)); WeaponAmmoSetGrenadeCount(p_Client, SLOT_SMGRENADE, 0, false); return Plugin_Handled; } else { ++p_Clients[p_Client][numSG]; return Plugin_Continue; } } else { WeaponAmmoSetGrenadeCount(p_Client, SLOT_SMGRENADE, 0, false); return Plugin_Handled; } } if(strcmp(p_tempWeapon,"flashbang") == 0) { new p_Client = GetClientOfUserId(GetEventInt(event,"userid")); if(GetConVarInt(p_TotalFlash) > 0) { if(p_Clients[p_Client][numFB] >= GetConVarInt(p_TotalFlash)) { if(GetConVarInt(p_TotalFlash) == 1) CPrintToChat(p_Client, "{lightgreen}{HoM}: {default}You are only allowed to use %d Flash Bang per round!", GetConVarInt(p_TotalFlash)); else CPrintToChat(p_Client, "{lightgreen}{HoM}: {default}You are only allowed to use %d Flash Bangs per round!", GetConVarInt(p_TotalFlash)); WeaponAmmoSetGrenadeCount(p_Client, SLOT_FBGRENADE, 0, false); return Plugin_Handled; } else { ++p_Clients[p_Client][numFB]; return Plugin_Continue; } } else { WeaponAmmoSetGrenadeCount(p_Client, SLOT_FBGRENADE, 0, false); return Plugin_Handled; } } } return Plugin_Continue; }
public OnPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast) { if(GetConVarInt(p_Enabled) == 1) { new p_Client = GetClientOfUserId(GetEventInt(event,"userid")); p_Clients[p_Client][numHE] = 0; p_Clients[p_Client][numSG] = 0; p_Clients[p_Client][numFB] = 0; } }
/** Credits to Greyscale * Set the count of any grenade-type a client has. * * @param client The client index. * @param slot The type of * @param value The amount of ammo to set to. * @param add (Optional) If true, the value is added to the grenades' current ammo count. */ stock WeaponAmmoSetGrenadeCount(client, any:type, value, bool:add) { // Initialize variable (value is 0) new ammovalue; // If we are adding, then update variable with current ammo value. if (add) { ammovalue = WeaponAmmoGetGrenadeCount(client, type); } SetEntData(client, g_iToolsAmmo + (type * 4), ammovalue + value, _, true); }
/** Credits to Greyscale * Get the count of any grenade-type a client has. * * @param client The client index. * @param slot The type of */ stock WeaponAmmoGetGrenadeCount(client, any:type) { return GetEntData(client, g_iToolsAmmo + (type * 4)); }
|
|