InGame v2.0

Post gaming related scripts
_3D_
Posts: 139
Joined: 29 Jan 2014, 14:40

Class Task - usage

29 May 2016, 04:19

How ClassTask look like in usage? Master Process: "GameHelper"

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Now in master script only control and any process keep its code separately.
Why (new Task()).run().end()?
1. new Task(TaskName) - create control for TaskName (and push it to Task.List - if master going to close all child processes invited to close too).
2. .run() - run TaskName - when process is short and straight it is not necessary Task.List to keep control till the end of Master, but only till TaskName close itself.
3. .end() - unsubscribe TaskName from Task.List and clear .VAR and/or .AHK depend of options this.exit.
This way we have control over "child" process till it in run and release CPU and Memory resources when it close.
DONT FORGET!
Class Task - create and keep only control to the "child" process - not the same process.
Class Task - give possibilities to run MULTI processing - but real multitasking become from windows.
THE LAST started script hold and cover SHORTCUTS of already started scripts (if SHORTCUTS duplication).
Enjoy!
AHKv2.0 use the future now.
_3D_
Posts: 139
Joined: 29 Jan 2014, 14:40

Play media with embeded WMPlayer

30 Jun 2016, 01:57

Inspired from jethrow https://autohotkey.com/board/topic/56987-com-object-reference-autohotkey-v11/page-8#entry399166
class WMPLayer: create and managed hidden Windows Media Player.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Usage:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Work perfect at XP, 7, 8, 8.1, 10.
It is possible to be played many medias at the same time - this case you will need different show() method.
It is possible to manage any WMPlayer instance volume and speed rate.
MSDN WMPlayer documentation: https://msdn.microsoft.com/en-us/library/dd564034

Enjoy!
AHKv2.0 use the future now.
_3D_
Posts: 139
Joined: 29 Jan 2014, 14:40

Using "class" without instantiate.

25 Jul 2016, 04:26

If script will use only ONE instance of "class" - instance not needed:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Script use "class" description name (WMPlayer) without using new command (without making instance variable).
AHKv2.0 use the future now.
_3D_
Posts: 139
Joined: 29 Jan 2014, 14:40

[Function] inList

22 Aug 2016, 07:37

inList(arg, list, [pos])
function create list of positions of the equal to "arg" "list" elements and return number of results. 0 - mean no any equal to "arg".

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Function inList use FOR to loop in all list elements, but function listtostr use pure loop to loop only "indexed" elements.
AHKv2.0 use the future now.
_3D_
Posts: 139
Joined: 29 Jan 2014, 14:40

Using reference as key.

07 Sep 2016, 03:11

In classTask I fill List of tasks in indexed array. This way I know order of creating of tasks but searching inside list is too complicated.
Using reference as key in {key:val} sequence made inserting / deleting / searching easy.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

It is simple example that demonstrate using reference as key.
(+) - extremely simple add / delete and access list elements.
(-) - list element access in random order (due to for nature).
And optimized classTask code:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

AHKv2.0 use the future now.
User avatar
evilC
Posts: 3593
Joined: 27 Feb 2014, 12:30

Re: InGame v2.0

07 Sep 2016, 13:27

Regarding not having to instantiate a class, I generally use this technique:

Code: [Select all] [Download] GeSHi © Codebox Plus

Class MyClass {
static var := MyClass.Init()

Init(){
msgbox
}
}
_3D_
Posts: 139
Joined: 29 Jan 2014, 14:40

Re: InGame v2.0

07 Sep 2016, 15:15

ty for example I like this instance less
guest3456
open my eyes with this post https://autohotkey.com/boards/viewtopic.php?p=95001#p95001
AHKv2.0 use the future now.
_3D_
Posts: 139
Joined: 29 Jan 2014, 14:40

classTask again

14 Sep 2016, 14:10

When I change Task.List to list of references I made major revision of code:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


1. Any new task is subscribed to task list.
2. Winclose("ahk_pid" pid) - instead of name - it is exactly process that need to be closed.
3. WM_CLOSE and WM_QUERYENDSESSION call __myExit that call __onExit tought ExitApp - this way avoid double calling of __onExit

Enjoy!
AHKv2.0 use the future now.
_3D_
Posts: 139
Joined: 29 Jan 2014, 14:40

[FUNCTION] ColorIs()

11 Oct 2016, 14:32

Hi,
In many scripts We need to check what color is at a given coordinate - it is simple task:

Code: [Select all] [Download] GeSHi © Codebox Plus

if PixelGetColor(x, y) == 0xC1C2C3, do action
BUT there different video resolutions and different video cards, so we have a method to check color at "unknown coordinates" with "unknown color" and script to keep the same functionality.
At advance we can have some TRUE colors and some FALSE colors:
0xFFFFFF:1, 0xFFFF00:1 - TRUE colors
0x000000:0, 0x0000FF:0 - FALSE colors
Lets We take the same syntax: <color>:<boolean>
And let We organize colors in list:
0xFFFFFF:1, 0xFFFF00:1, 0x000000:0, 0x0000FF:0
So we have 4 different colors 2xTRUE(1) and 2xFALSE(0).
At this time We have a next syntax:

Code: [Select all] [Download] GeSHi © Codebox Plus

Color=x, y, color:1, color:0

And in different resolutions and different video cards We must need different sign for the same action:

Code: [Select all] [Download] GeSHi © Codebox Plus

[Section1]
USER_check= 100, 100, 0x010203
[Section2]
USER_check= 110, 110, 0x010101
Now in this INI We have 2 different sections Section1 and Section2, but for one action USER_check.
Now We have method to activate the same action with the different attributes.
Let made method to read from this INI

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Function READ from INI record that define coordinates and colors that give TRUE and FALSE.
Now We need to check what color We have at the screen:

Code: [Select all] [Download] GeSHi © Codebox Plus

ColorIs(sec, byRef pix:="", mis:= 998) {
cnt:= 0
loop sec {
tooltip(sec--) ;
pix.c:= PixelGetColor(pix.x, pix.y) ;add c to pix
for key, val in pix
if key == pix.c, return val
sleep(mis)
}
return ""
}
This function return color:action if screen color is equal to color or "" if time out.
I chose "" instead of 0 because in some variations function return 0, 1, 2 and "".
1. Advantage - create virtual class:
The 2 functions creates and modified (class) pixl, used to keep parameters for a given pixel and to communicate between functions. Like result pixl keep coordinates, color actions and color of given coordinate that we get from screen.
2. Advantage - use script like INI file

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

There only one section but demonstrate all explained things.
Enjoy!
Last edited by _3D_ on 19 Oct 2017, 03:22, edited 1 time in total.
AHKv2.0 use the future now.
_3D_
Posts: 139
Joined: 29 Jan 2014, 14:40

IniReadPixel

17 Oct 2016, 15:21

IniReadPixel ini variants

Let We have next source:

Code: [Select all] [Download] GeSHi © Codebox Plus

[Computer-1-1280x800]
OPEN_btn_chek= 100, 100, 0x010203:1, 0x010200:0
OPEN_btn_push= 110, 110
And another source:

Code: [Select all] [Download] GeSHi © Codebox Plus

[Computer-2-1280x800]
OPEN_btn_chek= 100, 100, 0x112233:1, 0x010200:0
OPEN_btn_push= 110, 110
Here We have two sections that have only one color difference.

VARIANT 1

Code: [Select all] [Download] GeSHi © Codebox Plus

[Computer-1-1280x800]
OPEN_btn_chek= 100, 100, 0x010203:1, 0x010200:0
OPEN_btn_push= 110, 110
[Computer-2-1280x800]
OPEN_btn_chek= 100, 100, 0x112233:1, 0x010200:0
OPEN_btn_push= 110, 110
Complete description.

VARIANT 2

Code: [Select all] [Download] GeSHi © Codebox Plus

[Computer-1-1280x800]
OPEN_btn_chek= 100, 100, 0x010203:1, 0x112233:1, 0x010200:0
OPEN_btn_push= 110, 110
Short description but the same functionality due to action OPEN_bnt_chek have two TRUE colors.

Enjoy !
AHKv2.0 use the future now.
_3D_
Posts: 139
Joined: 29 Jan 2014, 14:40

WakeUp-Run-Sleep

30 Oct 2016, 07:16

After several months of testing on my WakeUp robot - I get next conclusions.
1. MS Documentation - not so accurate.
2. MS Windows - cant work fine if system used Sleep-Wakeup.
Edit:
3. Mandatory disable hibernation. (run cmd as administrator then type powercfg -h off)
Now how the robot must to work to avoid MS troubles:

1. Start Robot in clean environment.
This is most important if you have your robot to work longer without strange errors. After several wakeup-sleep cycles script become nonfunctional but restart return script to normal condition (I dont know why and cant investigate). Let just say: this is initial part.

2. If you using computer for other activities.
This part describe the robot action and Ill named: action part.

3. Autorun after restart.

AutoRun part became last in list but Ill explain it first:

Code: [Select all] [Download] GeSHi © Codebox Plus

#SingleInstance force
;Copyright (c) D.Donchev

msgBOX(,"AUTORUN", "RUN Robot after 120 sec", 120) ;inital waiting till computer became ready
run c:\develop\ahkv2.0\robot\action.ahk
Yep, just 2 lines. And let name it: AutoRun.ahk
1. You must copy Autohotkey.exe near to initial script AutoRun.ahk.
2. You must rename Autohotkey.exe to AutoRun.exe
3. You must plase shortcut of AutoRun.exe to your startup folder (Win+R then write shell:startup).
MS not start .ahk files no matter if it registered or no for known extensions.

Action part the part in the middle.
It is main action that we need but in most cases we need to check and reorganizing this part - so it must be written that way to avoid forced running easily.

Code: [Select all] [Download] GeSHi © Codebox Plus

aTime:= IniRead(A_ScriptName, "Status", "NextRun", A_Now) ;read when will be next run
;if record missing A_Now will be return as default value
if DateDiff(A_Now, aTime, "S") < 0 ;if > (after time) or == (in time) run action
{ msgBOX(,,"Run at " FormatTime(aTime, "HH:mm:ss"),5)
ExitApp
}
If not still the time Exit. This simple lines avoid accidental running.
DONT FORGET: script must end with /*

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

You can use other ini file of course and then this part not needed A_ScriptName must be changed to your.ini.

Initial part. LOL "initial" but last in line why?
I named this part initial because it initiate the whole action sequence. At my example this section just will restart computer.

Code: [Select all] [Download] GeSHi © Codebox Plus

#SingleInstance force
;Copyright (c) D.Donchev

msgBOX(,"ATENTION", "RESTART after 120 sec", 120) ;waiting user to became ready
Shutdown 6

Conclusions:
It is sequence of actions that guarantee wake up running of main action in clear environment (after reset) wait user to end his activities if have (before restart) in appropriate time, do the action and sleep again.
My robot wake-run-sleep in 323 seconds any 6 hours.

Enjoy!
AHKv2.0 use the future now.
_3D_
Posts: 139
Joined: 29 Jan 2014, 14:40

EndTask

11 Jan 2017, 13:34

Hi,
In my practice have an "great" programmer with "great" programs. Unfortunately some, probably most, have problems to catch and to execute system event messages. So SHUTDOWN, RESTART, LOG OFF and so on cant be properly do it due to cycling inside the "programs".
I just write a simple script that KILL looped processes.
VARIANT 1:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

It work perfect extremely small code BUT there a maintenance problem, just ONE. It is extremely unreadable and editable for ordinary person.
VARIANT 2:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

What is goal here - you can call by phone to pretty girl and ask her to white at the end of file new process. :bravo:

Enjoy!
AHKv2.0 use the future now.
_3D_
Posts: 139
Joined: 29 Jan 2014, 14:40

for vs loop in array

30 Apr 2017, 12:47

Hi
There is a simple test that represent 3 different search methods in array (actually in Autohotkey no arrays but lists).

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

First test with array of 10 elements and we search value 5
variant 1 - 421
variant 2 - 390
variant 3 - 500
what many operations inside loop - so low

Second test with array of 100 elements and we search value 55
variant 1 - 1859
variant 2 - 2360
variant 3 - 2828
amazing result

So for faster than loop in large arrays.
If you need to search inside arrays use for to get best performans.
Enjoy!
AHKv2.0 use the future now.
User avatar
SnowFlake
Posts: 365
Joined: 28 Apr 2015, 05:41
Google: floowsnaake
GitHub: floowsnaake
Contact:

Re: InGame v2.0

30 Apr 2017, 15:05

i don't know how to use any of your scripts sorry
:yawn:
_3D_
Posts: 139
Joined: 29 Jan 2014, 14:40

Re: InGame v2.0

15 May 2017, 14:29

RegExNMatch Function

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

There no "ALL" option at the moment but Ill think about.
Last edited by _3D_ on 25 May 2017, 04:11, edited 1 time in total.
AHKv2.0 use the future now.
_3D_
Posts: 139
Joined: 29 Jan 2014, 14:40

Re: InGame v2.0

15 May 2017, 14:36

SnowFlake wrote:i don't know how to use any of your scripts sorry
You don`t need know - you need to understand.
AHKv2.0 use the future now.
User avatar
SnowFlake
Posts: 365
Joined: 28 Apr 2015, 05:41
Google: floowsnaake
GitHub: floowsnaake
Contact:

Re: InGame v2.0

15 May 2017, 15:07

then teach me/show me how to understand and also im sure a lot of other ppl want to know and understand also :)
:yawn:
_3D_
Posts: 139
Joined: 29 Jan 2014, 14:40

Re: InGame v2.0

23 May 2017, 14:10

In this post I explain how to OCR digits https://autohotkey.com/boards/viewtopic.php?f=19&t=2400#p14243
There many many changes that I forgоt to post so:

Code: [Select all] [Download] GeSHi © Codebox Plus

ocrGetDigit(recBmp, color, varia, nores:= "") {
static _i:= 10, _bmp:= [] ;still not possible initializing static
;first time loop 10
;second time loop 0 => no loop by language default
Loop _i
_bmp[_i]:= Gdip_CreateBitmapFromFile(".\ocr\" --_i ".bmp") ;it work perfect
Loop 10
if ocrBWCompare(recBmp, _bmp[A_Index-1], color, varia), return A_Index-1
return nores ;added extra return if no match
}
Shorter code - just optimized - there only one arithmetic operation in first loop (--_i) for both sides.

Code: [Select all] [Download] GeSHi © Codebox Plus

			mX:=X+295, mY:=Y+147, itemP:= "" ;ocr item price RED digits
loop 10 {
bmp:= Gdip_BitmapFromScreen(mX "|" mY "|5|7")
itemP .= ocrGetDigit(bmp, 0xFF0000, 50, 0) ;concatenate as string
Gdip_DisposeImage(bmp)
mX += (mod(A_Index, 3) == 1)? 9: 6
}
itemP += 0 ;force conversion to value
Shorter code - the same - calculations is replaced to concatenation and added forced conversion to value (simple enough).
Enjoy!
Last edited by _3D_ on 25 May 2017, 08:32, edited 1 time in total.
AHKv2.0 use the future now.
_3D_
Posts: 139
Joined: 29 Jan 2014, 14:40

RegExNMatch

25 May 2017, 08:17

RegExNMatch - revised.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Changes:
1. while Numbers-- instead of loop Numbers - negative value produced loop until break.
2. check if v.count() - stop iterations if pattern match nothing (void looping).

Enjoy!
AHKv2.0 use the future now.
_3D_
Posts: 139
Joined: 29 Jan 2014, 14:40

dd_ToolTip

28 May 2017, 17:09

Function dd_ToolTip - revised

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Function dd_ToolTip is usable when in one place you set message and in other place you need to add extra text to message. In example sleep and count.

Enjoy!
AHKv2.0 use the future now.

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 2 guests