• Stop shooting
    14 replies, posted
currently using the hook GM/KeyPress to see whether someone is currently shooting using the function checking if v:KeyDown( IN_ATTACK ) is there a way to then deny that command from the key press like returning false or something? if not how can i achieve the ability to negate someones attack.
WEAPON/CanPrimaryAttack return false here
If you want this for all weapons and not just one specifically, remove the key in GM/StartCommand
so use that hook and then create a function containing if ( con:KeyDown( IN_ATTACK ) then return false end
hook.Add("StartCommand","no_shooting",function(ply,CUserCmd) if true then--replace true with what ever conditional statement you want to check for CUserCmd:RemoveKey(IN_ATTACK)--default mouse 2 CUserCmd:RemoveKey(IN_ATTACK2)--defualt mouse 1 CUserCmd:RemoveKey(IN_RELOAD)--reload key end end) i think that you can only listen in on stuff using this hook, to modify stuff you need to call CUserCmd/RemoveKey
No, just remove the key from the usercmd. For example: local not_IN_ATTACK = bit.bnot(IN_ATTACK) hook.Add("StartCommand", "RemoveAttackKey", function(pPlayer, cmd) cmd:SetButtons(bit.band(cmd:GetButtons(), not_IN_ATTACK)) end)
okay then thanks guys i am never any good with hooks
Hi again, after applying your code to my item the principle works but has some strange outcomes. Any ideas how to solve this issue? https://youtu.be/GRM06K-Lh8o
code needs to be in a shared environment
*looks at it, looks at it, looks at it,* *sees next post,* did you put it in a serverside only environment?
I might have done that, whats the best way to share it with client? Networking Net Library Usage? or something else.
no, it needs to be in a shared environment
so if i take the function out of the if SERVER then section and put it on its own or do i add its to if CLIENT as well. or something completely differemt. and could you explain why this is the issue cause it would be helpful to know whats gone wrong for the future.
Just don't do any realm checks - just put it outright in a shared file so you only have to write the code once. That will work - SWEPs are ran shared.
Sorry, you need to Log In to post a reply to this thread.