Skip to content

Instantly share code, notes, and snippets.

@na-stewart
Last active December 14, 2024 20:34
Show Gist options
  • Save na-stewart/1454d4390bcd7aa80eeef4a7afdfb1b6 to your computer and use it in GitHub Desktop.
Save na-stewart/1454d4390bcd7aa80eeef4a7afdfb1b6 to your computer and use it in GitHub Desktop.
Garry's Mod Pointshop2 patch that prevents an item on the ground from overriding loadout assignment.
-- pointshop2-master\lua\ps2\modules\weapons
hook.Add( "PlayerSpawn", "InitLoadoutConflictListener", function( ply )
ply.ps2LoadoutPrimaryAssigned = false;
ply.ps2LoadoutSecondaryAssigned = false;
end )
hook.Add( "PlayerCanPickupWeapon", "LoadoutConflictListener", function( ply, weapon )
-- Prevent pickup until player inventory is loaded.
if not ply.PS2_Inventory then return false end
-- Cancel listener if player is spectating or a SpecDM ghost.
if ply:GetObserverMode() > 0 or ( ply.IsGhost and ply:IsGhost() ) then return end
local ps2Primary = ply:PS2_GetItemInSlot( "Primary" )
local ps2Secondary = ply:PS2_GetItemInSlot( "Secondary" )
if weapon.Kind == 3 then
-- Cancel listener if primary is already assigned.
if ply.ps2LoadoutPrimaryAssigned then
return
-- Check if primary slot is empty or if weapon pickup is the same as the primary.
elseif not ps2Primary or ps2Primary.weaponClass == weapon:GetClass() then
ply.ps2LoadoutPrimaryAssigned = true;
end
return ply.ps2LoadoutPrimaryAssigned;
end
if weapon.Kind == 2 then
-- Cancel listener if secondary is already assigned.
if ply.ps2LoadoutSecondaryAssigned then
return
-- Check if secondary slot is empty or if weapon pickup is the same as the secondary.
elseif not ps2Secondary or ps2Secondary.weaponClass == weapon:GetClass() then
ply.ps2LoadoutSecondaryAssigned = true;
end
return ply.ps2LoadoutSecondaryAssigned;
end
end )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment