epi: Get max ammo size from info editor

This commit is contained in:
Jackzie 2021-05-18 18:55:25 -05:00
parent 59e2aac5ed
commit 0b4e398749
No known key found for this signature in database
GPG key ID: 1E834FE36520537A
2 changed files with 33 additions and 7 deletions

Binary file not shown.

View file

@ -34,6 +34,7 @@
#include <sdktools> #include <sdktools>
#include <sdkhooks> #include <sdkhooks>
#include <left4dhooks> #include <left4dhooks>
#include <l4d_info_editor>
#include <jutils> #include <jutils>
#define L4D2_WEPUPGFLAG_NONE (0 << 0) #define L4D2_WEPUPGFLAG_NONE (0 << 0)
@ -60,6 +61,8 @@ static bool isCheckpointReached, isLateLoaded, firstGiven, isFailureRound;
static ArrayList ammoPacks; static ArrayList ammoPacks;
static int g_iAmmoTable; static int g_iAmmoTable;
static StringMap weaponMaxClipSizes;
#define CABINET_ITEM_BLOCKS 4 #define CABINET_ITEM_BLOCKS 4
enum struct Cabinet { enum struct Cabinet {
int id; int id;
@ -79,6 +82,7 @@ public void OnPluginStart() {
SetFailState("This plugin is for L4D2 only."); SetFailState("This plugin is for L4D2 only.");
} }
weaponMaxClipSizes = new StringMap();
ammoPacks = new ArrayList(2); //<int entityID, ArrayList clients> ammoPacks = new ArrayList(2); //<int entityID, ArrayList clients>
HookEvent("player_spawn", Event_PlayerSpawn); HookEvent("player_spawn", Event_PlayerSpawn);
@ -164,6 +168,15 @@ public Action Command_RunExtraItems(int client, int args) {
/// EVENTS /// EVENTS
//////////////////////////////////// ////////////////////////////////////
public void OnGetWeaponsInfo(int pThis, const char[] classname) {
char clipsize[8];
InfoEditor_GetString(pThis, "clip_size", clipsize, sizeof(clipsize));
int maxClipSize = StringToInt(clipsize);
if(maxClipSize > 0)
weaponMaxClipSizes.SetValue(classname, maxClipSize);
}
//Called on the first spawn in a mission. //Called on the first spawn in a mission.
public Action Event_GameStart(Event event, const char[] name, bool dontBroadcast) { public Action Event_GameStart(Event event, const char[] name, bool dontBroadcast) {
firstGiven = false; firstGiven = false;
@ -195,6 +208,17 @@ public Action Event_PlayerFirstSpawn(Event event, const char[] name, bool dontBr
} }
} }
public Action L4D_OnMobRushStart() {
PrintToChatAll("MOB RUSH");
}
public Action L4D_OnIsTeamFull(int team, bool &full) {
if(team == 2 && full) {
full = false;
return Plugin_Continue;
}
}
public void Frame_GiveNewClientKit(int client) { public void Frame_GiveNewClientKit(int client) {
if(!DoesClientHaveKit(client) && GetRealSurvivorsCount() > 4) { if(!DoesClientHaveKit(client) && GetRealSurvivorsCount() > 4) {
int item = GivePlayerItem(client, "weapon_first_aid_kit"); int item = GivePlayerItem(client, "weapon_first_aid_kit");
@ -419,7 +443,7 @@ public Action OnUpgradePackUse(int entity, int activator, int caller, UseType ty
} }
char classname[32]; char classname[32];
int upgradeBits = GetEntProp(primaryWeapon, Prop_Send, "m_upgradeBitVec"), ammo = 10; int upgradeBits = GetEntProp(primaryWeapon, Prop_Send, "m_upgradeBitVec"), ammo;
//Get the new flag bits //Get the new flag bits
GetEntityClassname(entity, classname, sizeof(classname)); GetEntityClassname(entity, classname, sizeof(classname));
@ -428,12 +452,14 @@ public Action OnUpgradePackUse(int entity, int activator, int caller, UseType ty
if(upgradeBits & L4D2_WEPUPGFLAG_LASER == L4D2_WEPUPGFLAG_LASER) newFlags |= L4D2_WEPUPGFLAG_LASER; if(upgradeBits & L4D2_WEPUPGFLAG_LASER == L4D2_WEPUPGFLAG_LASER) newFlags |= L4D2_WEPUPGFLAG_LASER;
SetEntProp(primaryWeapon, Prop_Send, "m_upgradeBitVec", newFlags); SetEntProp(primaryWeapon, Prop_Send, "m_upgradeBitVec", newFlags);
GetEntityClassname(primaryWeapon, classname, sizeof(classname)); if(!weaponMaxClipSizes.GetValue(classname, ammo)) {
if(StrEqual(classname, "weapon_grenade_launcher", true)) ammo = 1; GetEntityClassname(primaryWeapon, classname, sizeof(classname));
else if(StrEqual(classname, "weapon_rifle_m60", true)) ammo = 150; if(StrEqual(classname, "weapon_grenade_launcher", true)) ammo = 1;
else { else if(StrEqual(classname, "weapon_rifle_m60", true)) ammo = 150;
int currentAmmo = GetEntProp(primaryWeapon, Prop_Send, "m_iClip1"); else {
if(currentAmmo > ammo) ammo = currentAmmo; int currentAmmo = GetEntProp(primaryWeapon, Prop_Send, "m_iClip1");
if(currentAmmo > 10) ammo = 10;
}
} }
SetEntProp(primaryWeapon, Prop_Send, "m_nUpgradedPrimaryAmmoLoaded", ammo); SetEntProp(primaryWeapon, Prop_Send, "m_nUpgradedPrimaryAmmoLoaded", ammo);