AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   [L4D2] Grenade Counter (https://forums.alliedmods.net/showthread.php?t=340208)

AsphyxiaJLSA 11-02-2022 13:58

[L4D2] Grenade Counter
 
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

HarryPotter 11-03-2022 01:33

Re: [L4D2] Grenade Counter
 
Is possible, count+1 when player throws grenade.
And block action in OnPlayerRunCmd when limit reached

`666 11-03-2022 16:01

Re: [L4D2] Grenade Counter
 
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;



Marttt 11-03-2022 18:02

Re: [L4D2] Grenade Counter
 
I believe there is no "grenade_thrown" event in L4D2

`666 11-03-2022 18:25

Re: [L4D2] Grenade Counter
 
Damn, looks like it.

alasfourom 11-03-2022 23:30

Re: [L4D2] Grenade Counter
 
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);



NoroHime 11-04-2022 14:42

Re: [L4D2] Grenade Counter
 
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


All times are GMT -4. The time now is 14:21.

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