AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   L4D2 - Back 4 Blood card feature - Auto Reload (https://forums.alliedmods.net/showthread.php?t=335836)

Sev 01-07-2022 16:12

L4D2 - Back 4 Blood card feature - Auto Reload
 
There is a card you can use in Back 4 Blood that alllows you to auto reload a weapon that's NOT equipped in your hands. For example, if your primary weapon is half full, then you switch to your melee weapon or secondary weapon, the primary weapon (or secondary) will auto reload.

I think it would be neat if this card feature could be brought over to this game.

Bacardi 01-07-2022 16:47

Re: L4D2 - Back 4 Blood card feature - Auto Reload
 

Bacardi 01-08-2022 02:03

Re: L4D2 - Back 4 Blood card feature - Auto Reload
 
sorry for double post...


Here some kind experiment.
I have not test much.
- Doesn't reload when cvar ammo_*_max set to 0 or less
Unless cvar ammo_*_max is set to -2, which is unlimited ammo (pistols by default)
- Autoreload happens 3 seconds after player stop switching items/weapons. Otherwise timer reset.
- There is chat output as well, remove them from code if you not like it.

PHP Code:

// L4D2
// Autoreload unequipped weapon
// Back 4 Blood - Admin Reload card

enum {
    
AMMO_TYPE_NONE = -1,
    
AMMO_TYPE_UNKNOWN0 0,
    
AMMO_TYPE_PISTOL,
    
AMMO_TYPE_PISTOL_MAGNUM,
    
AMMO_TYPE_ASSAULTRIFLE,
    
AMMO_TYPE_UNKNOWN4,
    
AMMO_TYPE_SMG 5,
    
AMMO_TYPE_M60,
    
AMMO_TYPE_SHOTGUN,
    
AMMO_TYPE_AUTOSHOTGUN,
    
AMMO_TYPE_HUNTINGRIFLE,
    
AMMO_TYPE_SNIPERRIFLE 10,
    
AMMO_TYPE_UNKNOWN11,
    
AMMO_TYPE_PIPEBOMB,
    
AMMO_TYPE_MOLOTOV,
    
AMMO_TYPE_VOMITJAR,
    
AMMO_TYPE_PAINPILLS 15,
    
AMMO_TYPE_FIRSTAID,
    
AMMO_TYPE_GRENADELAUNCHER,
    
AMMO_TYPE_ADRENALINE,
    
AMMO_TYPE_CHAINSAW,
    
AMMO_CARRIED_ITEM 20,
    
AMMO_CARRIED_MAX
}



Handle player_timers[MAXPLAYERS];
KeyValues kv;



#include <sdkhooks>

public void OnPluginStart()
{
    for(
int i 1<= MaxClientsi++)
    {
        if(
IsClientInGame(i)) OnClientPutInServer(i);
    }
}

public 
void OnConfigsExecuted()
{
    
KvSetUpWeapons(kv);
    
//kv.ExportToFile("kvtest.txt");
}

public 
void OnClientPutInServer(int client)
{
    if(!
IsFakeClient(client))
        
SDKHook(clientSDKHook_WeaponSwitchPostWeaponSwitchPost);
}

public 
void WeaponSwitchPost(int clientint weapon)
{
    if(
player_timers[client] != null)
        
delete player_timers[client];

    
DataPack pack;
    
player_timers[client] = CreateDataTimer(3.0delaypack);

    
pack.WriteCell(client);
    
pack.WriteCell(GetClientUserId(client));
    
pack.Reset();
}

public 
Action delay(Handle timerDataPack pack)
{
    
int client pack.ReadCell();
    
player_timers[client] = null;

    
int userid pack.ReadCell();
    
client GetClientOfUserId(userid);

    if(
client == || !IsClientInGame(client) || !IsPlayerAlive(client))
        return 
Plugin_Continue;

    
int active_weapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
    
int arraysize GetEntPropArraySize(clientProp_Send"m_hMyWeapons");

    
int m_hMyWeapon = -1;
    
int m_iPrimaryAmmoType = -1;

    
int m_iClip1 0xFF;    // weapon clip
    
int clip_sizefillclip 0;    // weapon max clip and fill clip

    
int m_iAmmo 0;    // client ammo
    
int ammo 0;        // cvar max ammo

    
char clsname[30];
    
char kvstring[65];

    for(
int x 0arraysizex++)
    {
        
m_hMyWeapon GetEntPropEnt(clientProp_Send"m_hMyWeapons"x);

        
// empty slot or same weapon
        
if(m_hMyWeapon == -|| m_hMyWeapon == active_weapon) continue;

        
// entity missing propertie
        
if(!HasEntProp(m_hMyWeaponProp_Send"m_iPrimaryAmmoType")) continue;

        
// entity missing this propertie
        
if(!HasEntProp(m_hMyWeaponProp_Send"m_isDualWielding")) continue;

        
m_iPrimaryAmmoType GetEntProp(m_hMyWeaponProp_Send"m_iPrimaryAmmoType");

        
// no ammo type
        
if(m_iPrimaryAmmoType == -1) continue;

        
m_iClip1 GetEntProp(m_hMyWeaponProp_Send"m_iClip1");

        
// clip out of range... is weapon/item/grenade without ammo
        
if(m_iClip1 == -|| m_iClip1 == 0xFF) continue;

        
m_iAmmo GetEntProp(clientProp_Send"m_iAmmo"_m_iPrimaryAmmoType);

        
GetEntityClassname(m_hMyWeaponclsnamesizeof(clsname));
        
Format(kvstringsizeof(kvstring),"%s/clip_size"clsname);
        
clip_size kv.GetNum(kvstring0);

        
Format(kvstringsizeof(kvstring),"%s/ammo"clsname);
        
ammo kv.GetNum(kvstring0);

        if(
GetEntProp(m_hMyWeaponProp_Send"m_isDualWielding"))
        {
            
clip_size clip_size 2;
        }

        
// weapon clip is not full
        
if(m_iClip1 clip_size)
        {
            
// cvar have max ammo and player have ammo
            
if(ammo && m_iAmmo 0)
            {
                
fillclip clip_size m_iClip1;
                
                if(
fillclip <= m_iAmmo)
                {
                    
SetEntProp(m_hMyWeaponProp_Send"m_iClip1"m_iClip1 fillclip);
                    
SetEntProp(clientProp_Send"m_iAmmo"m_iAmmo fillclip_m_iPrimaryAmmoType);
                    
PrintToChat(client"[SM] Auto reloaded %s clip +%i / ammo %i"clsnamefillclipm_iAmmo fillclip);
                }
                else
                {
                    
SetEntProp(m_hMyWeaponProp_Send"m_iClip1"m_iClip1 m_iAmmo);
                    
SetEntProp(clientProp_Send"m_iAmmo"0_m_iPrimaryAmmoType);
                    
PrintToChat(client"[SM] Auto reloaded %s clip +%i / ammo %i"clsnamem_iAmmom_iAmmo fillclip);
                }
            }
            else if(
ammo == -2// cvar ammo max value -2 is unlimited ammo
            
{
                
SetEntProp(m_hMyWeaponProp_Send"m_iClip1"clip_size);
                
PrintToChat(client"[SM] Auto reloaded %s clip %i"clsnameclip_size);
            }
        }
    }

    return 
Plugin_Continue;
}


KvSetUpWeapons(KeyValues &kvweapons)
{
    if(
kvweapons != null)
        
delete kvweapons;

    
kvweapons = new KeyValues("weapons");

    
// Manually write weapon default clip size...
    
kvweapons.SetString("weapon_autoshotgun/clip_size""10");
    
kvweapons.SetString("weapon_grenade_launcher/clip_size""1");
    
kvweapons.SetString("weapon_hunting_rifle/clip_size""15");
    
kvweapons.SetString("weapon_pistol/clip_size""15");
    
kvweapons.SetString("weapon_pistol_magnum/clip_size""8");
    
kvweapons.SetString("weapon_pumpshotgun/clip_size""8");
    
kvweapons.SetString("Weapon_rifle/clip_size""50");
    
kvweapons.SetString("Weapon_rifle_ak47/clip_size""40");
    
kvweapons.SetString("weapon_rifle_desert/clip_size""60");
    
kvweapons.SetString("weapon_rifle_m60/clip_size""150");
    
kvweapons.SetString("weapon_rifle_sg552/clip_size""50");
    
kvweapons.SetString("weapon_shotgun_chrome/clip_size""8");
    
kvweapons.SetString("weapon_shotgun_spas/clip_size""10");
    
kvweapons.SetString("weapon_smg/clip_size""50");
    
kvweapons.SetString("weapon_smg_mp5/clip_size""50");
    
kvweapons.SetString("weapon_smg_silenced/clip_size""50");
    
kvweapons.SetString("weapon_sniper_awp/clip_size""20");
    
kvweapons.SetString("weapon_sniper_military/clip_size""30");
    
kvweapons.SetString("weapon_sniper_scout/clip_size""15");

/*
cvar
ammo_grenadelauncher_max 30
ammo_assaultrifle_max 360
ammo_huntingrifle_max 150
ammo_minigun_max 800
ammo_autoshotgun_max 90
ammo_sniperrifle_max 180
ammo_m60_max 0
ammo_smg_max 650
ammo_shotgun_max 56
ammo_pistol_max -2
*/


    
ConVar cvar FindConVar("ammo_autoshotgun_max");
    
int ammo 0;

    if(
cvar != null)
        
ammo cvar.IntValue;

    
kvweapons.SetNum("weapon_autoshotgun/ammo"ammo);
    
kvweapons.SetNum("weapon_shotgun_spas/ammo"ammo);


    
cvar FindConVar("ammo_grenadelauncher_max");
    
ammo 0;

    if(
cvar != null)
        
ammo cvar.IntValue;

    
kvweapons.SetNum("weapon_grenade_launcher/ammo"ammo);

    
cvar FindConVar("ammo_huntingrifle_max");
    
ammo 0;

    if(
cvar != null)
        
ammo cvar.IntValue;

    
kvweapons.SetNum("weapon_hunting_rifle/ammo"ammo);

    
cvar FindConVar("ammo_pistol_max");
    
ammo 0;

    if(
cvar != null)
        
ammo cvar.IntValue;

    
kvweapons.SetNum("weapon_pistol/ammo"ammo);
    
kvweapons.SetNum("weapon_pistol_magnum/ammo"ammo);

    
cvar FindConVar("ammo_shotgun_max");
    
ammo 0;

    if(
cvar != null)
        
ammo cvar.IntValue;

    
kvweapons.SetNum("weapon_pumpshotgun/ammo"ammo);
    
kvweapons.SetNum("weapon_shotgun_chrome/ammo"ammo);

    
cvar FindConVar("ammo_assaultrifle_max");
    
ammo 0;

    if(
cvar != null)
        
ammo cvar.IntValue;

    
kvweapons.SetNum("Weapon_rifle/ammo"ammo);
    
kvweapons.SetNum("Weapon_rifle_ak47/ammo"ammo);
    
kvweapons.SetNum("weapon_rifle_desert/ammo"ammo);
    
kvweapons.SetNum("weapon_rifle_sg552/ammo"ammo);

    
cvar FindConVar("ammo_m60_max");
    
ammo 0;

    if(
cvar != null)
        
ammo cvar.IntValue;

    
kvweapons.SetNum("weapon_rifle_m60/ammo"ammo);

    
cvar FindConVar("ammo_smg_max");
    
ammo 0;

    if(
cvar != null)
        
ammo cvar.IntValue;

    
kvweapons.SetNum("weapon_smg/ammo"ammo);
    
kvweapons.SetNum("weapon_smg_mp5/ammo"ammo);
    
kvweapons.SetNum("weapon_smg_silenced/ammo"ammo);

    
cvar FindConVar("ammo_sniperrifle_max");
    
ammo 0;

    if(
cvar != null)
        
ammo cvar.IntValue;

    
kvweapons.SetNum("weapon_sniper_awp/ammo"ammo);
    
kvweapons.SetNum("weapon_sniper_military/ammo"ammo);
    
kvweapons.SetNum("weapon_sniper_scout/ammo"ammo);

    



Sev 01-08-2022 03:31

Re: L4D2 - Back 4 Blood card feature - Auto Reload
 
Works like a charm. Thanks!


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

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