-
Notifications
You must be signed in to change notification settings - Fork 0
/
starcraft2.lua
692 lines (572 loc) · 18.3 KB
/
starcraft2.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
-- Version 1.5
-- 25.02.2013
function OnEvent(event, arg, family)
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
-- On ACTIVATED
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
if (event=="PROFILE_ACTIVATED" and GetRunningTime()< 50) then
OutputLogMessage("==================== START SCRIPT ====================\n");
ReleaseAll();
ClearLog();
SetMKeyState(1); -- Force M1
-- INIT Variables for all Race
SC2WOL = "1";
SC2HOTS = "2";
CURRENTGAME = SC2HOTS;
ARMY1 = "1";
ARMY2 = "2";
BASES = "5";
SAVEDACTION = "0";
SCV_LARVA="s";
DRONE="d";
PROBE="e";
VAR_start=0;
-- Init globals variables for Zerg
QUEEN = "9";
QueenOK=0;
TimeLastLarva=0;
TimeSinceLastLarva=0;
-- Init globals variables for Terran
-- Init globals variables for Protoss
end
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
-- On DEACTIVATED
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
if (event=="PROFILE_DEACTIVATED") then
-- switch M2 and M1 at desactivation for keyboard and G13
--SetMKeyState(2,"kb");
--SetMKeyState(2,"lhc");
--SetMKeyState(1,"kb");
--SetMKeyState(1,"lhc");
end
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
-- On every event do
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
showMousePosition();
OutputLogMessage("OnEvent = %s, arg = %s\n", event, arg);
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
-- M1 for Zerg
if (event=="M_PRESSED" and arg==1) then
-- Init locals variables for Zerg
--SetBacklightColor(0,167,0);
Race=1;
SelectLarva="s"; -- Key for zerg larva
VAR_CreatePeon="d" -- Key for create peon
VAR_CreateArmy1="z"; -- Zergling
VAR_CreateArmy2="r"; -- Roach
VAR_CreateArmy3="h"; -- Hydralisk
VAR_CreateArmy4="t"; -- Mutalisk
end
-- M2 for Terran
if (event=="M_PRESSED" and arg==2) then
--SetBacklightColor(0,0,167);
Race=2;
VAR_CreatePeon="s"; -- Key for create peon
end
-- M3 for Protoss
if (event=="M_PRESSED" and arg==3) then
--SetBacklightColor(167,0,0);
Race=3;
VAR_CreatePeon="e"; -- Key for create peon
end
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
-- G1 G2 G7 and G8 For M1, M2 and M3 (All race)
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
---------------------------------------------------
-- G1,
---------------------------------------------------
if (event=="G_PRESSED" and arg==1) then
Init(SC2HOTS);
end
---------------------------------------------------
-- G7, new game
---------------------------------------------------
if (event=="G_PRESSED" and arg==7) then
end
---------------------------------------------------
-- G11, Split units
---------------------------------------------------
if (event=="G_PRESSED" and arg==11) then
splitUnits();
end
---------------------------------------------------
-- G2, Start
---------------------------------------------------
if (event=="G_PRESSED" and arg==2) then
--OutputLogMessage("OnEvent = %s, arg = %s\n", event, arg);
OutputLogMessage("VAR_Start Debut = %s\n",VAR_start);
start();
OutputLogMessage("VAR_Start Fin = %s\n",VAR_start);
end
---------------------------------------------------
-- G8, Kitte
---------------------------------------------------
if (event=="G_PRESSED" and arg==8) then
kitteWithRangedUnits();
end
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
-- M1 for Zerg
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
if (Race==1) then
------------------------------------------------------------------------------------------------------
-- On every Zerg event do
------------------------------------------------------------------------------------------------------
if QueenOK==1 then
TimeSinceLastLarva=GetRunningTime()-TimeLastLarva;
end
OutputLogMessage("TimeSinceLastLarva = %s\n", TimeSinceLastLarva);
-- check if must make larva
if QueenOK==1 and TimeSinceLastLarva > 35000 then
MakeLarva()
end
---------------------------------------------------
-- G3, Mass Zerglings
---------------------------------------------------
if (event=="G_PRESSED" and arg==3) then
--saveCurrentAction();
masseProduction(25, VAR_CreateArmy1);
-- Select transformation larva and add to group 1
AddGroup("1",1,1)
--goToSavedAction();
end
---------------------------------------------------
-- G9, Mass Roach
---------------------------------------------------
if (event=="G_PRESSED" and arg==9) then
masseProduction(25, VAR_CreateArmy2);
-- Select transformation larva and add to group 2
AddGroup("2",1,1)
end
---------------------------------------------------
-- G4, Mass Hydralisk
---------------------------------------------------
if (event=="G_PRESSED" and arg==4) then
masseProduction(25, VAR_CreateArmy3);
-- Select transformation larva and add to group 3
AddGroup("3",1,1)
end
---------------------------------------------------
-- G10, Mass Mutalisk
---------------------------------------------------
if (event=="G_PRESSED" and arg==10) then
masseProduction(25, VAR_CreateArmy4);
-- Select transformation larva and add to group 4
AddGroup("4",1,1)
end
---------------------------------------------------
-- G5, Nothing
---------------------------------------------------
if (event=="G_PRESSED" and arg==5) then
--Nothing
end
---------------------------------------------------
-- G6, Nothing
---------------------------------------------------
if (event=="G_PRESSED" and arg==7) then
--Nothing
end
---------------------------------------------------
-- G12, Queen make larva
---------------------------------------------------
if (event=="G_PRESSED" and arg==12) then
MakeLarva()
end
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
-- M1 for Terran
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
elseif (Race==2) then
-- Nothing at the moment
------------------------------------------------------------------------------------------------------
-- On every Terran event do
------------------------------------------------------------------------------------------------------
--Nothing
---------------------------------------------------
-- G3, Nothing
---------------------------------------------------
if (event=="G_PRESSED" and arg==3) then
--Nothing
end
---------------------------------------------------
-- G9, Nothing
---------------------------------------------------
if (event=="G_PRESSED" and arg==9) then
--Nothing
end
---------------------------------------------------
-- G4, Nothing
---------------------------------------------------
if (event=="G_PRESSED" and arg==4) then
--Nothing
end
---------------------------------------------------
-- G10, Nothing
---------------------------------------------------
if (event=="G_PRESSED" and arg==10) then
--Nothing
end
---------------------------------------------------
-- G5, Nothing
---------------------------------------------------
if (event=="G_PRESSED" and arg==5) then
--Nothing
end
---------------------------------------------------
-- G6, Nothing
---------------------------------------------------
if (event=="G_PRESSED" and arg==7) then
--Nothing
end
---------------------------------------------------
-- G12, Nothing
---------------------------------------------------
if (event=="G_PRESSED" and arg==12) then
MakeLarva()
end
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
-- M3 for Protoss
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
elseif (Race==3) then
-- Nothing at the moment
------------------------------------------------------------------------------------------------------
-- On every Protoss event do
------------------------------------------------------------------------------------------------------
--Nothing
---------------------------------------------------
-- G3, Nothing
---------------------------------------------------
if (event=="G_PRESSED" and arg==3) then
--Nothing
end
---------------------------------------------------
-- G9, Nothing
---------------------------------------------------
if (event=="G_PRESSED" and arg==9) then
--Nothing
end
---------------------------------------------------
-- G4, Nothing
---------------------------------------------------
if (event=="G_PRESSED" and arg==4) then
--Nothing
end
---------------------------------------------------
-- G10, Nothing
---------------------------------------------------
if (event=="G_PRESSED" and arg==10) then
--Nothing
end
---------------------------------------------------
-- G5, Nothing
---------------------------------------------------
if (event=="G_PRESSED" and arg==5) then
--Nothing
end
---------------------------------------------------
-- G6, Nothing
---------------------------------------------------
if (event=="G_PRESSED" and arg==7) then
--Nothing
end
---------------------------------------------------
-- G12, Nothing
---------------------------------------------------
if (event=="G_PRESSED" and arg==12) then
MakeLarva()
end
end
end
---------------------------------------------------
-- Functions
---------------------------------------------------
function Init(gameMode)
CURRENTGAME = gameMode;
OutputLogMessage("VAR_Start Init = %s\n",VAR_start);
ReleaseAll();
ClearLog();
VAR_start=0;
QueenOK=0;
TimeLastLarva=0;
TimerQueen=0;
end
---------------------------------------------------
function kitteWithRangedUnits()
f=0;
while f<5 do
PressAndReleaseMouseButton(3);
Sleep(math.random(1050, 1100)); -- //marine shoot at 0.8608
PressAndReleaseKey("S"); -- //Stop the units
Sleep(math.random(100, 110));
f = f+1;
end
end
---------------------------------------------------
function splitUnits()
PressAndReleaseKey(ARMY1);
MoveMouseTo(25476, 55756);
PressAndReleaseMouseButton(1);
PressAndReleaseKey(ARMY1);
MoveMouseTo(25476, 55756);
PressAndReleaseMouseButton(1);
PressAndReleaseKey(ARMY1);
MoveMouseTo(27969, 55756);
PressAndReleaseMouseButton(1);
PressAndReleaseKey(ARMY1);
MoveMouseTo(29813, 55574);
PressAndReleaseMouseButton(1);
PressAndReleaseKey(ARMY1);
MoveMouseTo(31384, 55392);
PressAndReleaseMouseButton(1);
-- Mouse is at 23871, 55392
-- Mouse is at 25476, 55756
-- Mouse is at 27969, 55756
-- Mouse is at 29813, 55574
-- Mouse is at 31384, 55392
-- Mouse is at 33194, 55574
-- Mouse is at 35380, 55635
-- Mouse is at 37327, 55392
-- Mouse is at 23393, 58793
-- Mouse is at 25408, 58611
-- Mouse is at 27491, 59340
-- Mouse is at 29950, 59097
-- Mouse is at 31316, 59097
-- Mouse is at 33331, 59401
-- Mouse is at 35482, 58975
-- Mouse is at 37224, 59036
-- Mouse is at 23803, 62680
-- Mouse is at 25510, 62498
-- Mouse is at 27491, 62559
end
---------------------------------------------------
function MakeLarva()
saveCurrentAction();
i=0;
while i<5 do
i = i+1;
PressAndReleaseKey(QUEEN);
Sleep(math.random(10, 20));
PressAndReleaseKey("v");
-- Center mouse on screen and click the left mouse button
MoveMouseTo(32817,23600);
Sleep(math.random(10, 20));
PressAndReleaseKey("backspace")
Sleep(math.random(30, 50));
PressAndReleaseMouseButton(1);
Sleep(math.random(10, 20));
end
goToSavedAction();
TimeLastLarva= GetRunningTime();
QueenOK=1;
end
---------------------------------------------------
function showMousePosition()
x, y = GetMousePosition();
OutputLogMessage("Mouse is at %d, %d\n", x, y);
end
---------------------------------------------------
function saveCurrentAction()
OutputLogMessage("saveCurrentAction\n");
PressKey("lctrl")
Sleep(10);
PressAndReleaseKey(SAVEDACTION);
Sleep(10);
ReleaseKey("lctrl");
Sleep(10);
end
---------------------------------------------------
function goToSavedAction()
OutputLogMessage("goToSavedAction\n");
Sleep(10);
PressAndReleaseKey(SAVEDACTION, SAVEDACTION);
end
---------------------------------------------------
function masseProduction(amount, UnitType)
OutputLogMessage("MASSE\n");
OutputLogMessage(BASES,"\n");
PressAndReleaseKey(BASES);
Sleep(math.random(10, 20));
if (Race==1) then -- Zerg case
OutputLogMessage("======== ZERG ========\n");
PressAndReleaseKey(SelectLarva);
Sleep(math.random(10, 20));
elseif (Race==2) then -- Marine case
OutputLogMessage("Marine");
elseif (Race==3) then -- Protoss case
OutputLogMessage("Protoss");
end
while amount > 0 do
PressAndReleaseKey(UnitType);
Sleep(math.random(10, 20));
amount = amount - 1;
end
--Sleep (270);
--MoveMouseTo(22460, 55207);
OutputLogMessage("END");
end
---------------------------------------------------
function start()
-- 1st run
if VAR_start==0 then
OutputLogMessage("Function start");
if CURRENTGAME == SC2WOL then
SelectWorkers(0);
UnSelect(3);
AddGroup("0",0,0);
PressAndReleaseKey("0");
UnSelect(2);
AddGroup("8",0,0);
SelectWorkers(0);
end
PressAndReleaseKey("backspace");
Sleep(math.random(40, 50));
MoveMouseTo(32819, 23566);
PressAndReleaseMouseButton(1);
PressKey("lctrl");
Sleep(math.random(10, 20));
PressAndReleaseKey(BASES);
Sleep(math.random(10, 20));
ReleaseKey("lctrl");
Sleep(math.random(10, 20));
CreatePeonRandom();
PressAndReleaseKey(BASES);
Sleep(math.random(10, 20));
SelectWorkers(1);
VAR_start=1;
elseif VAR_start==1 then
PressAndReleaseKey("0");
VAR_start=2;
elseif VAR_start==2 then
PressAndReleaseKey("8");
VAR_start=3;
elseif VAR_start==3 then
CreatePeon(1);
end
end
---------------------------------------------------
function CreatePeon(amount)
OutputLogMessage("CreatePeon Start\n");
OutputLogMessage(BASES,"\n");
PressAndReleaseKey(BASES);
if (Race==1) then -- Zerg case
OutputLogMessage("======== ZERG ========\n");
PressAndReleaseKey(SelectLarva);
Sleep(math.random(10, 20));
elseif (Race==2) then -- Terran case
OutputLogMessage("Terran");
elseif (Race==3) then -- Protoss case
OutputLogMessage("Protoss");
end
i=0;
while i<amount do
PressAndReleaseKey(VAR_CreatePeon);
Sleep(math.random(10, 20));
i=i+1;
end
OutputLogMessage("CreatePeon END\n");
end
---------------------------------------------------
function CreatePeonRandom()
OutputLogMessage("CreatePeonRandom Start\n");
OutputLogMessage(BASES,"\n");
PressAndReleaseKey(BASES);
PressAndReleaseKey(SCV_LARVA);
Sleep(math.random(10, 20));
PressAndReleaseKey(DRONE);
Sleep(math.random(10, 20));
PressAndReleaseKey(PROBE);
Sleep(math.random(10, 20));
OutputLogMessage("CreatePeonRandom END\n");
end
---------------------------------------------------
function UnSelect(number)
OutputLogMessage("started unselect\n");
PressKey("lshift");
Sleep(math.random(10, 20));
MoveMouseTo(23564,55693);
i=0;
while i<number do
PressAndReleaseMouseButton(1);
Sleep(math.random(10, 20));
i = i + 1;
end
ReleaseKey("lshift");
MoveMouseTo(32819, 23566);
OutputLogMessage("end unselect\n");
end
---------------------------------------------------
function SelectWorkers(Action)
--Action=0 only select
--Action=1 add
OutputLogMessage("started selectWorkers action : %s\n",Action);
PressKey("lctrl");
Sleep(math.random(10, 20));
if Action==1 then
PressKey("lshift");
Sleep(math.random(10, 20));
end
PressAndReleaseKey("F1");
Sleep(math.random(10, 20));
if Action==1 then
ReleaseKey("lshift");
Sleep(math.random(10, 20));
end
ReleaseKey("lctrl");
Sleep(math.random(10, 20));
OutputLogMessage("end selectWorkers\n");
end
---------------------------------------------------
function AddGroup(Group,Action,Safe)
--Action=0 only select
--Action=1 add
--Safe=1 add only same type of the 1st unit
if Safe==1 then
OutputLogMessage("AddGroup\n");
Sleep(math.random(10, 20));
MoveMouseTo(23564,55693);
Sleep(math.random(10, 20));
PressKey("lctrl");
Sleep(math.random(10, 20));
PressAndReleaseMouseButton(1);
Sleep(math.random(10, 20));
ReleaseKey("lctrl");
Sleep(math.random(10, 20));
else
PressAndReleaseKey(Group);
end
if Action==0 then
PressKey("lctrl");
Sleep(math.random(10, 20));
elseif Action==1 then
PressKey("lshift");
Sleep(math.random(10, 20));
end
PressAndReleaseKey(Group);
Sleep(math.random(10, 20));
if Action==0 then
ReleaseKey("lctrl");
Sleep(math.random(10, 20));
elseif Action==1 then
ReleaseKey("lshift");
Sleep(math.random(10, 20));
end
PressAndReleaseKey(Group);
end
---------------------------------------------------
function ReleaseAll()
ReleaseKey("lctrl");
ReleaseKey("lshift");
end