-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
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 ) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, StyledStrike's addon uses a timer.Simple()
https://github.com/StyledStrike/gmod-custom-loadout/blob/master/lua/custom_loadout/sv_main.lua#L93
local wep = ply:GetActiveWeapon() | ||
|
||
if IsValid( wep ) then | ||
spawnProtectionWeaponChangeCheck( ply, nil, wep ) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
I've changed two things on recent commits to address this:
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 ) |
No description provided.