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

DELETE


Post New Thread Closed Thread   
 
Thread Tools Display Modes
Author Message
canadianjeff
BANNED
Join Date: Sep 2016
Old 05-02-2020 , 01:41   DELETE
#1

DELETE

Last edited by canadianjeff; 03-07-2022 at 02:30.
canadianjeff is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 05-05-2020 , 06:24   Re: [REQ] Infinite Ammo No Reload (Half-Life 2 Single Player)
#2

- This plugin use .../scripts/weapon_*.txt files

- If you want this to work in other HL2 episodes, you need copy weapon txt files from HL2 and paste another mod (episodic, ep2).
- You find also weapon txt files from inside VPK files. You copy and paste those files.

*updated - not need copy/paste files anymore.

PHP Code:


enum 
{
    
clip,
    
primary,
    
secondary
}

KeyValues kv;

#define SK_MAX_AMMOTYPE    "sk_max_ammotype"

public void OnPluginStart()
{
    
kv = new KeyValues("weapondata");
    
    
kv.JumpToKey(SK_MAX_AMMOTYPEtrue);
    
kv.SetString("AR2",                        "sk_max_ar2");
    
kv.SetString("AlyxGun",                    "sk_max_alyxgun");
    
kv.SetString("Pistol",                    "sk_max_pistol");
    
kv.SetString("SMG1",                    "sk_max_smg1");
    
kv.SetString("357",                        "sk_max_357");
    
kv.SetString("XBowBolt",                "sk_max_crossbow");
    
kv.SetString("Buckshot",                "sk_max_buckshot");
    
kv.SetString("RPG_Round",                "sk_max_rpg_round");
    
kv.SetString("SMG1_Grenade",            "sk_max_smg1_grenade");
    
kv.SetString("SniperRound",                "sk_max_sniper_round");
    
kv.SetString("SniperPenetratedRound",    "sk_max_sniper_round");
    
kv.SetString("Grenade",                    "sk_max_grenade");
    
kv.SetString("GaussEnergy",                "sk_max_gauss_round");
    
kv.SetString("HelicopterGun",            "sk_max_smg1");
    
kv.SetString("AR2AltFire",                "sk_max_ar2_altfire");
    
kv.SetString("Grenade",                    "sk_max_grenade");
    
kv.SetString("Hopwire",                    "sk_max_hopwire");
    
kv.Rewind();


    
CreateTimer(0.0repeat1TIMER_REPEAT);
}

public 
Action repeat(Handle timerany client)
{
    if(!
IsValidEntity(client)) return Plugin_Continue;

    if(
GetEntProp(clientProp_Send"deadflag"))
    {
        return 
Plugin_Continue;
    }

    
int health GetEntProp(clientProp_Send"m_iHealth");
    
    if(
health >= && health 100)
    {
        
SetEntProp(clientProp_Send"m_iHealth", ++health);
    }
    
    
int m_hActiveWeapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
    if(
m_hActiveWeapon == -1) return Plugin_Continue;


    
// if weapon have primary ammo type, then it must have also ammo to use ?
    
int m_iPrimaryAmmoType GetEntProp(m_hActiveWeaponProp_Send"m_iPrimaryAmmoType");

    if(
m_iPrimaryAmmoType <= 0) return Plugin_Continue;



    static 
int entity_ref = -1;
    static 
int max[] = {-1, -1, -1}; // clip_size, primary_ammo, secondary_ammo

    // Are we handling very same entity ?
    
int ref EntIndexToEntRef(m_hActiveWeapon);

    if(
entity_ref != ref)
    {
        
entity_ref ref;
        
// Update variables
        
max[clip] = -1;
        
max[primary] = -1;
        
max[secondary] = -1;
        
        
Update(m_hActiveWeaponmax);
        
    }


    
    
// grenade, rpg
    
if(max[clip] > 0)
    {
        
SetEntProp(m_hActiveWeaponProp_Send"m_iClip1"max[clip]);
    }

    if(
max[primary] > 0)
    {
        
SetEntProp(clientProp_Send"m_iAmmo"max[primary], _m_iPrimaryAmmoType);
    }


    if(
max[secondary] > 0)
    {
        
int m_iSecondaryAmmoType GetEntProp(m_hActiveWeaponProp_Send"m_iSecondaryAmmoType");        
        
SetEntProp(clientProp_Send"m_iAmmo"max[secondary], _m_iSecondaryAmmoType);
    }



    return 
Plugin_Continue;
}


void Update(const int weaponint[] max)
{
    
char classname[30];

    
GetEntityClassname(weaponclassnamesizeof(classname));

    
// Go top first.
    
kv.Rewind();

    if(
FoundWeapon(classname))
    {
        
max[clip] = MaxClip(classname);
        
max[primary] = MaxCarry(classname"primary_ammo");
        
max[secondary] = MaxCarry(classname"secondary_ammo");
    }
    else
    {
        
//Create new section
        
AddWeapon(classname);
        
        
max[clip] = MaxClip(classname);
        
max[primary] = MaxCarry(classname"primary_ammo");
        
max[secondary] = MaxCarry(classname"secondary_ammo");
    }
    
    
PrintToServer("Update \
                    %i %i %i"
,
                        
max[clip],
                        
max[primary],
                        
max[secondary]);
}




bool FoundWeapon(const char[] classname)
{
    
bool result kv.JumpToKey(classnamefalse);
    
kv.Rewind();
    return 
result;
}

int MaxClip(const char[] classname)
{
    
int result = -1;

    if(
kv.JumpToKey(classnamefalse))
    {
        
result kv.GetNum("clip_size", -1);
    }
    
kv.Rewind();

    return 
result;
}

int MaxCarry(const char[] classname, const char[] AmmoType)
{
    static 
ConVar cvar;
    
    
char buffer[30];

    if(
kv.JumpToKey(classnamefalse))
    {
        
kv.GetString(AmmoTypebuffersizeof(buffer), "");
        
kv.Rewind();
    }

    if(
kv.JumpToKey(SK_MAX_AMMOTYPEfalse))
    {
        
kv.GetString(bufferbuffersizeof(buffer), "");
        
kv.Rewind();
    }


    
//PrintToServer("convar buffer '%s'", buffer);



    
if(StrContains(buffer"sk_max_") != 0)
    {
        return -
1;
    }
    
    
cvar FindConVar(buffer);
    
    if(
cvar == null)
    {
        return -
1;
    }
    
    return 
cvar.IntValue;
}



void AddWeapon(const char[] classname)
{
    
// create new section
    
kv.JumpToKey(classnametrue);


    
KeyValues temp = new KeyValues("data");
    
char weaponfile[64];

    
Format(weaponfilesizeof(weaponfile), "scripts/%s.txt"classname);


    
int clip_size = -1;
    
char primary_ammo[20] = "None"secondary_ammo[20] = "None";


    if(!
FileExists(weaponfiletrueNULL_STRING))
    {
        
PrintToServer("NOOPE")
        
delete temp;

        
kv.SetNum("clip_size"clip_size);
        
kv.SetString("primary_ammo"primary_ammo);
        
kv.SetString("secondary_ammo"secondary_ammo);
        
kv.Rewind();

        return;
    }


    
temp.ImportFromFile(weaponfile);

    
clip_size temp.GetNum("clip_size", -1);
    
temp.GetString("primary_ammo"primary_ammosizeof(primary_ammo), "None");
    
temp.GetString("secondary_ammo"secondary_ammosizeof(secondary_ammo), "None");

    
delete temp;

    
//PrintToServer("%i %s %s", clip_size, primary_ammo, secondary_ammo);


    
    
kv.SetNum("clip_size"clip_size);
    
kv.SetString("primary_ammo"primary_ammo);
    
kv.SetString("secondary_ammo"secondary_ammo);
    
kv.Rewind();

__________________
Do not Private Message @me

Last edited by Bacardi; 05-05-2020 at 09:40. Reason: updated
Bacardi is offline
Closed Thread



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:45.


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