Raised This Month: $51 Target: $400
 12% 

[L4D2] Grenade Counter


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AsphyxiaJLSA
Member
Join Date: Oct 2021
Location: Lima,Perú
Old 11-02-2022 , 13:58   [L4D2] Grenade Counter
Reply With Quote #1

Hello everyone, I am not sure if this plugin exists or it is possible to do it, I am looking for a plugin that makes the client have a limit of throwing grenades per map, that is, each client can throw a grenade 2 or 3 times per map and restarts again at the end of this map or when losing a map.

I don't know if it exists or if it is possible to create it, I hope your help
__________________
→MY STEAM PROFILE←

DISCORD: Asphyxia#9797

Sorry for my bad English
AsphyxiaJLSA is offline
HarryPotter
Veteran Member
Join Date: Sep 2017
Location: Taiwan, Asia
Old 11-03-2022 , 01:33   Re: [L4D2] Grenade Counter
Reply With Quote #2

Is possible, count+1 when player throws grenade.
And block action in OnPlayerRunCmd when limit reached
__________________
HarryPotter is offline
`666
AlliedModders Donor
Join Date: Jan 2006
Old 11-03-2022 , 16:01   Re: [L4D2] Grenade Counter
Reply With Quote #3

If limit reached entity will be deleted on throw. Change limit to what ever you want @ g_iLimit
Count reset on round start or if client re-joins. I only tested in insurgency.

PHP Code:
#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>

public Plugin myinfo =
{
    
name "grenade_limit",
    
author "",
    
description "",
    
version "1.0",
    
url ""
};

int    ga_iCount[MAXPLAYERS 1] = {0, ...},
    
g_iLimit 2;

public 
void OnPluginStart() {
    
HookEvent("grenade_thrown"Event_GrenadeThrownEventHookMode_Pre);
    
HookEvent("round_start"Event_RoundStart);
}

public 
void OnClientPostAdminCheck(int client) {
    if (!
IsFakeClient(client)) {
        
ga_iCount[client] = 0;
    }
}

public 
Action Event_RoundStart(Event event, const char[] namebool dontBroadcast) {
    for (
int i 1<= MaxClientsi++) {
        if (
IsClientInGame(i) && !IsFakeClient(i)) {
            
ga_iCount[i] = 0;
        }
    }
    return 
Plugin_Continue;
}

public 
Action Event_GrenadeThrown(Event eventchar[] namebool dontBroadcast) {
    
int client GetClientOfUserId(event.GetInt("userid"));
    if (
ga_iCount[client] >= g_iLimit) {
        
int iNade event.GetInt("entityid");
        if (
iNade && IsValidEntity(iNade)) {
            
RemoveEntity(iNade);
            
PrintToChat(client"\x07cc3300You have reached the grenade throw limit: \x070088cc%d\x01"g_iLimit);
        }
        return 
Plugin_Continue;
    }
    
ga_iCount[client]++;
    return 
Plugin_Continue;

`666 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 11-03-2022 , 18:02   Re: [L4D2] Grenade Counter
Reply With Quote #4

I believe there is no "grenade_thrown" event in L4D2
__________________
Marttt is offline
`666
AlliedModders Donor
Join Date: Jan 2006
Old 11-03-2022 , 18:25   Re: [L4D2] Grenade Counter
Reply With Quote #5

Damn, looks like it.
`666 is offline
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 11-03-2022 , 23:30   Re: [L4D2] Grenade Counter
Reply With Quote #6

I made something before to limit the use for defibrillators, I just converted it to be for throwers.

PHP Code:
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>

#pragma semicolon 1
#pragma newdecls required
#define PLUGIN_VERSION "1.0"

int g_iThrower_Counter[MAXPLAYERS+1];

ConVar g_Cvar_PluginEnable;
ConVar g_Cvar_ThrowCounter;

public 
Plugin myinfo =
{
    
name "L4D2 Thrower Limiter",
    
author "alasfourom",
    
description "Set A Limit For Thrower Items",
    
version PLUGIN_VERSION,
    
url "https://forums.alliedmods.net/showthread.php?t=340208"
};

public 
void OnPluginStart()
{
    
CreateConVar ("l4d2_thrower_limiter_version"PLUGIN_VERSION"L4D2 Thrower Limiter"FCVAR_SPONLY FCVAR_NOTIFY FCVAR_DONTRECORD);
    
g_Cvar_PluginEnable CreateConVar("l4d2_thrower_limit_enable""1""Enable L4D2 Thrower Limiter Plugin"FCVAR_NOTIFYtrue0.0true1.0);
    
g_Cvar_ThrowCounter CreateConVar("l4d2_thrower_limit_count""3""Set The Maximum Times Allowed To Use Thrower Items"FCVAR_NOTIFY);
    
AutoExecConfig(true"L4D2_Thrower_Limiter");
    
    
HookEvent("round_start"Event_RoundStart);
    
HookEvent("weapon_fire"Event_WeaponFire);
    
HookEvent("item_pickup"Event_ItemPick);
    
HookEvent("weapon_given"Event_ItemPick);
}

public 
void OnMapStart()
{
    for (
int i 1<= MaxClientsi++) g_iThrower_Counter[i] = GetConVarInt(g_Cvar_ThrowCounter);
}

public 
void Event_RoundStart(Event event, const char[] namebool dontBroadcast)
{
    
OnMapStart();
}

void Event_WeaponFire(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    if (!
client || !IsClientInGame(client) || !IsPlayerAlive(client) || GetClientTeam(client) != || !GetConVarBool(g_Cvar_PluginEnable)) return;
    
    
char sWeapon[32];
    
GetClientWeapon(clientsWeaponsizeof(sWeapon));
    
    if (
StrEqual(sWeapon"weapon_molotov") || StrEqual(sWeapon"weapon_vomitjar") || StrEqual(sWeapon"weapon_pipe_bomb"))
    {
        -- 
g_iThrower_Counter[client];
        if (
g_iThrower_Counter[client] > 0PrintToChat(client"\x04[Thrower Limiter] \x01You have \x05%d \x01more throwers to use before it fails."g_iThrower_Counter[client]);    
        else 
PrintToChat(client"\x04[Thrower Limiter] \x01You have reached the throwers \x05limit\x01.");
    }
}

void Event_ItemPick(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    if (!
client || !IsClientInGame(client) || !IsPlayerAlive(client) || GetClientTeam(client) != || !GetConVarBool(g_Cvar_PluginEnable)) return;

    
int iThrower GetPlayerWeaponSlot(client2);
    if (
g_iThrower_Counter[client] < 1)
        if (
IsValidEdict(iThrower)) SDKHooks_DropWeapon(clientiThrower);

__________________

Last edited by alasfourom; 11-06-2022 at 14:58.
alasfourom is offline
NoroHime
Veteran Member
Join Date: Aug 2016
Location: bed
Old 11-04-2022 , 14:42   Re: [L4D2] Grenade Counter
Reply With Quote #7

I think don't aggressive behavior needed here, just make player can't switch weapon to throwable at this round, also more compatible with "pipe bomb shove" etc
__________________

Last edited by NoroHime; 11-04-2022 at 14:45.
NoroHime is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:59.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode