Quick Buy AHK script

General Discussion is for anything related to Blackstone not covered in the other forums.
Post Reply
Drow Arrow
Baron
Baron
Posts: 57
Joined: Sat Jun 12, 2021 9:19 am

Quick Buy AHK script

Post by Drow Arrow »

Hey Folks,

I recently remembered that there was an AHK script on here from a while back to make buying stuff from an store easier but AHK has since deprecated V1 and refined their language with V2 which is now their focus and I decided I'd write a similar script to the one provided by Catopillar, although mine will work slightly differently.

to use this you will need to have Autohotkey V2 installed. For now I'll just be providing the script which you can save into a text document and replace it's extension with .ahk

Script 1:
This is the first version that i successfully got working.

Code: Select all

#Requires AutoHotkey v2.0-rc.2
#Hotif WinActive("AHK_exe nwmain.exe")

Global DragDistance := 300

; Use Ctrl + F to quickly buy 10 of the item you are hovering the cursor over.
^f:: {
    MouseGetPos &StartX, &StartY
    Loop(10) { ; change the loop count to however many times you want it to make the purchase before stopping
        Click "Down Right"
        Sleep 220
        MouseMove StartX + DragDistance, StartY
        Click "Up Right"
        Sleep 220
        MouseMove StartX, StartY
        }
}
Script 2:
Version 2 of my quick buy script, functionally works just the same but I approached it in a more compact manner.

Code: Select all

#Requires AutoHotkey v2.0-rc.2
#Hotif WinActive("AHK_exe nwmain.exe")

Global DragDistance := 300

; Use Ctrl + F to quickly buy 10 of the item you are hovering the cursor over.
^f:: {
    MouseGetPos &StartX, &StartY
    Loop(10) { ; change the loop count to however many times you want it to make the purchase before stopping
        MouseClickDrag "right", StartX, StartY, StartX + DragDistance, StartY, 100
        Sleep 230
        MouseMove StartX, StartY
        }
}
Script 3: Quick Buy script with GUI
decided to add a GUI so the end user can easily change the hotkey used as well as the amount of times it will buy the item.

Code: Select all

#Requires Autohotkey v2
#SingleInstance Force
#NoTrayIcon
HotIfWinActive("ahk_exe nwmain.exe")

; INI file configuration
if FileExist("NWNHotkeys.ini"){
	QBHotkey := IniRead("NWNHotkeys.ini", "Hotkeys", "QBHotkey", "^f")
	QBLoop := IniRead("NWNHotkeys.ini", "Loops", "QBLoop")
	OpLevel := IniRead("NWNHotkeys.ini", "Options", "Opacity")
	AOTCheck := IniRead("NWNHotkeys.ini", "Options", "AlwaysOnTop", 0)
}
else {
	IniWrite "^f", "NWNHotkeys.ini", "Hotkeys", "QBHotkey"
	IniWrite 10, "NWNHotkeys.ini", "Loops", "QBLoop"
	IniWrite 255, "NWNHotkeys.ini", "Options", "Opacity"
	IniWrite 0, "NWNHotkeys.ini", "Options", "AlwaysOnTop"
	QBHotkey := IniRead("NWNHotkeys.ini", "Hotkeys", "QBHotkey", "^f")
	QBLoop := IniRead("NWNHotkeys.ini", "Loops", "QBLoop", 10)
	OpLevel := IniRead("NWNHotkeys.ini", "Options", "Opacity", 255)
	AOTCheck := IniRead("NWNHotkeys.ini", "Options", "AlwaysOnTop", 0)
}

{
	myGui := Constructor()
	myGui.Show("w300 h200")
}

Constructor()
{
	Global QBHotkey
	myGui := Gui()
	Tab := myGui.Add("Tab3", "x0 y0 w303 h210", ["Neverwinter Nights", "Options"])
	Tab.UseTab(1)
	myGui.AddHotkey("vQuickBuy Limit1 x8 y32 w120 h21", QBHotkey) ; "vQuickBuy": used to assign a variable name for the hotkey which can be called later on with gui.submit | "QBHotkey": A variable that holds the key combination for the hotkey which is defined as a Global variable at the top of the script
	myGui.Add("Text", "x136 y32 w120 h23 +0x200", "Quick Buy")
	UpdBtn1 := myGui.Add("Button", "x200 y32 w80 h21", "Update")
	myGui.AddEdit("vQBEdit Number x8 y64 w120 h21", QBLoop)
	myGui.Add("Text", "x136 y64 w120 h23 +0x200", "Buy Count")
	UpdBtn2 := myGui.Add("Button", "x200 y64 w80 h21", "Update")
	Tab.UseTab(2)
	AOT := myGui.AddCheckbox("vcb_aot x200 y180 Checked" AOTCheck, "Always on top?")
	Opacity := myGui.AddSlider("AltSubmit Center NoTicks ToolTipTop range100-255 x8 y55 w120 h21", OpLevel)
	myGui.Add("Text", "x30 y32 w120 h23 +0x200", "Transparency")
	Tab.UseTab()
	UpdBtn1.OnEvent("Click", UpdateHotkey) ; Calls the UpdateHotkey function when the update button is clicked.
	UpdBtn2.OnEvent("Click", UpdateLoop)
	AOT.OnEvent("Click", AlwaysOnTop)
	Opacity.OnEvent("Change", Op_Adjust)
	myGui.OnEvent('Close', ExitProcedure)
	myGui.Title := "NWNHotkeys"
	
	return myGui
}

;Startup Variables Read
WinWait("NWNHotkeys")
	WinSetTransparent(OpLevel)

	AOT_Startup := myGui.Submit(0).cb_aot
	if (AOT_Startup = 1)
		WinSetAlwaysOnTop 1
	else
		WinSetAlwaysOnTop 0

;Hotkey Update Function

UpdateHotkey(*) {
	Global QBHotkey
	QBHK := myGui.Submit(0).Quickbuy ; Grabs the updated hotkey from the hotkey gui box
	; assigns the updated Hotkey value from the gui to the QBHK variable

	ChangeHotkey(QBHK) {
		Hotkey(QBHotkey, QB, 'Off') ; Disables Hotkey
		QBHotkey := QBHK ; Updates the QBHotkey variable with the Hotkey value from the QBHK variable
		Hotkey(QBHotkey, QB) ; Enables hotkey with the newly assigned Hotkey combination
		IniWrite QBHotkey, "NWNHotkeys.ini", "Hotkeys", "QBHotkey"
	}

	if (QBHK != "") {
		ChangeHotkey(QBHK)
		ToolTip("Hotkey changed!")
		Sleep 1000
		ToolTip() ; Clear the tooltip
	}
}

;Buy Count Update Function

UpdateLoop(*) {
	Global QBLoop
	LoopCount := myGui.Submit(0).QBEdit ;grabs the value from the Buy Count GUI box and assigned it to the LoopCount variable 
	 ;assigns the updated buy count from the gui to the new loop variable

	ChangeLoop(LoopCount){
		QBLoop := LoopCount ; assigns the updated buy count to the QBLoop variable
		IniWrite QBLoop, "NWNHotkeys.ini", "Loops", "QBLoop" ;writes the new value of the QBLoop variable to the configuration file
	}

	if (LoopCount !=""){
		ChangeLoop(LoopCount)
		ToolTip("Buy Count Changed!")
		sleep 1000
		ToolTip()
	}
}

;Function for "ALways on Top?"" Checkbox

AlwaysOnTop(AOT, info){
	if (aot.Value = 1)
		WinSetAlwaysOnTop 1, "A"
	else
		WinSetAlwaysOnTop 0, "A"
}

Op_Adjust(Opacity, *){
	WinSetTransparent(Opacity.value)
	IniWrite(Opacity.value, "NWNHotkeys.ini", "Options", "Opacity")
}

Global DragDistance := 300

;Hotkeys

Hotkey(QBHotkey, QB)

; Quickbuy Function

QB(*) {
	MouseGetPos &StartX, &StartY
	Loop(QBLoop) { ; change the loop count to however many times you want it to make the purchase before stopping
		MouseClickDrag "right", StartX, StartY, StartX + DragDistance, StartY
		sleep 285 ; Edit the sleep time (milliseconds) to change how quick it makes each purchase
		}
	MouseMove StartX, StartY
}

ExitProcedure(AOTCheck){
	AOTCheck := mygui.Submit(0).cb_aot
	IniWrite(AOTCheck, "NWNHotkeys.ini", "Options", "AlwaysOnTop")
	ExitApp()
}

HotIf
ImageImage

Basic use is as follows:
  1. Put your cursor on the item you want to buy multiple of.
  2. Hold Ctrl and press the F key (Ctrl + F)
Known Issues:
  • None
To-Do List:
  • Figure out how to allow the GUI version to remember hotkey and loop changes between instances
    (This may take a while, especially if it means rewriting large parts of the script)
    was easier than I thought.
Last edited by Drow Arrow on Wed Sep 18, 2024 6:14 am, edited 16 times in total.
Active Characters:
Ragos Meadsmith
Efiel Meadsmith
Ezekial Meadsmith
Parnos Meadsmith
Drow Arrow
Baron
Baron
Posts: 57
Joined: Sat Jun 12, 2021 9:19 am

Re: Quick Buy AHK script

Post by Drow Arrow »

Changelog:

04/04/2024:
  • Initial Release of Quick buy script 1
  • Quick Buy Script 2 added (later on the same day)
23/08/2024:
  • Added version of script with GUI allowing user to edit hotkey and buy count without needing to edit the script directly
  • Added checkbox that allows you to make the window Always on Top
  • the Program now generates an configuration file to remember it's settings between instances.
24/08/2024:
  • Created an Options tab and moved all options into it.
  • Added Transparency Slider
  • Always on top now remembers it state between instances. (forgot this when initially setting up the settings file)
31/08/2024:
  • Fixed mistake which caused the buy count to be forcibly set to 10 when the program was started instead of using the value in the configuration file.
  • Fixed Hotkeys in the GUI version so they are now only active when game window is in focus.
Active Characters:
Ragos Meadsmith
Efiel Meadsmith
Ezekial Meadsmith
Parnos Meadsmith
Post Reply