How to make a player stop sprinting while reloading?
7 replies, posted
Hi, I was just wondering, how does one make a player stop sprinting while they're reloading your custom weapon? Is this possible, and if so, how do I do this?
[url]http://wiki.garrysmod.com/page/WEAPON/Reload[/url]
[url]http://wiki.garrysmod.com/page/Player/Lock[/url]
[url]http://wiki.garrysmod.com/page/Player/UnLock[/url]
Use a timer
Well, I want them to be able to move, just not sprint. (Or at least just stop sprinting when reloading starts).
KeyPress hook with if key == IN_RELOAD set sprint speed to same as run speed then a timer to set it back
In CreateMove or SetupMove? you could also check
Player:GetActiveWeapon( )
Weapon.NextReload > CurTime( )
If so, remove sprint off the keys pressed.
In your reload function make sure you set the time: self.Weapon.NextReload = CurTime( ) + self.Weapon:SequenceDuration( )
I liked your idea so much, I coded it. Pretty straight forward. This is done client-side.
[lua]//
// Disable Sprinting While Reloading - Josh 'Acecool' Moser
//
hook.Add( "CreateMove", "AcecoolWeaponBase:HandleNotSprintingWhileReloading", function( input )
local _weapon = LocalPlayer( ):GetActiveWeapon( );
if ( IsValid( _weapon ) ) then
if ( ( _weapon.NextReload or 0 ) > CurTime( ) ) then
local _buttons = input:GetButtons();
if input:KeyDown( IN_SPEED ) then _buttons = _buttons - IN_SPEED; end
input:SetButtons( _buttons )
end
end
end )[/lua]
If this is an essential thing in your gamemode, you probably should consider doing it not clientside. All I have to do is remove that hook and now I can sprint while reloading and give myself an advantage over other players.
Thanks guys. I'll try this out next week when I have the chance. Or on the weekend.
You should be able to call it server-side too, but with client-side it prevents having the server do the logic, but as Sasha points out integral parts of the game-mode should be server-side to prevent cheating.
Sorry, you need to Log In to post a reply to this thread.