Veteran Member
Join Date: Jan 2010
Location: mom's basement
|
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_AMMOTYPE, true);
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.0, repeat, 1, TIMER_REPEAT);
}
public Action repeat(Handle timer, any client)
{
if(!IsValidEntity(client)) return Plugin_Continue;
if(GetEntProp(client, Prop_Send, "deadflag"))
{
return Plugin_Continue;
}
int health = GetEntProp(client, Prop_Send, "m_iHealth");
if(health >= 1 && health < 100)
{
SetEntProp(client, Prop_Send, "m_iHealth", ++health);
}
int m_hActiveWeapon = GetEntPropEnt(client, Prop_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_hActiveWeapon, Prop_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_hActiveWeapon, max);
}
// grenade, rpg
if(max[clip] > 0)
{
SetEntProp(m_hActiveWeapon, Prop_Send, "m_iClip1", max[clip]);
}
if(max[primary] > 0)
{
SetEntProp(client, Prop_Send, "m_iAmmo", max[primary], _, m_iPrimaryAmmoType);
}
if(max[secondary] > 0)
{
int m_iSecondaryAmmoType = GetEntProp(m_hActiveWeapon, Prop_Send, "m_iSecondaryAmmoType");
SetEntProp(client, Prop_Send, "m_iAmmo", max[secondary], _, m_iSecondaryAmmoType);
}
return Plugin_Continue;
}
void Update(const int weapon, int[] max)
{
char classname[30];
GetEntityClassname(weapon, classname, sizeof(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(classname, false);
kv.Rewind();
return result;
}
int MaxClip(const char[] classname)
{
int result = -1;
if(kv.JumpToKey(classname, false))
{
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(classname, false))
{
kv.GetString(AmmoType, buffer, sizeof(buffer), "");
kv.Rewind();
}
if(kv.JumpToKey(SK_MAX_AMMOTYPE, false))
{
kv.GetString(buffer, buffer, sizeof(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(classname, true);
KeyValues temp = new KeyValues("data");
char weaponfile[64];
Format(weaponfile, sizeof(weaponfile), "scripts/%s.txt", classname);
int clip_size = -1;
char primary_ammo[20] = "None", secondary_ammo[20] = "None";
if(!FileExists(weaponfile, true, NULL_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_ammo, sizeof(primary_ammo), "None");
temp.GetString("secondary_ammo", secondary_ammo, sizeof(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
|
|