Skip to content

Commit

Permalink
Check applied status for medical items
Browse files Browse the repository at this point in the history
  • Loading branch information
dysphie committed May 31, 2023
1 parent 2c2ab83 commit b1ec711
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
plugins/
*.zip
*.zip
.vscode
28 changes: 21 additions & 7 deletions scripting/nmrih-backpack2.sp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#define PLUGIN_PREFIX "[Backpack2] "
#define PLUGIN_DESCRIPTION "Portable inventory boxes"
#define PLUGIN_VERSION "2.0.15"
#define PLUGIN_VERSION "2.0.16"

#define INVALID_USER_ID 0

Expand Down Expand Up @@ -506,27 +506,36 @@ enum struct Backpack
return false;
}

void AddWeaponByEnt(int weapon)
bool AddWeaponByEnt(int weapon)
{
if (IsValidEntity(this.wearerRef))
{
LogError("Tried to add weapon (%d) to carried backpack", weapon);
return;
return false;
}

Item reg;
if (!GetItemByEntity(weapon, reg)) {
return;
return false;
}

// Ignore medical items that have been consumed
if (IsItemConsumed(weapon)) {
return false;
}

int ammoAmt = GetEntProp(weapon, Prop_Send, "m_iClip1");

char targetname[MAX_TARGETNAME];
GetEntityTargetname(weapon, targetname, sizeof(targetname));

if (this.AddWeapon(ammoAmt, reg, _, targetname)) {
if (this.AddWeapon(ammoAmt, reg, _, targetname))
{
RemoveEntity(weapon);
return true;
}

return false;
}

void AddAmmoByEnt(int ammoBox, bool suppressSound = false, bool allowStacking = true)
Expand Down Expand Up @@ -1469,9 +1478,8 @@ void OnWeaponFallThink(int weaponRef)
{
Backpack bp;
int bpID = GetBackpackFromEntity(bpEnt, bp);
if (bpID != -1)
if (bpID != -1 && bp.AddWeaponByEnt(weapon))
{
bp.AddWeaponByEnt(weapon);
backpacks.SetArray(bpID, bp);
}
}
Expand Down Expand Up @@ -2423,4 +2431,10 @@ void InitializeHints()
{
delete hintUpdateTimer;
hintUpdateTimer = CreateTimer(cvHintsInterval.FloatValue, Timer_UpdateHints, _, TIMER_REPEAT);
}

bool IsItemConsumed(int item)
{
return HasEntProp(item, Prop_Send, "_applied") &&
GetEntProp(item, Prop_Send, "_applied") != 0;
}

0 comments on commit b1ec711

Please sign in to comment.