Page 1 of 3

Macros: Autohotkey Superthread

Posted: October 12th, 2008, 6:09 pm
by Juke
SZR's script, like most SA:MP RP servers, requires you to type in a whole lot of slash commands. Slash commands are commands that you enter into your text box beginning with a forward slash ( / ) to use specific game actions. Now, instead of taking the time to type these constantly, most people have been clever enough to make their own custom macro script. Instead of a laborious /enter, /repair, /tazer or any other command you want to use, you can turn those into one-push strokes such as alt-e, ctrl-r, or a mouse button.

This thread only deals with the most popular macro editor, Autohotkey, so you will want to start by downloading that here. It will come with it's own basic instructions, but I'll break down what I think you need to know.

First, we'll take an example macro and break it down.

Code: Select all

Numpad5::
SendInput tI've got ants in my pants and I like to dance.{Enter}
SendInput t/dance 3{Enter}
return
The result of this script is the following: You will now be able to press Numpad 5 at any time to tell people "I've got ants in my pants and I like to dance," then begin dancing. The exact components are as follows.

Numpad5:: This is your signal to AHK that you want to map something to Numpad 5.
Sendinput This is the start of most AHK binds for SAMP. It will tell AHK that you want to send the following keys to your computer.
SendInput tI've got ants in my pants and I like to dance. This is the bulk of your command. AHK will now send those keypresses to your computer, saving you a lot of time. Most SendInput lines for SAMP will begin with the letter "t" to open the chatbox before it starts sending keypresses.
{Enter} This is how you tell AHK to press the Enter or Return key. This will almost certainly be at the end of each line in the macro.
SendInput Again, this sends a flag to AHK that you want to start inputting keypresses.
SendInput t/dance 3{enter} "t" opens the chat box, you input your command, and you press enter to finish the line.
return This tells AHK "I'm done with this macro!" You can then continue to enter new macros underneath.

All this again allows you to press Numpad 5 and say "I've got ants in my pants and I love to dance." and begin dancing.

Note: You can also add more commands per line or seperate each command into a new line.

Code: Select all

Numpad5:: SendInput tI've got ants in my pants and I like to dance.{Enter}t/dance 3{Enter}
return
This would function exactly the same as the previous macro, but you should never format your AHK scripts like this, more on that later.

A common macro on the server for police is a tazer key.

Code: Select all

*MButton::
SendInput t/tazer{enter}
return
The only obvious addition is the use of an asterisk before labeling the key. In AHK this functions as a wildcard, meaning it will work regardless of any other keys being pressed. This means you can use it while on the run, useful for chasing down perps.

There's also the sleep function. Sleep will tell Autohotkey to chill out for an exact amount of milliseconds. Sleep 1 is one millisecond. Sleep 1000 is one second.

Our server gives automatic warnings and kicks for input spam from programs like AHK, intentional or not. To avoid being automatically warned and kicked you need to use the sleep function.

First, always end your binds with the following:

Code: Select all

sleep 500
return
These two commands must be on their own lines! If not, AHK can sometimes get "stuck" and spam the binds over and over, resulting in an automatic warning / kick which we will not remove under any circumstances so be careful!

Second, if your bind has more than one line of input to the server, every line of input should have sleep (at least) 4000 preceding it.

Code: Select all

numpad0::
SendInput t**Here is the LS transport CRANE. When you are done with car, /DROPCAR here and it will put back in pool{Enter}
Sleep 5000
SendInput t*for public use. You will also get a small finders fee for your work...$1000-$2000 at level one.{Enter}
return
If you do not use sleep between lines, you will easily exceed our automatic spam warning threshold and receive a warning / kick which we will not remove under any circumstances.

This will wait 5 seconds between saying "**Here is the LS transport CRANE. When you are done with car, /DROPCAR here and it will put back in pool"
and the next line "for public use. You will also get a small finders fee for your work...$1000-$2000 at level one."

This makes the text much easier to read than if it came in one block, makes it look like "human speech" instead of a macro, and avoids the automatic spam warning.

If you want to make it look more like "human speech" try to stagger the amount of sleep between each line.

Here's a long example from the tour script:

Code: Select all

!f::
SendInput t/b **All fishing commands can be found by using /fishhelp{Enter}
Sleep 4000
SendInput t*Fishing is fairly simple, just stand at a fishing pole to begin.{Enter}
Sleep 4500
SendInput t/b *Then type /fish over and over to catch fish... nothing complicated.{Enter}
Sleep 5000
SendInput t*You can hold five fish but catch six before the timer will warn you of overfishing the seas.{Enter}
Sleep 5500
SendInput t*Fishing is fairly useless at first because you only want fish over twenty pounds but won't catch them.{Enter}
Sleep 5000
SendInput t*The fishing timer will reset allowing you to fish again AT LEAST every twenty minutes.{Enter}
Sleep 5000
SendInput t*/b Fishing is profitable, but after you catch about 700 total you will no longer be able to fish.{Enter}
return
This will make a small, noticeable difference in the delay between sentences and make it look less rigid and robotic.

As you can see, this is a very powerful tool! But there are also some practical limitations. Along with the aforementioned limits, you should NEVER create a macro that repeats itself automatically more than once every thirty minutes. It spams our server and creates lag. To follow server rules, you should NEVER create a macro that allows you to function while away from keyboard. Not only does it almost always create server lag, it's unfair to players who are achieving things as intended. It's bad, and it's extremely obvious. If you are abusing macros we will notice very quickly and punish you.

That said, macros are almost always a good thing. Get creative, there are all sorts of multiple line macros you can use to save time. The most common binds are to Alt+keys and Ctrl+keys, which can be done with !KEY and ^KEY prefixing your first line, respectively.

Example:

Code: Select all

!G::
Alt+G

Code: Select all

^G::
Ctrl+G

You will also want to add "#IfWinActive, GTA:SA:MP" to the beginning of your .ahk file. This ensures that your hotkeys will only trigger while GTA:SA:MP is the active window. If you forget to turn off your AHK script or if you are playing windowed you will only use the hotkeys in GTA as intended.

A lot of people use separate .ahk scripts for each character. Here's one of my own full AHK scripts.

Code: Select all

#IfWinActive, GTA:SA:MP

!1::
SendInput t/usepot{enter}
sleep 500
return
!2::
SendInput t/usecrack{enter}
sleep 500
return
numpad1::
SendInput t/mget{enter}t/mdeliver{enter}
sleep 500
return
!4::
SendInput t/modcar 2{enter}
sleep 500
return
!5::
SendInput t/repair{enter}
sleep 500
return
numpad0::
SendInput t/dropcar{enter}
sleep 500
return
!h::
SendInput tOk bye.{enter}t/h{enter}t/cellout{enter}
sleep 500
return
!p::
SendInput t/cellin{enter}t/p{enter}tHello. This is Conrad.{enter}
sleep 500
return
!-::
SendInput t/accept crack{enter}
SendInput t/accept pot{enter}
sleep 500
!0::
SendInput t/accept repair{enter}
sleep 500
return
!,::
SendInput t/enter{enter}
sleep 500
return
!.::
SendInput t/exit{enter}
sleep 500
return
!k::
SendInput t/s BOOP BWEEP{Enter}t/unlock{Enter}
Sendinput t/me unlocks the car{enter}
sleep 500
return
!l::
SendInput t/s BWEEP BOOP{Enter}t/lock{Enter}
Sendinput t/me locks the car{enter}
sleep 500
return
There is a list of more advanced tutorials available on the AHK website here.

Hope this helps!

Re: Macros: Autohotkey Superthread

Posted: October 14th, 2008, 7:00 am
by Akimoto Shun
Juke this is very good. Thanks for putting forth the :effort: that some of us wouldn't.

Re: Macros: Autohotkey Superthread

Posted: October 28th, 2008, 12:52 pm
by Adj
Ofcourse you would only want to use the hotkeys in samp and when you press it outside samp it's a mistake and it sucks.

You can enforce it by adding a line of code to the start and end of your script. This way it will only work when you're ingame.

Code: Select all

#IfWinActive, GTA:SA:MP

!p::
SendInput t/pickup{enter}
SendInput t/cellin{enter}
SendInput tHello{enter}
Return

; Rest of your code

#IfWinActive

Re: Macros: Autohotkey Superthread

Posted: October 29th, 2008, 3:20 pm
by cHR0ME
What a nice guy putting his time into this.

Re: Macros: Autohotkey Superthread

Posted: November 1st, 2008, 4:41 pm
by Strange
I thought I might stop in here and give the Arms Dealers a break from all that tedious typing. So here are a few likes for AHK that should be useful.

!Numpad1::
SendInput t/sellgun sdpistol{Left 9}
return

!Numpad2::
SendInput t/sellgun shotgun{Left 8}
return

!Numpad3::
SendInput t/sellgun mp5{Left 4}
return

!Numpad4::
SendInput t/sellgun ak47{Left 5}
return

!Numpad5::
SendInput t/sellgun m4{Left 3}
return


When these commands are run in the script, they will open your chat box, type all that you see there into it, and position the cursor so that the players ID is all you need to type before pressing enter. Of course, assign them to whatever key you feel comfortable with, you don't have to use mine.

Re: Macros: Autohotkey Superthread

Posted: November 3rd, 2008, 6:07 am
by Robinson_Sparis
I have a good question for you, if you click edit script and you put two times this:
Numpad5:: SendInput tI've got ants in my pants and I like to dance.{Enter}t/dance 3{Enter}
return
Numpad5:: SendInput tI've got ants in my pants and I like to dance.{Enter}t/dance 3{Enter}
return
Then it makes errors always when i run the program, where can i find the notepad file to edit it or what can i do? reinstall isn't fixing this.

Re: Macros: Autohotkey Superthread

Posted: November 3rd, 2008, 6:48 am
by Robinson_Sparis
Finaly i fixex my problem :)

Re: Macros: Autohotkey Superthread

Posted: November 24th, 2008, 7:25 am
by Gonz_Diller
or use keybind pm me for it, is easier and no code required, you are just limited to use from 0 to 9 numbers

Re: Macros: Autohotkey Superthread

Posted: December 5th, 2008, 10:05 pm
by simon_bg
Thanks for the post Juke. I have been looking for this program.

Re: Macros: Autohotkey Superthread

Posted: December 16th, 2008, 2:23 pm
by Jakew
Thank you man,great tutorial!

Re: Macros: Autohotkey Superthread

Posted: December 28th, 2008, 9:33 pm
by Gerofied
for some reason when i put the copy the gun one it doesn't allow me to run the script.

*EDIT: I have got it to work but the {Left 9} etc doesn't work properly.

Re: Macros: Autohotkey Superthread

Posted: December 29th, 2008, 11:10 pm
by Adj
If you expect a solution from someone you should've included the code.

Re: Macros: Autohotkey Superthread

Posted: December 30th, 2008, 1:38 am
by Gerofied
Dw, i got it working. should've edited again.

I tested each one individually then it worked, i tried to make an extra one which didn't work then.

Now it does XD

Re: Macros: Autohotkey Superthread

Posted: January 5th, 2009, 9:41 am
by Peter_Bonjasky
Gonz_Diller share that here.
So it will be nice for people to see another way of binding.
And you will not be spamed with pm's.

Re: Macros: Autohotkey Superthread

Posted: January 7th, 2009, 10:34 pm
by TriggerHappy
I got a question for you.
Let's say i use /drink, and everytime i drink i usually say '' /me opens the fridge, takes out a drink and starts drinking. ''
So how do i put a macro in so everytime i type /drink i say '' /me opens the fride, takes out a drink and starts drinking. ''

Edit: figured it out, nevermind.

Re: Macros: Autohotkey Superthread

Posted: March 26th, 2009, 1:00 pm
by Kronik
I got a question, ok lets say I make a hotkey for /find 4.. is there any way I can set it to auto, to like /find every ____ seconds?

Also here is my Autohotkey script for the Entire number pad.

Numpad1::sendinput t/me Takes out a Dutch and starts blazing {Enter} t/smoke {Enter}

Numpad2::sendinput t/me Throws up G for Life {Enter}

Numpad3::sendinput t Thanks for the ride Kuz {Enter} t/Me Throws up his middle finger as he drives off {Enter}


Numpad4::sendinput t/p {Enter} t What up kuz? Who this be? {Enter}


Numpad5::sendinput t/h {Enter} t Aite 1 {Enter}


Numpad6::sendinput t/



Numpad7::sendinput t/


Numpad8::sendinput t/Unlock {Enter}


Numpad9::sendinput t/Lock {Enter}


NumpadDiv::sendinput t/find 2 {Enter}


NumpadMult::sendinput t/locker store gun {Enter}


NumpadAdd::sendinput t/mget {Enter} t/Mdeliver {Enter} t Aite got that shit nigga {Enter}


NumpadSub::sendinput t/Enter {Enter} t/Exit {Enter}


NumpadEnter::sendinput t/Stats {Enter} t/me Takes out Ipod to check stats {Enter}


Numpad0::sendinput t/Dropcar {Enter}

Re: Macros: Autohotkey Superthread

Posted: March 26th, 2009, 1:36 pm
by Adj
There is a way, but don't do it, it's gay.
It'd not be you, but AHK that'd play.
Wow I may be having a poetic day

Just make a hotkey to do find 1 or something, and get a timer to make some ding.

I always just use mirc, a program for szr chat, it's free.
/timer [How often it should do it, 0 is infinite] [Amount of seconds delay] [Command for a sound to play]


/timer 0 130 /beep
/timers off to put it to sleep.

Re: Macros: Autohotkey Superthread

Posted: May 2nd, 2009, 6:09 pm
by Silas_Methodman
:ughh:

Re: Macros: Autohotkey Superthread

Posted: May 2nd, 2009, 6:55 pm
by David_York
The gang icons are always bugging out, making it so we have to either type or hit our keybinds over and over. Can someone show me a example where it will loop /quitgang /joingang automatically? This will not only help me, but everyone else who uses gang icons as a important tool.

Re: Macros: Autohotkey Superthread

Posted: May 6th, 2009, 3:37 am
by John_Woody

Code: Select all


Gchat = 0000

!g::
Input, Gchat, l4, {Lcontrol}
return

^g::
Sendinput t/quitgang{enter}
Sendinput t/joingang{space}%Gchat%{enter}
return

alt+g: Enter gangchat, press left control to submit
ctr+g: rejoin

Not tested yet, but it should work

Edit:

A nice addition to the Input hotkey is this line

Code: Select all

SendInput t/w{space}YOURNAME{space}%Gchat%{enter}
Just put this above the retrun, and you will whisper the entered gangchat number to yourself every time you change it, this prevents you from joining a wrong gangchat by accident.

Edit2:

I tested it now, works perfectly

Re: Macros: Autohotkey Superthread

Posted: May 6th, 2009, 12:17 pm
by David_York
Pretty much I have what you have there, but less complicated.

Numpad2::
SendInput t/quitgang{Enter}
SendInput t/joingang XXXX{Enter}
SendInput t/w David_York Gang Chat is: XXXX{Enter}
return

What I was actually looking for was a script that will immediately begin looping /joingang /quitgang every 5 minutes or so when I join sa-mp. It would require no keys but maybe only to make the script active.

Or we could just fix this problem we have with the bugging gang icons on our maps.

Re: Macros: Autohotkey Superthread

Posted: May 7th, 2009, 3:34 am
by John_Woody
This should work

Code: Select all

Gchat = 0000

Loop
{
SendInput t/quitgang{enter}t/joingang{space}%Gchat%{enter}
sleep 300000
}

!g::
Input, Gchat, l4, {Lcontrol}
return

I feel the hotkey comes in handy if you wanna change your gangchat every now and then.

Another way to do it( you got to enter your gchat everytime you start your script)

Code: Select all

Gchat = 0000

!g::
Input, Gchat, l4, {Lcontrol}
Loop
{
SendInput t/quitgang{enter}t/joingang{space}%Gchat%{enter}
sleep 300000
}
return

And the simplest solution: (it requieres to edit your script everytime you change your gangchat

Code: Select all

Loop
{
SendInput t/quitgang{enter}t/joingang{space}XXXX{enter}
sleep 300000
}

Re: Macros: Autohotkey Superthread

Posted: May 11th, 2009, 2:56 pm
by Mevi_Gonzole
Thank you alot, well i have searched for this alot.
not so easy to use but i learned it after some days.

ill post my scripts soon :arghy:

Re: Macros: Autohotkey Superthread

Posted: May 21st, 2009, 2:20 pm
by Adj
It is forbidden to use a loop like that.

DO NOT use a loop to send a command. You can use a loop to play a sound so it remembers you to press a key but you can not let your computer play for you, it'll get you banned.

Re: Macros: Autohotkey Superthread

Posted: May 21st, 2009, 2:44 pm
by John_Woody
You are right Adj, ad by the way: using a loop to rejoin a gang is pretty pointless, since the period of time before the markers disappear is pretty random. I wrote this piece of shitscript because that guy really seemed to want to have it, I do not recommend using it.
My first solution I posted might be the best for this problem, and I think that one is allowed :)

And thanks for your post it forced me to get the a nice idea, now /repair starts a timer, and after it is over my script plays a sound that indicates that I can repair the car again :smugdog: