Skip to content

Commit

Permalink
Add convar to limit max dropped weapons in map (#114)
Browse files Browse the repository at this point in the history
* Add convar to limit max dropped weapons in map

* Set default value to -1
  • Loading branch information
FortyTwoFortyTwo authored Aug 6, 2023
1 parent a805231 commit 3b3f330
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions addons/sourcemod/scripting/scp_sf.sp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ ConVar CvarKarmaRatio;
ConVar CvarKarmaMin;
ConVar CvarKarmaMax;
ConVar CvarAllowCosmetics;
ConVar CvarDroppedWeaponCount;
float NextHintAt = FAR_FUTURE;
float RoundStartAt;
float EndRoundIn;
Expand Down
1 change: 1 addition & 0 deletions addons/sourcemod/scripting/scp_sf/convars.sp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void ConVar_Setup()
CvarKarmaMin = CreateConVar("scp_karmamin", "0.0", "Minimum karma level", _, true, 0.0, true, 100.0);
CvarKarmaMax = CreateConVar("scp_karmamax", "100.0", "Maximum karma level", _, true, 0.0, true, 100.0);
CvarAllowCosmetics = CreateConVar("scp_allowcosmetics", "1", "Whether to allow certain classes to equip cosmetics", _, true, 0.0, true, 1.0);
CvarDroppedWeaponCount = CreateConVar("scp_droppedweaponcount", "-1", "How many dropped weapon to allow in map, -1 for no limit", _, true, -1.0);

AutoExecConfig(true, "SCPSecretFortress");

Expand Down
27 changes: 27 additions & 0 deletions addons/sourcemod/scripting/scp_sf/items.sp
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,33 @@ bool Items_DropItem(int client, int helditem, const float origin[3], const float

TeleportEntity(entity, origin, NULL_VECTOR, vel);
result = true;

// Add dropped weapon to list, ordered by time created
static ArrayList droppedweapons;
if (!droppedweapons)
droppedweapons = new ArrayList();

droppedweapons.Push(EntIndexToEntRef(entity));
int length = droppedweapons.Length;
for (int i = length - 1; i >= 0; i--)
{
// Clean up any ents that were already removed
if (!IsValidEntity(droppedweapons.Get(i)))
droppedweapons.Erase(i);
}

int maxcount = CvarDroppedWeaponCount.IntValue;
if (maxcount != -1)
{
// If there are too many dropped weapon, remove some ordered by time created
length = droppedweapons.Length;
while (length > maxcount)
{
RemoveEntity(droppedweapons.Get(0));
droppedweapons.Erase(0);
length--;
}
}
}
}

Expand Down

0 comments on commit 3b3f330

Please sign in to comment.