• CUserCmd:SetButtons(2) not working?
    9 replies, posted
I was trying to simulate primary attack for all weapons, but I think SetButtons isn't working (at least not on the server). Could anyone tell me if my code is wrong? Thanks in advance. [code]hook.Add("Move", "MoveTest", function(ply) ply:GetCurrentCommand():SetButtons(2) end)[/code]
What exactly are you trying to do?
Simulate a weapon shot on a bot, but the code doesn't work for players either.
It doesn't work for some SWEPs which require you to hold the button for a while, I already tried that :frown:
[QUOTE=GranPC;19800406]It doesn't work for some SWEPs which require you to hold the button for a while, I already tried that :frown:[/QUOTE] Oh it's true. I tested that together with him.
SetButtons works just fine for me. The following code just quickly taps the attack key. [lua] local attack = false; /*------------------------------------ CreateMove() ------------------------------------*/ local function CreateMove( cmd ) attack = !attack; if( attack ) then cmd:SetButtons( cmd:GetButtons() | IN_ATTACK ); end end hook.Add( "CreateMove", "AttackCreateMove", CreateMove ); [/lua] Also, don't use magic numbers. Use IN_ATTACK instead of the value it represents. Because if you come back to your code in the future you won't know what it does, nor will other people looking at your code. Also, 2 is IN_JUMP not IN_ATTACK.
Hopefully that will work.
[QUOTE=Jinto;19813282]SetButtons works just fine for me. The following code just quickly taps the attack key. [lua] local attack = false; /*------------------------------------ CreateMove() ------------------------------------*/ local function CreateMove( cmd ) attack = !attack; if( attack ) then cmd:SetButtons( cmd:GetButtons() | IN_ATTACK ); end end hook.Add( "CreateMove", "AttackCreateMove", CreateMove ); [/lua] Also, don't use magic numbers. Use IN_ATTACK instead of the value it represents. Because if you come back to your code in the future you won't know what it does, nor will other people looking at your code. [/QUOTE] Is there any way to do that serverside? I doubt I can run Lua on bots. [QUOTE=Jinto]Also, 2 is IN_JUMP not IN_ATTACK.[/QUOTE] Oops :downs:
Sorry, you need to Log In to post a reply to this thread.