Jump to content

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

ImageSearch


  • Please log in to reply
31 replies to this topic
girlgamer
  • Moderators
  • 3263 posts
  • Last active: Feb 01 2015 09:49 AM
  • Joined: 04 Jun 2010
Then here's what you do to get started with the task of programming a routine to find and harvest a single tree. Once you have that you can expand it for any tree on the screen...
The ultimate key to programming is to have a detailed idea of exactly what has to be accomplished to get the job done. so first you have to have a "job description". Example: Find and harvest a single tree in the PkHonor RSPS
2nd step is an outline of those actions that will accomplish the job as described in "job description"
to do that you, if possible, have to walk the steps, either in the actual environment where the job has to be completed ( in this case, ingame) or you need to create an environment that mimic's the real environment that the program will have to function in)
In the case of game scripting the 2nd step is fairly easy if a bit boring. you simply (and repeatedly) do the steps necessary to accomplish the job. Write down each step you do in as much detail as possible. Do all necessary steps to finish the job. The outline of steps then becomes the outline for your script. each step in the outline becomes a comment or remark statement in the script you want to create. So the top level design would look something like this...
; script to harvest a single tree in PkHonor
; step 1: search the screen for a tree
;     the trick here is how to tell your script what a tree looks like on the screen
;     especially when the tree colors and shapes are changing
;     step 1a: if there are no trees on the screen
;          quit trying to harvest
;          go to a new location 
;          go back to step 1
; step 2: move to tree
;     get the location of the tree on the screen
;     move your character to that location
; step 3: begin cutting down tree
;     do one or more actions needed to cut down tree
;          note actions may change depending on what tool you use for cutting
;          what kind of tree it is...
;          if you get attacked while harvesting...
;          other unforseen circumstances. like a bio break, etc
; step 4: is tree down?
;     trick here is how to tell if the tree is down? 
;     step4a: if yes
;          pick up tree loot if any
;          go back to step 1
;     step4b: If no
;          either wait for tree to fall down or...
;          go back to step 3 and keep wacking on tree
; step5: end routine
;     given that we're in an infinite loop above how 
;     would you ever get here?
What makes this whole thing a long term exercise is that the more you fill in the details of what you have to do the clearer the idea of what you need to do becomes. It's something called an "iterative procedure" where you write stuff down, try it out, figure out what's messed up, go fix it, write what you did to fix it down, go back to the beginning and do it all over again. And you do that until the job is as complete as you want to make it.

The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ●
MMO Fighter   KeyLooperDemo   Key Spammer   TinyClickRecorder  GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
Rock-on%20kitten.gif


Enzy
  • Members
  • 16 posts
  • Last active: Aug 07 2012 04:25 AM
  • Joined: 07 Aug 2012
how can i get the detail of the tree well the job description and also the enviroment of the area. is there a turtorial i can follow upon on so i can get a brief example of what i gotta do and how can i do it.

girlgamer
  • Moderators
  • 3263 posts
  • Last active: Feb 01 2015 09:49 AM
  • Joined: 04 Jun 2010
How to learn computer programming...
http://norvig.com/21-days.html

The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ●
MMO Fighter   KeyLooperDemo   Key Spammer   TinyClickRecorder  GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
Rock-on%20kitten.gif


Enzy
  • Members
  • 16 posts
  • Last active: Aug 07 2012 04:25 AM
  • Joined: 07 Aug 2012
that relates to java c++ and some other languages but i wask asking for some tutorials not how long etc it will take.

TakeNoPrisoners
  • Guests
  • Last active:
  • Joined: --
First rule of programming: If you can't describe what you have to do to make the computer do a certain thing then you can't program for it. With scripting that's a pretty easy task. You simply do the steps and write them down. With other programming languages it's not so straightforward.

Once you have the steps written down you pick the commands, using the AutoHotkey Help file to find a command or commands that do that step.

Insert that command into the text using the editor. Find, make, generate or otherwise create the arguments the command needs in order to work. Add those to the command you just put in the text.

Test the command by running the script to see if it works. If it doesn't, figure out what's wrong and fix it.

Then move to the next step and repeat the entire process.

That's the rock bottom simplest explanation you're likely to find anywhere on the internet.


Learn to ask the right questions when making your program. That's a skill that only develops over time. Along with "thinking outside the box". That means that sometimes you want to chop down a tree you look at it's roots first. "Where is the color NOT changing?" is one question to ask. Another question on color cycling is. "Can I read the colors til it finds one that works so i can start chopping?"
Note: if ImageSearch doesn't work for you maybe PixelGetColor will. Another question is, "What if i could use only part of the whole color? The green for example or the blue or the red part?" And "How would i split the colors up to do that?" These are the kinds of questions that need to be asked. And that experience only comes by digging in and starting the script. And that's the reason I said to do one step and test it til it works. If you can't get past that step, doing more steps isn't really going to help.

TakeNoPrisoners
  • Guests
  • Last active:
  • Joined: --
Oh, and one other thing, besides being able to find and read the help file. The most important command in any computer language you will ever learn is the comment statement. Use it -- liberally and often.

Enzy
  • Members
  • 16 posts
  • Last active: Aug 07 2012 04:25 AM
  • Joined: 07 Aug 2012
i know what your saying but i tried pixle search but the format of it is a bit confusing and also i can't make pixlesearch work also tried at an if statement and it always fails out on the else and if i try to fix that the script does nothing.

TakeNoPrisoners
  • Guests
  • Last active:
  • Joined: --
then lets break it down...
Searches a region of the screen for a pixel of the specified color.
PixelSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ColorID [, Variation, Fast|RGB]

So first it's a search function. The outputs x and y are where it finds the color (colorid) somewhere in the search range (x1,y1 (upper left corner) x2,y2(lower right corner)) of some screen or window as set by CoordMode That's if it can find the color at all. If the colors can vary by some degree then the variation is how much the colors can be different (the red the green and the blue) from the color you told it to search for (color ID) Since there are two ways to describe a color to the script (BlueGreenRed form and RedGreenBlue blue form) you will need to tell the search command what mode you want to use with the RGB flag. The form you tell it to search for is also the form the colorID has to be in as well. If the color id is in BGR form and you tell the command to use the RGB form then the command will fail. The two forms have to match to succeed.
That's how it works. But maybe you don't really need a pixel search...

Maybe you just need a pixel get color and a loop.... could you figure out how to work that one?. If you know the spot where the tree is.... you could test your theory on that spot to see if it worked? Remember you're testing your script. You're trying to teach it to see what you see.

TakeNoPrisoners
  • Guests
  • Last active:
  • Joined: --
Thing is with pixel search you're trying to find a tree but the script doesn't know what color a tree really is.. so first you teach it what color a tree is then you can send it out to go find other trees that have that color someplace else on the screen.

Enzy
  • Members
  • 16 posts
  • Last active: Aug 07 2012 04:25 AM
  • Joined: 07 Aug 2012
i used window spy for it and it never worked

TakeNoPrisoners
  • Guests
  • Last active:
  • Joined: --
if one tool doesn't work either try another or make one.... maybe this one will work for you?

Try this little routine from my toolkit library. I use it a lot. Press Shift-Alt-g to check locations and colors on the screen. Check the tooltip for how to grab the color and location to the clipboard. use Shift-Alt-Esc to end the script. Analyze it. See how it works. Try to figure out why certain commands are in certain places. That's another way to learn too.

#NoEnv
#singleInstance, Force
#MaxThreadsPerHotkey, 2
SetBatchLines, -1
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen
CoordMode, Tooltip, Screen
SetTitleMatchMode, 2
SetKeyDelay -1
SendMode InputThenPlay


;------------------------------------------------
; loc/color grabber with timer display
; Use the middle mouse button to exit the routine
; Because some applications change the color of
; or highlight the the item the mouse is hovering
; over this this routine grabs two colors from 
; the selected location -- the color displayed 
; when the mouse is on the location and the color 
; that is displayed when the mouse is not on the 
; location. This method allows you to choose which
; color choice best works for you. The location and
; colors are copied to the clipboard as a comma-
; separated value so it can be pasted into a text
; file or directly into a variable in a script.
; -----------------------------------------------
+!g:: ;<-- tkGrabIt 
tkGrabIt:
MouseGetPos, oposx, oposy
Sleep 200
tkGrabItTimerFlag = 1
gosub tkGrabItTimer
Return

tkGrabItTimer:
MouseGetPos, mx, my
sleep 200
pixelgetcolor, mouseoncolor, %mx%,%my%, Alt RGB
Sleep 200
str = %mx%`,%my%`,%mouseoncolor%
Tooltip, %str%`nUse the Mouse MButton to grab,,,3

If (GetKeyState("Mbutton", "P"))
{	If (tkGrabItTimerFlag)
	{	tkGrabItTimerFlag = 0
		MouseMove, %oposx%, %oposy%
		PixelGetColor, mouseoffcolor, %mx%,%my%, RGB
		str = %str%`,%mouseoffcolor%
	}
	clipboard = %str%
	ClipWait
	tooltip,,,,3
	Return
}
SetTimer, tkGrabItTimer, -100
Return

+!Esc::
ExitApp


Enzy
  • Members
  • 16 posts
  • Last active: Aug 07 2012 04:25 AM
  • Joined: 07 Aug 2012
218,171,0x3A621D,0x3A621D
323,166,0x485813,0x485813
333,135,0x38402C,0xFF0000

these are the three codes i've gathered but pixlesearch format is like this

PixelSearch, Px, Py, 664, 451, 592, 138, 0x1A3030, 3, Fast

so the format is different, unless there is a different command cause thats the only command i can find

girlgamer
  • Moderators
  • 3263 posts
  • Last active: Feb 01 2015 09:49 AM
  • Joined: 04 Jun 2010
you said

218,171,0x3A621D,0x3A621D
323,166,0x485813,0x485813
333,135,0x38402C,0xFF0000

these are the three codes i've gathered but pixlesearch format is like this

PixelSearch, Px, Py, 664, 451, 592, 138, 0x1A3030, 3, Fast

so the format is different, unless there is a different command cause thats the only command i can find

First of all the routine i provided uses the RGB switch to read the colors from the screen at the location found. The first color is the color you get when you have the mouse over the item, the second color is the color seen when the mouse is NOT on the item. You will note that the color at 333,135 has changed color between being on the item and not on the item. that could be for either of two reasons. Reason 1; the item is highlighted when the mouse is on it and not highlighted when the mouse is somewhere else on the screen. Reason 2: the color is constantly varying and the colors you get depend on the cycle of the colors at the time. There is a simple way to handle this and that's to check for BOTH colors at a location when doing a pixel search. If either color matches you can consider that the item is "available for clicking. The other way is to check to see if BOTH colors fail at that location. That would tell you (in the case of a harvest node) that there is no node present at that location. I don't know what colors you're looking for given the range of xy cooords you specified in your pixel search command. So i can't tell whether it would fail or not.

Also from your post It appears you are using the BGR not the RGB form of the color so using the colors from my routine would fail since the color form is different. you would have to use the RGB option for the pixel search to be compatible with the colors found using my pixel scanner. Had you specified the RGB switch and picked a color within that region to scan for using my scanner we could see if the search passed or failed. Unfortunately that's not true with what you've posted.

The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ●
MMO Fighter   KeyLooperDemo   Key Spammer   TinyClickRecorder  GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
Rock-on%20kitten.gif


Enzy
  • Members
  • 16 posts
  • Last active: Aug 07 2012 04:25 AM
  • Joined: 07 Aug 2012
Okay cool and those three colours are the shades of the tree and the effect that it brings out. also how do i find the RGB colour

girlgamer
  • Moderators
  • 3263 posts
  • Last active: Feb 01 2015 09:49 AM
  • Joined: 04 Jun 2010
I gave you a routine to find the RGB color. That's what it does, along with the location where that color is.

The universe is a wondrous place! The faster you create unbreakable code, the faster the universe creates people that can break it. All scripting follows the rule Rule Of Twos -- 1) Good, 2) Fast 3) Cheap -- pick any Two.
I guarantee absolutely nothing about any code I provide except that it works in my machine. ●
MMO Fighter   KeyLooperDemo   Key Spammer   TinyClickRecorder  GGs Password Generator.ahk
For the newest version of AutoHotkey and some killer scripts go here.
Rock-on%20kitten.gif