Need to find a hook for when player pushes right-click or shift
10 replies, posted
I'm looking to rewrite my scripts, and one of the things that needs rewriting is the fact that player speed changes happen completely within the weapons as part of functions on the Weapon Think hook. Yeah, it's bizarre and that's why I'm changing all that.
Anyway, I've been looking around and can't find the hook I'm looking for. I'd greatly appreciate the help!
PlayerBindPress could work with +attack2 and +sprint ( not sure if sprint is that, sorry if I'm wrong )
It depends what you're trying to accomplish and when it is supposed to happen. Based on the title, you could use a GM hook, or if it is limited to the weapon you could use SecondaryAttack for the right click, and shift could be checked more ways than just by checking a key. You can check to see if the player speed is more than the walking speed with shift, or without it.... I do a few specific things for my weapons: [code]if ( ( self.Owner:KeyDown( IN_SPEED ) && self.Owner:GetVelocity( ):Length( ) > self.Owner:GetWalkSpeed( ) ) || self.Owner:IsAgainstWall( ) ) then[/code]
Basically make it not able to fire, and on the ViewModel system I have it lower the weapon. I use Secondary Attack to convert from lowered to aiming down hip / sights ( taken over by think logic that fires once per change by using a toggle var ), and again secondary attack to check for double-clicks to put the weapon into passive / normal mode.
There are many ways to create logic for something and it depends on whether it'll be weapon-base specific ( using SWEP functions ), game-mode specific ( injecting / rewriting meta-table functions, using hooks, etc... ), etc...
To adjust speed, you could do it in CreateMove / SetupMove before the move happens ( and have it rely on any number of things such as weapon-type, hold-type, etc... )...
Can you tell us anything more specific about what you're trying to do?
[QUOTE=HumbleTH;45556989]PlayerBindPress could work with +attack2 and +sprint ( not sure if sprint is that, sorry if I'm wrong )[/QUOTE]
Sprint is +speed
[QUOTE=TeddyHunter;45560179]Sprint is +speed[/QUOTE]I think +sprint works as well though.
You can see what bind/cmd was used, and look up the key that was used to press it. It is +speed, I haven't seen it as +sprint yet. "bind "SHIFT" "+speed""
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/open_vgui_based_on_keypress.lua.html[/url]
[QUOTE=Acecool;45560296]You can see what bind/cmd was used, and look up the key that was used to press it. It is +speed, I haven't seen it as +sprint yet. "bind "SHIFT" "+speed""
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/open_vgui_based_on_keypress.lua.html[/url][/QUOTE]TTT uses +sprint for something, just double checked then.
[QUOTE=ShadowRanger;45560361]TTT uses +sprint for something, just double checked then.[/QUOTE]
Good find...
[quote] gamemodes\terrortown\gamemode\cl_keys.lua (1 hit)
Line 39: elseif bind == "+sprint" then[/quote]
[code] elseif bind == "+sprint" then
-- set voice type here just in case shift is no longer down when the
-- PlayerStartVoice hook runs, which might be the case when switching to
-- steam overlay
ply.traitor_gvoice = false
RunConsoleCommand("tvog", "0")
return true[/code]
But it uses this here at the bottom of the same file:
[code]-- Note that for some reason KeyPress and KeyRelease are called multiple times
-- for the same key event in multiplayer.
function GM:KeyPress(ply, key)
if not IsFirstTimePredicted() then return end
if not IsValid(ply) or ply != LocalPlayer() then return end
if key == IN_SPEED and ply:IsActiveTraitor() then
timer.Simple(0.05, function() RunConsoleCommand("+voicerecord") end)
end
end
function GM:KeyRelease(ply, key)
if not IsFirstTimePredicted() then return end
if not IsValid(ply) or ply != LocalPlayer() then return end
if key == IN_SPEED and ply:IsActiveTraitor() then
timer.Simple(0.05, function() RunConsoleCommand("-voicerecord") end)
end
end[/code]
and this in cl_voice:
[code]function GM:PlayerStartVoice( ply )
****
RunConsoleCommand("tvog", "1")
****
RunConsoleCommand("tvog", "0")
****
[/code]
+sprint isn't a recognized bind though so it must be left over from debugging or something... The logic for traitor voice is done elsewhere, and that bind shouldn't ever be ran ( unless someone binds +sprint to a key and sets up alias +sprint and alias -sprint )
I'll double check; but the code doesn't seem to do anything necessary to the functionality of the traitor chat as those use IN_SPEED.. so there may be a pull-request to remove that code sometime soon ( if something else in the file needs to be edited, or if it messes with anything ). Good find though.
Uhh I see, didn't look at the rest, sorry. But at least you cleared it up for us.
I basically want the player to move at different speeds when holding shift or right-click, and I want them to have restrictions. (i.e. the player is forced to the slowest speed when holding right-click and cannot sprint). I also want to include a weight variable in my SWEP base table called "weight" that will further influence the player's speeds.
It can be done one of many ways. In my stamina script, I have it dynamically change the max-speed. In another stamina script, I have it dynamically alter the speed the player moves in Create/SetupMove hook.
Both work and are both really smooth.
Sorry, you need to Log In to post a reply to this thread.