Limit legacy loadout to missing weapons
This commit is contained in:
+59
-4
@@ -87,23 +87,78 @@ function GM:IsSpawnpointSuitable(ply, spawnpointent, bMakeSuitable)
|
||||
end
|
||||
|
||||
local hl2dmLoadout
|
||||
local automaticLoadout
|
||||
local BuildAutomaticLoadout
|
||||
local ammoWeaponPairs = {
|
||||
{ weapon = "weapon_pistol", ammo = { "item_ammo_pistol", "item_ammo_pistol_large" } },
|
||||
{ weapon = "weapon_smg1", ammo = { "item_ammo_smg1", "item_ammo_smg1_large", "item_ammo_smg1_grenade" } },
|
||||
{ weapon = "weapon_357", ammo = { "item_ammo_357", "item_ammo_357_large" } },
|
||||
{ weapon = "weapon_ar2", ammo = { "item_ammo_ar2", "item_ammo_ar2_large", "item_ammo_ar2_altfire" } },
|
||||
{ weapon = "weapon_shotgun", ammo = { "item_box_buckshot" } },
|
||||
{ weapon = "weapon_crossbow", ammo = { "item_ammo_crossbow" } },
|
||||
{ weapon = "weapon_rpg", ammo = { "item_rpg_round" } }
|
||||
}
|
||||
|
||||
if SERVER then
|
||||
hl2dmLoadout = CreateConVar(
|
||||
"gc_hl2dmloadout",
|
||||
"1",
|
||||
FCVAR_ARCHIVE,
|
||||
"Give the standard HL2 Deathmatch spawn weapons expected by legacy coop maps"
|
||||
"Legacy map loadout: 0 off, 1 supply weapons missing for placed ammo, 2 full HL2DM loadout"
|
||||
)
|
||||
|
||||
local function MapProvidesWeapon(className)
|
||||
if #ents.FindByClass(className) > 0 then return true end
|
||||
|
||||
for _, equip in ipairs(ents.FindByClass("game_player_equip")) do
|
||||
local weaponNames = equip:GetSaveTable().m_weaponNames or {}
|
||||
for _, equippedClass in pairs(weaponNames) do
|
||||
if string.lower(tostring(equippedClass)) == className then return true end
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
BuildAutomaticLoadout = function()
|
||||
automaticLoadout = {}
|
||||
|
||||
for _, pair in ipairs(ammoWeaponPairs) do
|
||||
local hasAmmoPickup = false
|
||||
for _, ammoClass in ipairs(pair.ammo) do
|
||||
if #ents.FindByClass(ammoClass) > 0 then
|
||||
hasAmmoPickup = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if hasAmmoPickup and not MapProvidesWeapon(pair.weapon) then
|
||||
automaticLoadout[#automaticLoadout + 1] = pair.weapon
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
hook.Add("InitPostEntity", "CustomCoopDetectMissingAmmoWeapons", BuildAutomaticLoadout)
|
||||
end
|
||||
|
||||
function GM:PlayerLoadout(ply)
|
||||
if striponspawn then return end
|
||||
|
||||
ply:Give("weapon_fists")
|
||||
if not hl2dmLoadout or not hl2dmLoadout:GetBool() then return end
|
||||
local loadoutMode = hl2dmLoadout and hl2dmLoadout:GetInt() or 0
|
||||
if loadoutMode <= 0 then return end
|
||||
|
||||
-- Legacy HL2DM coop maps commonly place ammo for these weapons but rely on
|
||||
-- CHL2MP_Player::GiveDefaultItems to supply the weapons themselves.
|
||||
if loadoutMode == 1 then
|
||||
-- InitPostEntity normally prepares this before anybody spawns. The
|
||||
-- fallback also covers script auto-refresh during a running map.
|
||||
if not automaticLoadout and BuildAutomaticLoadout then BuildAutomaticLoadout() end
|
||||
for _, weaponClass in ipairs(automaticLoadout or {}) do
|
||||
ply:Give(weaponClass)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
-- Forced compatibility mode mirrors CHL2MP_Player::GiveDefaultItems.
|
||||
ply:Give("weapon_crowbar")
|
||||
ply:Give("weapon_pistol")
|
||||
ply:Give("weapon_smg1")
|
||||
|
||||
Reference in New Issue
Block a user