CSGO BHop (w/ strafe) AHK Script (That I made)

Post gaming related scripts
wboycher
Posts: 6
Joined: 20 May 2018, 21:24

CSGO BHop (w/ strafe) AHK Script (That I made)

Post by wboycher » 20 May 2018, 21:32

Middle Button (press on scroll wheel) to bhop.
To adjust the speed and length of each strafe, look for the following block of text in the code:

moveCount := 25
sleepInterval := 2
relativeMove := 28


Adjust these variables to get different results until you find your favorite config. Or, if the existing config is good enough for you, do not edit any other pieces of code.
If you do, it may break the script. Please note that this is only for testing purposes and that I am not responsible for any server bans or VAC bans (VAC is unlikely).
Don't forget to give me feedback. It helps me improve.

Code: Select all

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance ignore
#NoEnv
SendMode, Input
SetBatchLines -1
CoordMode, Mouse, Screen
F6::Suspend
Home::Reload
jump()
{                                    
Send, {Space}
}
mouseXY(x, y)
{
DllCall("mouse_event",uint,1,int,x,int,y,uint,0,int,0)
}

strafe(left)
{
moveCount := 25
sleepInterval := 2
relativeMove := 28
if (left)
{
key := "d"
move := relativeMove
} else
{
key := "a"
move := -relativeMove
}
send {%key% down}
DllCall("Sleep", "UInt", 5)
Loop, %moveCount%
{
mouseXY(move, -(move/4))
DllCall("Sleep", "UInt", sleepInterval)
}
send {%key% up}
}
$mbutton::
while getkeystate("mbutton","P")
{
jump()
strafe(true)
strafe(false)
}

Return
Rangerbot
Posts: 34
Joined: 02 Mar 2018, 10:33

Re: CSGO BHop (w/ strafe) AHK Script (That I made)

Post by Rangerbot » 27 May 2018, 10:02

Dam bud! you got a pretty fine script here. My first piece of advice is to indent your code. It not only helps us reading it but also yourself one day maybe. I tidied it up for myself to read and am nowhere near imposing a format on you. Your use of DLL calls is exquisite in keeping the script smooth as butter, TBH it is one of the finest-tuned scripts in the gaming forum I have seen so far. I'm curious about you calling the DLL for thread Sleep as opposed to using the [Sleep, T] command already in AHK. You also had a few #preprocess commands that were mixed in with process commands at the top and you duplicated a few of them, not sure it affects the code here but it is always safest to keep them in order in the auto-run section. I can't try the code below, but also to help me - let me know if it runs the same as yours so I know if I'm being an @$$ about the auto-run portion.

Code: Select all

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance ignore

CoordMode, Mouse, Screen
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetBatchLines -1

	;Settings
	moveCount := 25
	sleepInterval := 2
	relativeMove := 28

F6::Suspend
Home::Reload

jump() {                                    
	Send, {Space}
}

mouseXY(x, y) {
	DllCall("mouse_event",uint,1,int,x,int,y,uint,0,int,0)
}

strafe(left) {
	
	if (left) {
		key := "d"
		move := relativeMove
	} else {
		key := "a"
		move := -relativeMove
	}

	send {%key% down}
	DllCall("Sleep", "UInt", 5)
	
	Loop, %moveCount% {
		mouseXY(move, -(move/4))
		DllCall("Sleep", "UInt", sleepInterval)
	}

	send {%key% up}
}

$mbutton::
	while getkeystate("mbutton","P") {
		jump()
		strafe(true)
		strafe(false)
	}
Return
:beer: :thumbup: all in all impeccable code and thank you for joining in the forum and sharing!
swagfag
Posts: 1217
Joined: 11 Jan 2017, 17:59

Re: CSGO BHop (w/ strafe) AHK Script (That I made)

Post by swagfag » 27 May 2018, 12:43

Code: Select all

	;Settings
	moveCount := 25
	sleepInterval := 2
	relativeMove := 28
by moving these variables outside the scope of the function, they are no longer accessible. You'd need to either declare your function global, make the variables super-global, pass them as arguments or declare them global within the function scope. As is the script likely isnt doing much in terms of moving the mouse.

heres what id change in the original script:

Code: Select all

#NoEnv
; #Warn
SendMode Input
SetWorkingDir %A_ScriptDir%
#SingleInstance ignore
#NoEnv
SendMode, Input
SetBatchLines -1
CoordMode, Mouse, Screen ; this doesnt affect 'mouse_event', if u put it with that in mind 
F6::Suspend
Home::Reload
jump()
{                                    
Send, {Space}
}
mouseXY(x, y)
{
DllCall("mouse_event",uint,1,int,x,int,y,uint,0,int,0)
}

strafe(left) ; rather than a flag, id pass the key directly and check if its 'a/d' or not
{
moveCount := 25 ; these should propbably be 'static', if youre gonna leave them here
sleepInterval := 2 ; these should propbably be 'static', if youre gonna leave them here
relativeMove := 28 ; these should propbably be 'static', if youre gonna leave them here

; "if strife left is true, start pressing 'd' and moving the mouse in the right direction"
; wouldnt that result in effectively you strafing 'right'?? 
; idk how it works in csgo, but id imagine turning and moving right, makes you strafe right, no?
; poor naming, if thats the case
if (left)
{
key := "d" ; no need for this assignment, if passed as argument
move := relativeMove
} else
{
key := "a"
move := -relativeMove
}
send {%key% down}
DllCall("Sleep", "UInt", 5) ; cant imagine that playing any significant part, likely superfluous
Loop, %moveCount%
{
mouseXY(move, -(move/4)) ; why is touching the y-axis required?
DllCall("Sleep", "UInt", sleepInterval)
}
send {%key% up}
}
$mbutton::
while getkeystate("mbutton","P")
{
jump()
strafe(true) ; poor naming, resulting from the function signature. is strafe(true) equivalent to "start strafing"?
strafe(false) ; one would likely assume so, but wouldnt know for sure without digging into the function definition
}

Return
heres how id rewrite it, taking both scripts into consideration:

Code: Select all

#NoEnv
#SingleInstance Ignore
SendMode Input
SetBatchLines -1

moveCount := 25
sleepInterval := 2
relativeMove := 28

F6::Suspend
Home::Reload
*MButton::
while(GetKeyState("MButton","P"))
{
	jump()
	strafe("d")
	strafe("a")
}
Return

strafe(key) {
	global moveCount, sleepInterval, relativeMove

	Send {%key% Down}
	sleep(5)

	x := (key == "d") ? relativeMove : -relativeMove
	y := -(x/4) ; why does there have to be movement on the y-axis??

	Loop % moveCount
	{
		mouseMove(x, y)
		sleep(sleepInterval)
	}

	Send {%key% Up}
}

jump() {
	Send {Space}
}

mouseMove(x, y) {
	DllCall("mouse_event", "UInt", 1, "Int", x, "Int", y, "UInt", 0, "Int", 0)
}

sleep(duration) {
	DllCall("Sleep", "UInt", duration)
}

Rangerbot
Posts: 34
Joined: 02 Mar 2018, 10:33

Re: CSGO BHop (w/ strafe) AHK Script (That I made)

Post by Rangerbot » 27 May 2018, 17:08

aH yes thanks swag, I've been doing too many subs and forget about function scope in autohotkey
I am also curious about the y-axis mouse movement

http://flafla2.github.io/2015/02/14/bunnyhop.html
wboycher
Posts: 6
Joined: 20 May 2018, 21:24

Re: CSGO BHop (w/ strafe) AHK Script (That I made)

Post by wboycher » 02 Jun 2018, 18:37

Sorry for not replying, I havent been on here for a while. Thank you all for the compliments and feedback. I will improve the script and post the improved version.
wboycher
Posts: 6
Joined: 20 May 2018, 21:24

Re: CSGO BHop (w/ strafe) AHK Script (That I made)

Post by wboycher » 02 Jun 2018, 19:17

Code: Select all

#Warn

SetWorkingDir %A_ScriptDir%

#SingleInstance ignore

#NoEnv

SendMode, Input

SetBatchLines -1

F6::Suspend

Home::Reload

jump()

{                                    
	Send, {Space}
}

mouseXY(x, y)

{

	DllCall("mouse_event",uint,1,int,x,int,y,uint,0,int,0)
	
}

strafe(left)

{
	moveCount := 25
	
	sleepInterval := 2
	
	relativeMove := 28
	
	if (left)
	
{

	key := "d"
	
	move := relativeMove
	
} else

{

	key := "a"
	
	move := -relativeMove
	
}

	send {%key% down}
	
	DllCall("Sleep", "UInt", 5)
	
	Loop, %moveCount%
	
{

	mouseXY(move, -(move/4))
	
	DllCall("Sleep", "UInt", sleepInterval)
	
}

	send {%key% up}
	
}

	$mbutton::
	
	while getkeystate("mbutton","P")
	
{

	jump()
	
	strafe(true)
	
	strafe(false)
	
}

Return
This is the improved code. It runs the same but now it is more readable
wboycher
Posts: 6
Joined: 20 May 2018, 21:24

Re: CSGO BHop (w/ strafe) AHK Script (That I made)

Post by wboycher » 02 Jun 2018, 19:59

Go to https://github.com/BinaryDoge/CSGO-bhop-AHK to edit my script if it has anymore problems
Post Reply

Return to “Gaming”