Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Inventory Item Recognition (Organizational)


  • Please log in to reply
2 replies to this topic
Yavrashu
  • New members
  • 1 posts
  • Last active: Sep 29 2015 12:23 PM
  • Joined: 23 Sep 2015

Hello! I'm just getting started with AHK and am absolutely loving it! It's a lot of fun to mess around and discover new possibilities with.

Ok, on now to the question at hand...

 

 

Description:

I'm working on a script that is organizational in nature. My character performs an action, an item is, at times, collected into its inventory. The chance of the item being collected into the inventory is, of course, based on the game's algorithmic check and balances behind the scenes.

 

So, basically, I'm looking for a way for my script to be able to recognize that an item has been gathered into my inventory and, to which location (X, Y) in the inventory it was moved.

 

The various items, for the most part, have differing icons. My focus, for now, is on these that are more easily recognizable due to the differing icons.

 

So, of course, I was looking through the help files and a couple script examples others have done. The script examples I have available to study do not do anything of the sort, and are more simplistic than even what I'm describing here. I see possibilities within the help files, but am at a loss as to how to most effectively perform this task.

 

My initial idea was to have the recognition based on the color value, but that presents its own problems.

 

 

Task Breakdown:

Item moves into a slot within character's inventory

Script needs to recognize the item itself, as well as the exact screen position of the new item

If new item at X,Y location is item B, for example, the script would perform an action (ie. MouseClickDrag, etc.)

If script knows that no new items are in the character's inventory, at this point in the loop, it performs the appropriate action

 

 

Current Questions:

What would be the most effective functions, commands, etc. to use in order to have the script be able to:

  1. recognize a new item is in the character's inventory at a predetermined time in the loop?
  2. recognize the location of the new item within the character's inventory?
  3. recognize the "identity" of only the new item?

 



SnowFlake_FlowSnake
  • Members
  • 845 posts
  • Last active: Jan 24 2016 05:24 PM
  • Joined: 08 Oct 2012

hi

 

could you plz tell me what game it is and also a picture of the inventor system?


  • Download link of my scripts on Autohotkey.com 2/10/2015 [DOWNLAND]
  • Contact Info:  https://github.com/floowsnaake //  FloowSnaake(A)gmail.com
  • IF you need Help send me a PM,Email or Post on Github

  • Quote by tank  Posted 29 September 2015 - 06:14 PM

  • "Eventually i will find a way to convert the DB back to PHPBB3. but i dont have the bandwidth right now. No one that has tried has had success. It is the Only way i can keep this open is if i could successfully convert it."

floodindahood
  • Members
  • 383 posts
  • Last active: Apr 20 2018 01:45 PM
  • Joined: 21 Oct 2011
The only hurdle in what you're trying to do is detecting what is in your inventory.
Everything else can be done with simple sorting, mousemoves etc etc.

Assuming the game doesn't create comfy log files of your inventory, there is basically 2 options for detecting what's in your inventory and those are recognizing based on pixel color(s) and memory reading.
The latter would probably be an unbreakable wall unless you're fairly comfy with memory reading already.
This leaves us with pixel color detection.
The easiest solution would be using "imagesearch". You'd have to grab a picture of each item that you might pick up and then it'll be just looping through every image to get matches, calculating their row & column based on their location and submitting that info to a variable or an array.
inventory_x := 100 ;the x value of the top-left corner of your inventory in the game client
inventory_y := 100 ;the y value of ......
slotcount_x := 5   ;how many item slots on x axis
slotcount_y := 5   ;how many item ....
slot_width := 30   ;the width of each slot in pixels on x axis
slot_width := 30   ;the height of .....
wingetpos,wx,wy,,,targetwindow ;let's get the x and y of the targetwindow

;to reduce the size of the search area
wx:=wx-inventory_x
wy:=wy-inventory_y
ww:=slotcount_x*slot_width
wh:=slotcount_y*slot_height
;;to reduce the size of the search area

loop,%a_scriptdir%\images\*.png ;parse through every item's image you've place into "..\images\" folder
{
	imagesearch,found_x,found_y,%wx%,%wy%,%wh%,%ww%,%A_LoopFileFullPath%
	row := ceil((found_y-inventory_y)/slot_height)		;maths to calculate it's row
	column := ceil((found_x-inventory_x)/slot_width)	;maths to calcluate it's column
	MsgBox % "image " a_loopfilename " is on row " row " and column " column
	;here you'd add the location to an array or variable, up to you
}
The faster alternative would be using pixelgetcolor to get only few pixels per item and matching them to colors you've grabbed beforehand.
inventory_x := 100 ;the x value of the top-left corner of your inventory in the game client
inventory_y := 100 ;the y value of ......
slotcount_x := 5   ;how many item slots on x axis
slotcount_y := 5   ;how many item ....
slot_width := 30   ;the width of each slot in pixels on x axis
slot_width := 30   ;the height of .....
fileread,matchList,matchFile.txt
/*contents of matchFile.txt for 1 pixel check would be along the lines of,

flamboyant sword;0xFF00FF
extralicious booty shield;0xA0F0B0

~for multiple checks,

flamboyant sword;0xFF00FF,0x00FF00;0xDD00DD
extralicious booty shield;0xA0F0B0,0x233445,0x455667

*/
loop % slotcount_y {
	row := A_Index
	loop % slotcount_x {
		column := column
	
		search_x := inventory_x+((row-1)*slot_width)+(slot_width/2)
		search_y := inventory_y+((column-1)*slot_height)+(slot_height/2)
		;for 1 pixel check
		pixelgetcolor,foundColor, %search_x%, %search_y%
		if (instr(matchList,foundColor)) {
			loop,parse,matchList,`r`n
			{
				stringsplit,current_item,a_loopfield,`,
				if (current_item2 == foundColor && a_loopfield)
				{
					MsgBox % "item " current_item1 " is on row " row " and column " column
					;here you'd add the location and a_loopfilename to an array or variable, up to you
				}
			}
		}
		;1 pixel check, end
		
		;for multipixel check for higher accuracy
		foundColors := ""
		loop, 5 {
			
			pixelgetcolor,foundColor, % search_x+a_index, %search_y%
			foundColors .= foundColor ","
		}
		foundColors := rtrim(foundColors,",")
		if (instr(matchList,foundColor)) {
			loop,parse,matchList,`r`n
			{
				stringsplit,current_item,a_loopfield,`;
				if (current_item2 == foundColors && a_loopfield)
				{
					MsgBox % "item " current_item1 " is on row " row " and column " column
					;here you'd add the location and a_loopfilename to an array or variable, up to you
				}
			}
		}
		;multipixel check, end
	}
}