This is a simple script I use when I want to have a button preform a different in-game action each time it’s pressed. An example was from Darkfall, I used the TAB key to cycle between two different rank 50 nuke spells.
To use I would just tab and left click, tab and left click. The first press of tab would que up one rank 50 spell, after the spell was cast it had a slight delay before it could be used again; pressing tab and clicking again would que up another rank 50 spell from a different magic school allowing for rapid firing without waiting on a cooldown and without fat fingering a key and messing up the cycle.
To demonstrate this I will create an example. In this example I will create a script that will toggle between 2 different spells/abilities when the right mouse button is pressed at the same time as shift. This script assumes that abilities 9 and 0 are abilities on my action bar ingame or are assigned to spells or abilities in the games hotkeys.
First declare a variable at the top of your script and give it a value of 0 or 1.
Healstate = 1
Next define which key pressed you wish to preform the action of the toggle(in this example shift and right click).
+RButton::
And last but not least we create an if loop to make the magic happen. The statement will test the variable for the value 1. If the statement is TRUE(and it will be everyother time) it executes one branch of code, sets the value of the variable to anything but 1, and waits for you to press the key again.
if (Healstate == 1)
{
send {9}
Healstate = 0
return
}
else
{
send {0}
Healstate = 1
return
}
The Final Script
+RButton::
if (Healstate == 1)
{
send {9}
HealState = 0
return
}
else
{
send {0}
HealState = 1
return
}
Since most games use shift as a run key it is often required to use a script that will still toggle regardless of weather the shift key is pressed or not. Adding 1 line of code to the example will allow for this effect.
RButton::
+RButton::
if (HealState == 1)
{
send {9}
HealState = 0
return
}
else
{
send {0}
HealState = 1
return
}
This is the preferred method over having two separate sets of statements, one for each statement(RButton and +RButton).