Created
May 26, 2024 06:00
-
-
Save hfsaito/067d83dbafa07179dc1a05be70297171 to your computer and use it in GitHub Desktop.
Shortcuts in AutoHotKey for Plants vs. Zombies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires AutoHotkey v2.0 | |
PVZ_WINDOW_TITLE := "Plants vs. Zombies" | |
class Base { | |
static CARD_COORD := [ | |
{x: 0.14583333333333334, y: 0.06666666666666667}, | |
{x: 0.2111111111111111, y: 0.06666666666666667}, | |
{x: 0.26944444444444443, y: 0.06666666666666667}, | |
{x: 0.34375, y: 0.06666666666666667}, | |
{x: 0.3840277777777778, y: 0.06666666666666667}, | |
{x: 0.4798611111111111, y: 0.06666666666666667}, | |
{x: 0.5229166666666667, y: 0.06666666666666667}, | |
{x: 0.5916666666666667, y: 0.06666666666666667}, | |
{x: 0.6569444444444444, y: 0.06666666666666667}, | |
{x: 0.7194444444444444, y: 0.06666666666666667} | |
] | |
static CHOOSE_YOUR_PLANTS_COORD := { | |
peashooter: {x: 0.06111111111111111, y: 0.2638888888888889}, | |
sunflower: {x: 0.12152777777777778, y: 0.26481481481481484}, | |
cherryBomb: {x: 0.1909722222222222, y: 0.26296296296296295}, | |
wallNut: {x: 0.26458333333333334, y: 0.2611111111111111}, | |
potatoMine: {x: 0.32569444444444445, y: 0.26481481481481484}, | |
snowPea: {x: 0.3923611111111111, y: 0.2601851851851852}, | |
chomper: {x: 0.45625, y: 0.2611111111111111}, | |
repeater: {x: 0.5243055555555556, y: 0.2601851851851852}, | |
puffShroom: {x: 0.059027777777777776, y: 0.3824074074074074}, | |
sunShroom: {x: 0.12916666666666668, y: 0.3851851851851852}, | |
fumeShroom: {x: 0.2, y: 0.37962962962962965}, | |
graveBuster: {x: 0.2569444444444444, y: 0.38333333333333336}, | |
hypnoShroom: {x: 0.3215277777777778, y: 0.3861111111111111}, | |
scaredyShroom: {x: 0.38333333333333336, y: 0.38796296296296295}, | |
icoShroom: {x: 0.45694444444444443, y: 0.39166666666666666}, | |
doomShroom: {x: 0.5138888888888888, y: 0.39351851851851855}, | |
lilyPad: {x: 0.05763888888888889, y: 0.49722222222222223}, | |
squash: {x: 0.1284722222222222, y: 0.49444444444444446}, | |
threepeater: {x: 0.18958333333333333, y: 0.49537037037037035}, | |
tangleKelp: {x: 0.2569444444444444, y: 0.5}, | |
jalapeno: {x: 0.3236111111111111, y: 0.5009259259259259}, | |
spikeweed: {x: 0.39791666666666664, y: 0.5009259259259259}, | |
tourchwoord: {x: 0.4673611111111111, y: 0.5018518518518519}, | |
tallNut: {x: 0.51875, y: 0.5037037037037037}, | |
seaShroom: {x: 0.059027777777777776, y: 0.6129629629629629}, | |
plantern: {x: 0.12430555555555556, y: 0.6138888888888889}, | |
cactus: {x: 0.1909722222222222, y: 0.6148148148148148}, | |
blover: {x: 0.2569444444444444, y: 0.6138888888888889}, | |
splitPea: {x: 0.3229166666666667, y: 0.612037037037037}, | |
starfruit: {x: 0.3902777777777778, y: 0.6064814814814815}, | |
pumpkin: {x: 0.4548611111111111, y: 0.6111111111111112}, | |
magnetShroom: {x: 0.5222222222222223, y: 0.6203703703703703}, | |
cabbagePult: {x: 0.06875, y: 0.7314814814814815}, | |
flowerPot: {x: 0.12708333333333333, y: 0.7268518518518519}, | |
kernelPult: {x: 0.1951388888888889, y: 0.7314814814814815}, | |
coffeeBean: {x: 0.2604166666666667, y: 0.7342592592592593}, | |
garlie: {x: 0.3229166666666667, y: 0.7361111111111112}, | |
umbreallaLeaf: {x: 0.38680555555555557, y: 0.7351851851851852}, | |
marigold: {x: 0.45694444444444443, y: 0.7324074074074074}, | |
melonPult: {x: 0.5208333333333334, y: 0.7398148148148148}, | |
gatlingPea: {x: 0.05694444444444444, y: 0.850925925925926}, | |
twinSunflower: {x: 0.11736111111111111, y: 0.8546296296296296}, | |
gloomShroom: {x: 0.19444444444444445, y: 0.85}, | |
cattail: {x: 0.2611111111111111, y: 0.8481481481481481}, | |
winterMelon: {x: 0.31875, y: 0.8425925925925926}, | |
goldMagnet: {x: 0.3909722222222222, y: 0.8398148148148148}, | |
spikerock: {x: 0.45555555555555555, y: 0.8435185185185186}, | |
cobCannon: {x: 0.5298611111111111, y: 0.8425925925925926} | |
} | |
static LETS_GO_BUTTON_POSITION := {x: 0.28125, y: 0.9388888888888889} | |
static GetPixelCoord(coordInPercentage) { | |
WinGetPos ,, &WinWidth, &WinHeight, "Plants vs. Zombies" | |
WinRatio := WinHeight / WinWidth | |
GameRatio := 0.75 | |
GameWidth := WinWidth | |
GameHeight := WinHeight | |
HGap := 0 | |
VGap := 0 | |
if (WinRatio >= GameRatio) { | |
GameHeight := WinWidth * GameRatio | |
VGap := (WinHeight - GameHeight) / 2 | |
} else { | |
GameWidth := WinHeight / GameRatio | |
HGap := (WinWidth - GameWidth) / 2 | |
} | |
return { | |
x: (coordInPercentage.x * GameWidth) + HGap, | |
y: (coordInPercentage.y * GameHeight) + VGap | |
} | |
} | |
static GetCardCoord(n) { | |
return Base.GetPixelCoord(Base.CARD_COORD[n]) | |
} | |
static GetChooseYourPlantsCoord(plantName) { | |
return Base.GetPixelCoord(Base.CHOOSE_YOUR_PLANTS_COORD.%plantName%) | |
} | |
static SelectPlantCard(n) { | |
cardCoord := Base.GetCardCoord(n) | |
MouseGetPos &xold, &yold | |
Click cardCoord.x, cardCoord.y | |
Click xold, yold, 0 | |
} | |
static PlaceCard(n) { | |
cardCoord := Base.GetCardCoord(n) | |
MouseGetPos &xold, &yold | |
Click cardCoord.x, cardCoord.y | |
Click xold, yold | |
} | |
static ChooseYourPlants(plantName) { | |
plantCoord := Base.GetChooseYourPlantsCoord(plantName) | |
Click plantCoord.x, plantCoord.y | |
} | |
static LetsGo() { | |
letsGoCoord := Base.GetPixelCoord(Base.LETS_GO_BUTTON_POSITION) | |
Sleep 100 | |
Click letsGoCoord.x, letsGoCoord.y, 0 | |
Sleep 100 | |
Click letsGoCoord.x, letsGoCoord.y | |
} | |
static AutoClick(key) { | |
while GetKeyState(key, "P") { | |
Click | |
Sleep 10 | |
} | |
} | |
} | |
class Strategy extends Base { | |
static PICKED_PLANTS := [] | |
static MAP_CARD_TO_N := {} | |
static POOL_POSITIONS := [ | |
[ | |
{x: 0.10486111111111111, y: 0.21574074074074073}, | |
{x: 0.19444444444444445, y: 0.2101851851851852}, | |
{x: 0.2826388888888889, y: 0.20925925925925926}, | |
{x: 0.39444444444444443, y: 0.20925925925925926}, | |
{x: 0.5104166666666666, y: 0.20925925925925926}, | |
{x: 0.6020833333333333, y: 0.21851851851851853}, | |
{x: 0.7111111111111111, y: 0.21296296296296297}, | |
{x: 0.8027777777777778, y: 0.22037037037037038}, | |
{x: 0.8916666666666667, y: 0.22685185185185186} | |
], | |
[ | |
{x: 0.10208333333333333, y: 0.34629629629629627}, | |
{x: 0.21736111111111112, y: 0.3592592592592593}, | |
{x: 0.30069444444444443, y: 0.36574074074074076}, | |
{x: 0.3854166666666667, y: 0.36666666666666664}, | |
{x: 0.5041666666666667, y: 0.3611111111111111}, | |
{x: 0.5895833333333333, y: 0.3574074074074074}, | |
{x: 0.7020833333333333, y: 0.3712962962962963}, | |
{x: 0.8020833333333334, y: 0.3685185185185185}, | |
{x: 0.8979166666666667, y: 0.3861111111111111}, | |
], | |
[ | |
{x: 0.10347222222222222, y: 0.5203703703703704}, | |
{x: 0.2, y: 0.5166666666666667}, | |
{x: 0.3090277777777778, y: 0.5194444444444445}, | |
{x: 0.4041666666666667, y: 0.5203703703703704}, | |
{x: 0.5104166666666666, y: 0.5203703703703704}, | |
{x: 0.6041666666666666, y: 0.5222222222222223}, | |
{x: 0.7069444444444445, y: 0.5231481481481481}, | |
{x: 0.8069444444444445, y: 0.5185185185185185}, | |
{x: 0.9076388888888889, y: 0.5259259259259259}, | |
], | |
[ | |
{x: 0.1, y: 0.674074074074074}, | |
{x: 0.19583333333333333, y: 0.6907407407407408}, | |
{x: 0.2951388888888889, y: 0.6833333333333333}, | |
{x: 0.39652777777777776, y: 0.6916666666666667}, | |
{x: 0.49375, y: 0.6796296296296296}, | |
{x: 0.6020833333333333, y: 0.6722222222222223}, | |
{x: 0.7006944444444444, y: 0.674074074074074}, | |
{x: 0.7993055555555556, y: 0.6694444444444444}, | |
{x: 0.89375, y: 0.6824074074074075}, | |
], | |
[ | |
{x: 0.1076388888888889, y: 0.8148148148148148}, | |
{x: 0.20416666666666666, y: 0.8092592592592592}, | |
{x: 0.3104166666666667, y: 0.8212962962962963}, | |
{x: 0.4, y: 0.8148148148148148}, | |
{x: 0.5006944444444444, y: 0.812037037037037}, | |
{x: 0.5923611111111111, y: 0.8175925925925925}, | |
{x: 0.7, y: 0.8194444444444444}, | |
{x: 0.7972222222222223, y: 0.825}, | |
{x: 0.9069444444444444, y: 0.8185185185185185}, | |
], | |
[ | |
{x: 0.10833333333333334, y: 0.9342592592592592}, | |
{x: 0.19722222222222222, y: 0.9305555555555556}, | |
{x: 0.3104166666666667, y: 0.9277777777777778}, | |
{x: 0.4027777777777778, y: 0.9203703703703704}, | |
{x: 0.5, y: 0.9194444444444444}, | |
{x: 0.5979166666666667, y: 0.9194444444444444}, | |
{x: 0.6986111111111111, y: 0.9398148148148148}, | |
{x: 0.7951388888888888, y: 0.937037037037037}, | |
{x: 0.8986111111111111, y: 0.9425925925925925} | |
] | |
] | |
static Reset() { | |
Strategy.PICKED_PLANTS := [] | |
Strategy.MAP_CARD_TO_N := {} | |
Strategy.MAP_POSITIONS := [] | |
} | |
static ChooseYourPlants(plantName) { | |
super.ChooseYourPlants(plantName) | |
Strategy.PICKED_PLANTS.push(plantName) | |
Strategy.MAP_CARD_TO_N.%plantName% := Strategy.PICKED_PLANTS.Length | |
} | |
static PlacePlant(row, col, plantName) { | |
cardN := Strategy.MAP_CARD_TO_N.%plantName% | |
Strategy.SelectPlantCard(cardN) | |
position := Strategy.GetPixelCoord(Strategy.MAP_POSITIONS[row][col]) | |
Click position.x, position.y | |
} | |
static SelectMap(mapName) { | |
Strategy.MAP_POSITIONS := { | |
pool: Strategy.POOL_POSITIONS | |
}.%mapName% | |
} | |
} | |
class LastStandStrategy extends Strategy { | |
static Start() { | |
LastStandStrategy.Reset() | |
LastStandStrategy.ChooseYourPlants('lilyPad') | |
LastStandStrategy.ChooseYourPlants('marigold') | |
LastStandStrategy.ChooseYourPlants('coffeeBean') | |
LastStandStrategy.ChooseYourPlants('fumeShroom') | |
LastStandStrategy.ChooseYourPlants('gloomShroom') | |
LastStandStrategy.ChooseYourPlants('magnetShroom') | |
LastStandStrategy.ChooseYourPlants('goldMagnet') | |
LastStandStrategy.ChooseYourPlants('pumpkin') | |
LastStandStrategy.ChooseYourPlants('garlie') | |
LastStandStrategy.ChooseYourPlants('wallNut') | |
LastStandStrategy.LetsGo() | |
Sleep 3500 | |
LastStandStrategy.SelectMap('pool') | |
LastStandStrategy.PlacePlant(1, 1, 'marigold') | |
LastStandStrategy.PlacePlant(1, 2, 'marigold') | |
LastStandStrategy.PlacePlant(1, 3, 'marigold') | |
LastStandStrategy.PlacePlant(1, 4, 'marigold') | |
LastStandStrategy.PlacePlant(1, 5, 'marigold') | |
LastStandStrategy.PlacePlant(1, 6, 'marigold') | |
LastStandStrategy.PlacePlant(1, 7, 'marigold') | |
LastStandStrategy.PlacePlant(1, 8, 'garlie') | |
LastStandStrategy.PlacePlant(1, 9, 'garlie') | |
LastStandStrategy.PlacePlant(2, 1, 'marigold') | |
LastStandStrategy.PlacePlant(2, 2, 'marigold') | |
LastStandStrategy.PlacePlant(2, 3, 'marigold') | |
LastStandStrategy.PlacePlant(2, 4, 'marigold') | |
LastStandStrategy.PlacePlant(2, 5, 'marigold') | |
LastStandStrategy.PlacePlant(2, 6, 'wallNut') | |
LastStandStrategy.PlacePlant(3, 1, 'lilyPad') | |
LastStandStrategy.PlacePlant(3, 2, 'lilyPad') | |
LastStandStrategy.PlacePlant(3, 3, 'lilyPad') | |
LastStandStrategy.PlacePlant(3, 4, 'lilyPad') | |
LastStandStrategy.PlacePlant(3, 5, 'lilyPad') | |
LastStandStrategy.PlacePlant(3, 6, 'lilyPad') | |
LastStandStrategy.PlacePlant(3, 7, 'lilyPad') | |
LastStandStrategy.PlacePlant(3, 8, 'lilyPad') | |
LastStandStrategy.PlacePlant(3, 1, 'marigold') | |
LastStandStrategy.PlacePlant(3, 2, 'marigold') | |
LastStandStrategy.PlacePlant(3, 3, 'marigold') | |
LastStandStrategy.PlacePlant(3, 6, 'marigold') | |
LastStandStrategy.PlacePlant(3, 4, 'magnetShroom') | |
LastStandStrategy.PlacePlant(3, 5, 'magnetShroom') | |
LastStandStrategy.PlacePlant(3, 5, 'goldMagnet') | |
LastStandStrategy.PlacePlant(3, 7, 'fumeShroom') | |
LastStandStrategy.PlacePlant(3, 8, 'fumeShroom') | |
LastStandStrategy.PlacePlant(3, 7, 'gloomShroom') | |
LastStandStrategy.PlacePlant(3, 8, 'gloomShroom') | |
LastStandStrategy.PlacePlant(3, 4, 'coffeeBean') | |
LastStandStrategy.PlacePlant(3, 7, 'coffeeBean') | |
LastStandStrategy.PlacePlant(3, 8, 'coffeeBean') | |
LastStandStrategy.PlacePlant(3, 6, 'pumpkin') | |
LastStandStrategy.PlacePlant(3, 7, 'pumpkin') | |
LastStandStrategy.PlacePlant(3, 8, 'pumpkin') | |
LastStandStrategy.PlacePlant(4, 1, 'lilyPad') | |
LastStandStrategy.PlacePlant(4, 2, 'lilyPad') | |
LastStandStrategy.PlacePlant(4, 3, 'lilyPad') | |
LastStandStrategy.PlacePlant(4, 4, 'lilyPad') | |
LastStandStrategy.PlacePlant(4, 5, 'lilyPad') | |
LastStandStrategy.PlacePlant(4, 6, 'lilyPad') | |
LastStandStrategy.PlacePlant(4, 7, 'lilyPad') | |
LastStandStrategy.PlacePlant(4, 8, 'lilyPad') | |
LastStandStrategy.PlacePlant(4, 1, 'marigold') | |
LastStandStrategy.PlacePlant(4, 2, 'marigold') | |
LastStandStrategy.PlacePlant(4, 3, 'marigold') | |
LastStandStrategy.PlacePlant(4, 6, 'marigold') | |
LastStandStrategy.PlacePlant(4, 4, 'magnetShroom') | |
LastStandStrategy.PlacePlant(4, 5, 'magnetShroom') | |
LastStandStrategy.PlacePlant(4, 5, 'goldMagnet') | |
LastStandStrategy.PlacePlant(4, 7, 'fumeShroom') | |
LastStandStrategy.PlacePlant(4, 8, 'fumeShroom') | |
LastStandStrategy.PlacePlant(4, 7, 'gloomShroom') | |
LastStandStrategy.PlacePlant(4, 8, 'gloomShroom') | |
LastStandStrategy.PlacePlant(4, 4, 'coffeeBean') | |
LastStandStrategy.PlacePlant(4, 7, 'coffeeBean') | |
LastStandStrategy.PlacePlant(4, 8, 'coffeeBean') | |
LastStandStrategy.PlacePlant(4, 6, 'pumpkin') | |
LastStandStrategy.PlacePlant(4, 7, 'pumpkin') | |
LastStandStrategy.PlacePlant(4, 8, 'pumpkin') | |
LastStandStrategy.PlacePlant(5, 1, 'marigold') | |
LastStandStrategy.PlacePlant(5, 2, 'marigold') | |
LastStandStrategy.PlacePlant(5, 3, 'marigold') | |
LastStandStrategy.PlacePlant(5, 4, 'marigold') | |
LastStandStrategy.PlacePlant(5, 5, 'marigold') | |
LastStandStrategy.PlacePlant(5, 6, 'wallNut') | |
LastStandStrategy.PlacePlant(6, 1, 'marigold') | |
LastStandStrategy.PlacePlant(6, 2, 'marigold') | |
LastStandStrategy.PlacePlant(6, 3, 'marigold') | |
LastStandStrategy.PlacePlant(6, 4, 'marigold') | |
LastStandStrategy.PlacePlant(6, 5, 'marigold') | |
LastStandStrategy.PlacePlant(6, 6, 'marigold') | |
LastStandStrategy.PlacePlant(6, 7, 'marigold') | |
LastStandStrategy.PlacePlant(6, 8, 'garlie') | |
LastStandStrategy.PlacePlant(6, 9, 'garlie') | |
} | |
} | |
class IZombieEndlessStrategy extends Strategy { | |
static MAP_CARD_TO_N := { | |
imp: 1, | |
conedheadZombie: 2, | |
poleVaultingZombie: 3, | |
bucketHeadZombie: 4, | |
bungeeZombie: 5, | |
diggerZombie: 6, | |
ladderZombie: 7, | |
footballZombie: 8, | |
dancingZombie: 9, | |
} | |
static GlitchBungeeZombie() { | |
cardN := IZombieEndlessStrategy.MAP_CARD_TO_N.bungeeZombie | |
cardCoord := IZombieEndlessStrategy.GetCardCoord(cardN) | |
MouseGetPos &xold, &yold | |
Loop 24 | |
{ | |
Click cardCoord.x, cardCoord.y | |
Click xold, yold | |
Sleep 5 | |
} | |
} | |
} | |
#HotIf WinActive(PVZ_WINDOW_TITLE) | |
^esc::ExitApp | |
q::Base.PlaceCard(1) | |
w::Base.PlaceCard(2) | |
e::Base.PlaceCard(3) | |
r::Base.PlaceCard(4) | |
t::Base.PlaceCard(5) | |
a::Base.PlaceCard(6) | |
s::Base.PlaceCard(7) | |
d::Base.PlaceCard(8) | |
f::Base.PlaceCard(9) | |
g::Base.PlaceCard(10) | |
z::Base.AutoClick("z") | |
x::IZombieEndlessStrategy.GlitchBungeeZombie() | |
F1::LastStandStrategy.Start() | |
#HotIf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment