Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for delayed loadouts #42

Merged
merged 4 commits into from
Jul 5, 2024

Conversation

legokidlogan
Copy link
Member

No description provided.

@legokidlogan legokidlogan self-assigned this Jul 3, 2024
@legokidlogan
Copy link
Member Author

Fixes players immediately losing spawn protection when using StyledStrike's loadout addon.

-- Resume weapon checking on a player with a slight delay after they spawn, after loadout addons give their weapons
-- The expectation is for loadouts to prioritize holding the physgun at the end, making players not lose spawn protection
-- Note that some loadout addons (like StyledStrike's) use a 0.1s timer on PlayerLoadout to give weapons
hook.Add( "PlayerSpawn", "CFCspawnProtectionResumeCheckingWeapons", function( ply )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This arbitrary timer can be avoided, use PlayerSetModel it's called after PlayerLoadout which any loadout addon will use, https://github.com/Facepunch/garrysmod/blob/39867454ca05ffaa04d70e74a5aac6f0858a9272/garrysmod/gamemodes/base/gamemode/player.lua#L250

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local wep = ply:GetActiveWeapon()

if IsValid( wep ) then
spawnProtectionWeaponChangeCheck( ply, nil, wep )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wont this just remove the spawnprotection after 0.3s? whats the difference with before here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cfc_pvp ensures players start out holding a physgun, so they won't lose it unless they switch off intentionally.

Garry.s.Mod.x64.2024-07-03.11-16-36.mp4

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually no, turns out it's going to the physgun because I have it set as my preferred weapon in the loadout, which isn't a thing by default.
This might require a more complex solution or need some edits to StyledStrike's addon, like making it use the physgun as the preferred wep by default if none of the others are set as preferred.

@StyledStrike
Copy link

I've changed two things on recent commits to address this:

  • Physics Gun is the preferred weapon by default, if the player has not set one
  • Added the CLoadoutOverridePreferredWeapon hook, example:
hook.Add( "CLoadoutOverridePreferredWeapon", "OverridePreferredWeaponExample", function( ply, preferredClass )
    -- With godmode, prefer to use the Physics Gun
    if ply:HasGodMode() then
        return "weapon_physgun"
    end

    -- You can return false instead to disable the automatic selection of
    -- a preferred weapon, allowing you to do custom logic after a loadout is given
    ply:Give( "weapon_physgun" )
    ply:SelectWeapon( "weapon_physgun" )

    return false
end )

@legokidlogan legokidlogan requested a review from wrefgtzweve July 4, 2024 22:57
@legokidlogan legokidlogan merged commit 46980e0 into main Jul 5, 2024
1 check passed
@legokidlogan legokidlogan deleted the feature/account-for-delayed-loadouts branch July 5, 2024 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants