[Guide] Advanced Binds/Macros Using AutoHotKey Software
#1
Advanced Binds/Macros Using AutoHotKey


Summary
I am going to show you a way to get around the limitations which the Garry's Mod binds currently have, using my methods you'll be able to do the following:
  • Assign macros to specific macro keys on a keyboard.
  • Create commands to greatly reduce time spent typing.
  • Create automatic pipelines to do various duties.
  • And much more

So how is this achieved?
Using the software, you'll be able to create macros which are basically pipelines of code. Similar to how the default GMod binds are created, but much more advanced.
These lines of code can be activated by various ways, most commonly (for me at least) by pressing a key which will run a .exe of the code or by entering a '/' command in the console.

Where can I get the software

What you'll need to do this is the AutoHotKey software which you can get from HERE.

How to add the code

  1. Right-click an empty spot on your desktop or in a folder of your choice.
  2. In the menu that appears, select New -> AutoHotkey Script. (Alternatively, select New -> Text Document.)
  3. Type a name for the file, ensuring that it ends in .ahk. For example: Test.ahk
  4. Right-click the file and choose Edit Script.
  5. In the document, copy and paste code from one of the example codes below or create one yourself (there's an active community for the software, try googling what you want as a starting point and work from there).
  6. (optional) Some macros may require to be ran using a .exe (they'll be specified above the codes). For these you just need to right click the .ahk and click compile.

In-Game Demonstration



Example Commands

I encourage people who use this software to create their own commands to share some of their code to benefit everyone. Smile

Miranda Rights
Uses numpad 1 key but that can be easily configured.


Spoiler :
Code:
#NoEnv

Numpad1::
text1 =
(
You have the right to remain silent. Anything you say or do can and will be held against you in the court of law.
)
Send, y
sleep, 100
sendinput %text1%
sleep, 100
Send, {enter}

sleep, 600
text2 =
(
You have the right to an attorney. If you cannot afford an attorney, one will be appointed to you.
)
Send, y
sleep, 100
sendinput %text2%
Send, {enter}
return



Miranda Rights - Macro Keyboard
Needs to be compiled to .exe, This code was written for a macro key on the keyboard that was set the .exe


Spoiler :
Code:
#NoEnv

text1 =
(
You have the right to remain silent. Anything you say or do can and will be held against you in the court of law.
)
Send, y
sleep, 100
sendinput %text1%
sleep, 100
Send, {enter}

sleep, 600
text2 =
(
You have the right to an attorney. If you cannot afford an attorney, one will be appointed to you.
)
Send, y
sleep, 100
sendinput %text2%
Send, {enter}

ExitApp




Show ID Command
(Ran using the commands /id and /idt in console. /idt requires Gmod in windowed / windowed borderless mode because of input boxes)



Spoiler :
  • Change the character information to match your own in the configuration section of the code.
  • IDT works best in borderless windowed mode, it will bring up an input box for you to type the name of the person receiving the ID.
Code:
#NoEnv

; -------------
; CONFIGURATION
; -------------



firstname =
(
Ted
)

surname =
(
Baker
)

gender = ;Keep it male or female, otherwise his/her messages won't work.
(
male
)

age =
(
27
)



; ------------------
; MISC - LEAVE ALONE
; ------------------



if gender = male
    hisher =
    (
    his
    )
if gender = male
    walletpurse =
    (
    wallet
    )    
return
if gender = female
    hisher =
    (
    her
    )
if gender = female
    walletpurse =
    (
    purse
    )
return
    
    
; ----------------
; GENERAL ROLEPLAY
; ----------------



::/id::
id =
(
/me takes %hisher% ID card from %hisher% %walletpurse% and passes it over.
)
sendinput say %id%
Send, {Enter}
Send, {Esc}
sleep, 600
idt2 =
(
The ID displays the name %firstname% %surname%, aged %age% years old along with a photograph of the person.
)
Send, y
sleep, 100
sendinput /it %idt2%
Send, {enter}
return



::/idt::
idt =
(
/me takes his ID from %hisher% %walletpurse% and passes it over to
)
InputBox, UserInput, Reciever's Name, Please enter the name of the reciever., , 200, 100
if ErrorLevel
    MsgBox, CANCEL was pressed.
else
    Send, say %idt% %UserInput%.
    Sleep, 100
    Send, {Enter}
    Send, {Esc}
sleep, 600
idt2 =
(
The ID displays the name %firstname% %surname%, aged %age% years old along with a photograph of the person.
)
Send, y
sleep, 100
sendinput /it %idt2%
Send, {enter}
return



Fine Command
(Ran using the commands /fine in console. Gmod needs to be in windowed / windowed borderless because of input boxes)


Spoiler :
Code:
::/fine::
fine1 =
(
/me takes out their pen from their jacket pocket and begins to write a ticket up.
)
    sendinput say %fine1%
    Sleep, 100
    Send, {Enter}
    Send, {Esc}
InputBox, UserInput1, Criminal's Name, Please enter the name/id of the criminal., , 200, 100
if ErrorLevel
    return
else
InputBox, UserInput2, Fine Amount, Please enter the amount of the fine., , 200, 100
    if ErrorLevel
    return
else
    Send, y
    sleep, 100
    sendinput /me writes up a fine addressed to %UserInput1% for the cost of $%UserInput2% to be paid immediately.
    Sleep, 100
    Send, {Enter}
    sleep, 1000
    Send, y
    sleep, 100
    sendinput /me hands the ticket over to %UserInput1%.
    Send, {Enter}
return



Cash Register Command
(Ran using the command /register in console.)


Spoiler :
Code:
::/register::
register1 =
(
/me counts the money, quietly muttering whilst doing so.
)
sendinput say %register1%
Send, {Enter}
Send, {Esc}
sleep, 2000
register2 =
(
/me presses a combination of buttons which opens up the cash register.
)
Send, y
sleep, 100
sendinput %register2%
Send, {enter}
sleep, 2000
register3 =
(
/me places the money neatly inside the register's money tray and then closes it.
)
Send, y
sleep, 100
sendinput %register3%
Send, {enter}
sleep, 2000
register4 =
(
/it The register makes a loud *CLICK* as it shuts tight
)
Send, y
sleep, 100
sendinput %register4%
Send, {enter}
return



Impound Vehicle
(Ran using the command /impound in console.)



Spoiler :
(Needs to be used in windowed / borderless mode for Gmod.)

Works for both cop/sru and president jobs.

Generic reason for search warrant (vehicle violates traffic laws.)

Code:
::/impound::
Send, {Esc}
InputBox, criminal, Criminal's Steam Name or ID , Steam Name or ID., , 650, 100
if ErrorLevel
    return
else
impound1 =
(
/warrant %criminal% search vehicle violates traffic laws.
)
sleep, 100
Send, y
sleep, 100
sendinput %impound1%
sleep, 100
Send, {enter}
impound2 =
(
/pm %criminal% Your vehicle is going to be impounded by the EC:PD. Please report to the Nexus front desk to discuss how to retrieve it.
)
sleep, 1000
Send, y
sleep, 100
sendinput %impound2%
sleep, 100
Send, {enter}
return



Unlock Car
(Automatic when you press shift and right click)



Spoiler :
Code:
shift & RButton::
send {shift down}{RButton}{shift up}
sleep, 150
unlock1 =
(
/me Inserts his key inside the vehicle door and unlocks it.
)
Send, y
sendinput %unlock1%
Send, {enter}
return




To Do
  • How to bind something to a hard-coded keyboard macro key.
  • Add cancel command to auto-advert.
  • Demonstration video.


NOTE: To run Garry's Mod in Windowed Borderless mode, right click the game in your library - Go to properties - Set launch options - And type in -windowed -noborder
Then run Garry's Mod and make sure it's at the same resolution as your desktop.
The following 5 users Like GRiiM's post:
  • Obay, Roachy, Dauntless, Marty, kix2468
#2
This is a nice addition instead of the old console binds. :p
I would like to point out to people with windows 8.0, you can't run the show ID /idt command.
#3
(06-22-2014, 08:58 AM)SnowredWolf Wrote: This is a nice addition instead of the old console binds. :p
I would like to point out to people with windows 8.0, you can't run the show ID /idt command.

If it is that, could be something else. Would be nice to have other people try it out and report back.

Edit: Snowredwolf has confirmed that it now works properly with Windows 8.1 instead of 8.0 Smile
#4
Adjusted these binds to Garry's Mod from GTA:SAMP, just paste them right into the file by itself, save it then right click AHK and reload the script.
Here's the list of keys you could use instead of the numpad keys if you wish to change them http://www.autohotkey.com/docs/KeyList.htm

Mostly for Police, edit it to your likings.


Spoiler :
Numpad1::
Sendinput y
Sleep 100
Sendinput /y ECPD, Put your hands up or lethal force will be used{!}{Enter}
return

Numpad2::
Sendinput y
Sleep 100
Sendinput /y ECPD, Pull over immediately{!}{Enter}
Sleep 100
Sendinput y
Sleep 100
Sendinput /it **You see Red and Blue flashing lights**{Enter}
return

Numpad3::
Sendinput y
Sleep 100
Sendinput /y This is your SECOND warning, Pull over NOW or lethal force will be deployed{!}{Enter}
return

Numpad4::
Sendinput y
Sleep 100
Sendinput /y This is your THIRD and LAST warning, lethal force is now AUTHORIZED{!}{Enter}
return

NumpadAdd::
Sendinput y
Sleep 100
Sendinput You have the right to remain silent.{Enter}
Sleep 1500
Sendinput y
Sleep 100
Sendinput Anything you do or say can and will be used against you in the court of law.{Enter}
Sleep 1500
Sendinput y
Sleep 100
Sendinput You have the right to an attorney after initial processing has been completed.{Enter}
Sleep 1500
Sendinput y
sleep 100
Sendinput Do you understand these rights as I have read them?{enter}
return

The following 1 user Likes Remen3's post:
  • GRiiM
#5
Nice Guide! Is there a way to make an AHK script that automatically runs console commands, just like normal console binds? Instead of the chatbox opening, pasting and sending chat messages automatically(that's what Remen's code looks like). If there is none, I would do it like that:



Spoiler :
;I'm not sure if nothing goes wrong when I use such light-short sleeps.
L::
Sendinput y
sleep 100
Sendinput /broadcast <law1>{Enter}
sleep 800
Sendinput y
sleep 100
Sendinput /broadcast <law2>{Enter}
sleep 800
Sendinput y
sleep 100
Sendinput /broadcast <law3>{Enter}
sleep 800
Sendinput y
sleep 100
Sendinput /broadcast <law4>{Enter}
return

i have self control
#6
Great job on making this guide!
#7
(06-28-2014, 03:00 PM)Pawenstedt Wrote: Nice Guide! Is there a way to make an AHK script that automatically runs console commands, just like normal console binds? Instead of the chatbox opening, pasting and sending chat messages automatically(that's what Remen's code looks like). If there is none, I would do it like that:

I don't believe that there is a way for it to write commands straight into the console without opening it.
#8
(06-28-2014, 04:53 PM)GRiiM Wrote:
(06-28-2014, 03:00 PM)Pawenstedt Wrote: Nice Guide! Is there a way to make an AHK script that automatically runs console commands, just like normal console binds? Instead of the chatbox opening, pasting and sending chat messages automatically(that's what Remen's code looks like). If there is none, I would do it like that:

I don't believe that there is a way for it to write commands straight into the console without opening it.
Well, okay then. Is the code for the chatbox method I have written okay?
i have self control
#9
Added a fine command which looks like -

* GRiiM takes out their pen from their jacket pocket and begins to write a ticket up.
* GRiiM writes up a fine addressed to [CRIMINAL NAME] for the cost of [FINE AMOUNT] to be paid immediately.
* GRiiM hands the ticket over to [CRIMINAL NAME]


Also added a cash register command which looks like -

* GRiiM counts the money, quietly muttering whilst doing so.
* GRiiM presses a combination of buttons which opens up the cash register.
* GRiiM places the money neatly inside the register's money tray and then closes it.
** The register makes a loud *CLICK* as it shuts tight **


I've also added a quick in-game demonstration video.

Added a /impound command inspired by Georgetheboy's suggestion - http://www.fearlessrp.net/showthread.php?tid=50827

Added a car unlock /me action.
#10
Great work!

Moved to useful docs.
The following 1 user Likes GeorgeTheBoy's post:
  • GRiiM


Forum Jump:


Users browsing this thread: 1 Guest(s)