AutoIt Forums: MY FarmVille Program - AutoIt Forums

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

MY FarmVille Program 2250 lines long! Rate Topic: -----

#1 User is offline   BitByteBit 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 105
  • Joined: 20-May 09

Posted 04 November 2009 - 08:22 AM

I've set up a site for this program now, so for all future updates check out
removed


This program doesn't rely on knowing the mouse co-ords (eg the size of your field). Instead it looks for the pixel colour and clicks it. You can teach it to harvest new crops, also you can record mouse clicks to an .ini file and play them back allowing you to buy and sell hay bales super fast.

Enjoy guys, any comments will be greatly appreciated!!!

I went the long way round a few times, it was the only way I knew.

Enjoy.
http://i34.tinypic.com/w1prav.jpg

<code removed for violating the FarmVille Terms of Service>

This post has been edited by Valik: 27 February 2010 - 08:28 PM
Reason for edit: Code removed.


#2 User is offline   BitByteBit 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 105
  • Joined: 20-May 09

Posted 04 November 2009 - 09:04 AM

Open the file FV.ini and paste this in.
Sorry I forgot to mention that FV.ini should be in the root of C:\

[BlueBerries]
Colours=0x573734

[Pumpkins]
Colours=0xF58F20

[Green Tea]
Colors=0x3D651B

[Coffee]
Colors=0xA03118

[Raspberries]
Colors=0x9B1725

[Rice]
Colors=0x4A661F

[Tomatoes]
Colors=0xEF7B5F

[Unseeded Land]
Colors=0x602806

[Plowable Land]
Colors=0x474806

[Withered Crop]
Colors=0x463715

[Strawberries]
Colors=0x663117

[Ghost Chilli]
Colors=0x62270B

[BlackBerries]
Colors=0x325125

[Sunflower]
Colors=0xD48212

[Sugar Cane]
Colors=0x4D1C02

This post has been edited by BitByteBit: 04 November 2009 - 09:05 AM


#3 User is offline   storme 

  • Mass Spammer!
  • PipPipPipPip
  • Group: Full Members
  • Posts: 328
  • Joined: 30-October 08
  • Gender:Male
  • Location:Australia

Posted 04 November 2009 - 02:05 PM

Looks good.
I definately like your method! It's not forcing the farm to so what you want it's doing what is needed on the farm.
Do you ever have any misses with the searches and it clicks on the wrong thing?

2 suggestions if I may.

1. Work out a method of automatically fullscreening the farm. So when a chore chosen it does the whole farm.
2. Set it to always on top so you don't have to alt-tab back and forth to your program and farmville. (Minimize it when you are doing something so it doesn't hide anything.)

Oh one thing I just found....... I did a plow and it missed a line that had "red wheat" planted in front of it. Not a big problem but thought you should know.

Well done

#4 User is offline   BitByteBit 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 105
  • Joined: 20-May 09

Posted 04 November 2009 - 07:16 PM

Thanks for taking the time to reply.

No I don't have problems with it clicking the wrong thing. I've tried to be careful as to what pixel colour I program in.

1. I know how I would make it fullscreen, I would search for the plow tool colour, get the co-ords and minus a certain amount from them, thus moving the mouse a certain amount up and right, this would bring me to the fullscreen button I believe. However for some reason the functions run much slower if FV is fullscreen. I'm not sure why to be honest. Try it for yourself, make FV fullscreen and press Ctrl+Alt+P to plow, look at the speed, then press esc, it goes much faster when not fullscreened, I have no idea why, perhaps Adobe Flash Player when fullscreen is taking up more cpu cycles.

2. I'm aware of this problem, I need to change the pixel colour it searches for to one closer to the top of the top.

Thank you for your input, its people like you that help improve my program. :lol:


As for making it always on top, I'll think about it ;)

#5 User is offline   KeithDawn 

  • Newbie
  • Group: Full Members
  • Posts: 7
  • Joined: 06-November 09

Posted 06 November 2009 - 08:11 PM

This script is wonderful, I must say, but I have found a small issue with it.

It seems unable to work on any fertilized crops, plus the above mentioning of spaces being blocked by other crops.

Two quick questions though.
1 - Have you thought about doing an animal harvester with this code? Given they all have the pink diamond above their head, and the harvest option is always 3rd down on the list, would it be possible? (I as because I suck at coding, it's been to long for me.)
2 - Is there any way to pause the script / end it manually mid-run? I had an issue where it accidentally picked up a kitten twice, and just twitched back and forth across the screen for a minute until I closed firefox.

Just wondering, but awesome script and good job!

#6 User is offline   BitByteBit 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 105
  • Joined: 20-May 09

Posted 06 November 2009 - 11:33 PM

View PostKeithDawn, on 06 November 2009 - 09:11 PM, said:

This script is wonderful, I must say, but I have found a small issue with it.

It seems unable to work on any fertilized crops, plus the above mentioning of spaces being blocked by other crops.

Two quick questions though.
1 - Have you thought about doing an animal harvester with this code? Given they all have the pink diamond above their head, and the harvest option is always 3rd down on the list, would it be possible? (I as because I suck at coding, it's been to long for me.)
2 - Is there any way to pause the script / end it manually mid-run? I had an issue where it accidentally picked up a kitten twice, and just twitched back and forth across the screen for a minute until I closed firefox.

Just wondering, but awesome script and good job!


Ctrl+F1: Cancels the current action
Alt+Escape: Exits the script
Alt+R restarts the program

[ autoIt ]    ( ExpandCollapse - Popup )
#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_outfile=C:\Users\Tristan\Desktop\Animals.exe #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Opt("WinWaitDelay", 100) Opt("WinTitleMatchMode", 2) Opt("WinDetectHiddenText", 1) Opt("MouseCoordMode", 1) Opt("TrayIconDebug", 1) Opt("PixelCoordMode",1) HotKeySet("^{F1}", "Animals") HotKeySet("^{F2}", "Stop") Global $CoOrd[2] Global $CoOrd2[2] $Num = 0 $Searching = False     ToolTip("Ctrl+F1 to start", "", "", "!", 1, 2)     Sleep(2000)     ToolTip("")         ToolTip("Ctrl+F2 to stop","","", "!", 1, 2)     Sleep(2000)     ToolTip("") While 1     Sleep(10) wend Func Stop() While 1     Sleep(500) wend     EndFunc Func Animals() $Searching = True while $Searching = True $CoOrd = PixelSearch(0,0,1024,768,0xD02875,20)  ;  0xCF0867   0XFF409D Sorta works with shade variation of 10-20 ;$CoOrd = PixelSearch(0,0,1024,768,0xD02875,21) ;Deff working!!! ;$CoOrd3 = PixelSearch(0,0,1024,768,0XFF409D,15)  ;  Perhaps have several colous? if not @error then     MouseClick("Left",$CoOrd[0],$CoOrd[1],1,0)     ;MsgBox(0,"?","Click diamond?")     $CoOrd2=MouseGetPos()     $CoOrd2 [0] = $CoOrd[0] + 17     $CoOrd2 [1] = $CoOrd[1] + 47     Sleep(210)     MouseClick("Left",$CoOrd2[0],$CoOrd2[1],1,0)     ToolTip($Num, 0, 0, "!", 1, 2)     Sleep(75)     ToolTip("")     $Num = $Num + 1         ;MsgBox(0,"?","Click probs??")     Else         MsgBox(0,"1","No animals??")         $Searching = False     EndIf     WEnd     EndFunc  


That is the code for animals. I've yet to build it into the main GUI cos I hate redesigning GUI's!!!
That and the program is already pretty chunky!

#7 User is offline   KeithDawn 

  • Newbie
  • Group: Full Members
  • Posts: 7
  • Joined: 06-November 09

Posted 07 November 2009 - 01:38 AM

Did I mention how much a love you and your scripts?!?! Cause I do, very much so. Thanks you for pointing out how to pause the script, just had the same issue with the kitten and it fixed things quite nicely. As for the animal script, love it, works great.

Just my opinion, but if you were looking for something to cut from the main program to add in the animals, I say cut the profit calculator. I think people could survive without it.

That's just my opinion though, but yeah, love your work!

#8 User is offline   storme 

  • Mass Spammer!
  • PipPipPipPip
  • Group: Full Members
  • Posts: 328
  • Joined: 30-October 08
  • Gender:Male
  • Location:Australia

Posted 07 November 2009 - 03:30 AM

View PostBitByteBit, on 07 November 2009 - 08:33 AM, said:

Ctrl+F1: Cancels the current action
Alt+Escape: Exits the script
Alt+R restarts the program

[ autoIt ]    ( Popup )
HotKeySet("^{F1}", "Animals") HotKeySet("^{F2}", "Stop")  


That is the code for animals. I've yet to build it into the main GUI cos I hate redesigning GUI's!!!
That and the program is already pretty chunky!


Works well except it's picking up animals that have already been clicked and clicking them again. This brings up an "Animal is busy" message. I added a 2 second delay and it's working slow but no more messages. May be you coudl tighten up the tollerence so it ignores the clicked animals but I'm not sure if this will miss some.

Also it would be worth doing a check to see that what is being clicked on is "harvest/collect". The dairy menu is different and I think the "SELL" item is where the "harvest" is on animals. Wouldn't be good to sell things that you don't want to. :-)

Thanks again
John Morrison
aka
Storm-E

#9 User is online   JohnOne 

  • Mass Spammer!
  • PipPipPipPipPipPip
  • Group: Full Members
  • Posts: 1,903
  • Joined: 20-August 09

Posted 08 November 2009 - 01:11 AM

I would not mind trying a automation script like this, I will get a facebook account to try it.

Quick question, Do I need to know the game farmville, before trying this, or will it go from the start ?

The last computer game I played was pac man.

#10 User is offline   KeithDawn 

  • Newbie
  • Group: Full Members
  • Posts: 7
  • Joined: 06-November 09

Posted 09 November 2009 - 12:59 AM

With the dairy farms, it's the move which is third down, not sell, so no risk of selling there. I just harvest them first manually to prevent any errors.

View Poststorme, on 06 November 2009 - 10:30 PM, said:

Works well except it's picking up animals that have already been clicked and clicking them again. This brings up an "Animal is busy" message. I added a 2 second delay and it's working slow but no more messages. May be you coudl tighten up the tollerence so it ignores the clicked animals but I'm not sure if this will miss some.


Just wondering how to added the 2 second delay. FYI I suck at coding so I dare not try myself, but perhaps you could point me in the right direction.

View PostJohnOne, on 07 November 2009 - 08:11 PM, said:

I would not mind trying a automation script like this, I will get a facebook account to try it.

Quick question, Do I need to know the game farmville, before trying this, or will it go from the start ?

The last computer game I played was pac man.


Yes, you will need to know the game farmville before using this. In fact, this code would only become really useful once you get a few levels under your belt. But by that time, you'll understand the game. I like to think of it as a lite version of Harvest Moon.

EDIT: Also just realized, with the animal script it may be possible to harvest cherry trees. I have a bunch and just realized when I run the script with them on the screen, it clicks on them as if they are a pink triangle. Only problem I see is it's trying to do this when they are not ready, and as such would probably create a loop within the program of just clicking on the same tree over and over.

This post has been edited by KeithDawn: 09 November 2009 - 01:14 AM


#11 User is offline   BitByteBit 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 105
  • Joined: 20-May 09

Posted 09 November 2009 - 02:48 AM

John, Keith, thank you very much for your input so far.

I will cut out the profit calculator and change it to Animals soon, I will post the new code when I do.

This is the new Animals code. I haven't got round to fixing the Harvest/Move issue, maybe this week if I get time. So for now just harvest your dairy farms manually, sorry guys!

This should resolve the issue of click an animal multiple times. Let me know how it works out!

If you want to fiddle with the tolerance change the number 20 to a lower number here:
$CoOrd = PixelSearch(0,0,1024,768,0xD02875,20)


EDIT: Animal Code Fixed

[ autoIt ]    ( ExpandCollapse - Popup )
Opt("WinWaitDelay", 100) Opt("WinTitleMatchMode", 2) Opt("WinDetectHiddenText", 1) Opt("MouseCoordMode", 1) Opt("TrayIconDebug", 1) Opt("PixelCoordMode",1) HotKeySet("^{F1}", "Animals") HotKeySet("^{F2}", "Stop") Global $CoOrd[2] Global $CoOrd2[2] Global $CoOrd3[2] $CoOrd3 [0] = 0 $CoOrd3 [0] = 0 $Num = 0 $Searching = False     ToolTip("Ctrl+F1 to start", "", "", "!", 1, 2)     Sleep(2000)     ToolTip("")         ToolTip("Ctrl+F2 to stop","","", "!", 1, 2)     Sleep(2000)     ToolTip("") While 1     Sleep(10) wend Func Stop() While 1     Sleep(500) wend     EndFunc Func Animals() $Searching = True while $Searching = True $CoOrd = PixelSearch(0,0,1024,768,0xD02875,20) if not @error then     IF $CoOrd[0] <> $CoOrd3[0] OR $CoOrd[1] <> $CoOrd3[1] then     MouseClick("Left",$CoOrd[0],$CoOrd[1],1,0)     ;MsgBox(0,"?","Click diamond?")     $CoOrd2=MouseGetPos()     $CoOrd3[0] = $Coord2[0]     $CoOrd3[1] = $Coord2[1]     $CoOrd2 [0] = $CoOrd[0] + 17     $CoOrd2 [1] = $CoOrd[1] + 47     Sleep(210)     MouseClick("Left",$CoOrd2[0],$CoOrd2[1],1,0)     ToolTip($Num, 0, 0, "!", 1, 2)     Sleep(75)     ToolTip("")     $Num = $Num + 1     Else     Sleep(1)     EndIf     Else         ToolTip("Animals Done/No Animals")         Sleep(1250)         ToolTip("")         $Searching = False     EndIf     WEnd EndFunc  



Tree's is a whole other project, however it does use the same technique used for Animals and so shouldn't be hard at all.

The only catch is I basically need to get a colour for each fully matured tree, a colour that only appears when they are done and not when they are growing. On top of this I have to find a colour which is viewable regardless of what(and where said item) is front of the tree, however I do not think this is a major issue.

Once I have the colours; using the same method I can create a script to harvest Trees.

Balls in your court guys. If you want to try to create your own script for trees with the animal code then save a copy of the animals file and:


1. Open FarmVille.
2. Take a print screen by pressing the PrtScn button.
3. Open Paint.
4. Press Ctrl+V
5. Open AutoIt Window Info and click on the mouse tab (Installed with AutoIt)
6. Back in paint, hover over the fully matured tree and press Ctrl+Alt+F
7. In AutoIt Window Info double click "Color" , that colour code is now saved into your clipboard.
8. Replace the 0xD02875 part of "$CoOrd = PixelSearch(0,0,1024,768,0xD02875) with
$CoOrd = PixelSearch(0,0,1024,768,YOURCOLOURHERE)" with the colour you just got.
9. Test.
10. Report back.

If done correctly you will make a code to harvest one particular tree type ^__^, at which point you can call yourself a hobbyist programmer :huggles:

Send me a PM if you have issues/questions :D

I don't have any the trees so I can't do this, if I get a few Tree colour codes I will happily make a script to harvest trees.

. . .

One more thing, I'm fully aware of the Plowing issue, in my next update it will be fixed. However for now, open the source code and find and replace(Ctrl+H):

Find:
$Coord2 = PixelSearch(30, 30, 1024, 768, 9731111)

Replace with:
$Coord2 = PixelSearch(30, 30, 1024, 768, 0x68540E)

That will resolve the problem!!!

This post has been edited by BitByteBit: 09 November 2009 - 04:48 AM


#12 User is offline   KeithDawn 

  • Newbie
  • Group: Full Members
  • Posts: 7
  • Joined: 06-November 09

Posted 10 November 2009 - 02:11 PM

Thanks for the updates, things seem to be working well.

I've been busy so I've not had much time to try creating the trees program, however seeing how nicely you laid out everything above I did give it a few tries. I think it's going to be harder than I thought, the few times I've tried I keep running into the same problem. Often the color of the fruit (which is what I use to tell it harvest-able tree from non-harvest-able) is either used elsewhere within the game screen or, even more annoying, within the Firefox logo.

When I get some time I'll give it a few more gos and let you know what happens.

#13 User is offline   KeithDawn 

  • Newbie
  • Group: Full Members
  • Posts: 7
  • Joined: 06-November 09

Posted 20 November 2009 - 07:02 PM

Three comments Bit:

1 - the source code you posted is out of format. I'm not sure if it's the new code or just the old code messed up.

2 - I like where you put the animals into the program, this new code removed the repeated clicking on the same animal problem. However it has introduced a new problem. About 50% of the time, after clicking animals, I get an array error and the entire program crashes. I'll post more info the next time I get it (I forgot to write it down earlier).

3 - On your website, you should add a comment section or point back to this forum in someway. That way, others can contribute their modification / comments.

Also, I've had no luck with the trees. The colors are used too often within the browser I'm finding. That being said, I've found another program that utilized another pixel color identification method and am trying to test it on trees. If it works, perhaps the two could be combined.

#14 User is offline   BitByteBit 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 105
  • Joined: 20-May 09

Posted 21 November 2009 - 04:17 PM

1 - Old Code, will fix.
2 - Thanks I'll look into it. Try installing the version from the site, I don't think that has the same issue.
3 - I'm looking into an email function, I want to put up a testimonials page, could I get one from you.

Keith, check your inbox.

#15 User is offline   Home Bunny 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 19
  • Joined: 02-August 06
  • Location:Belgium

Posted 25 November 2009 - 07:48 AM

Hi Bit,

Love your program !

Could we do auto-harvesting after planting crops?, perhaps with adding a time table to the planted crops ...
And of course then autoplowing and auto-seeding , ..., ....

Keep up the good work.

Jim

#16 User is offline   BitByteBit 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 105
  • Joined: 20-May 09

Posted 14 January 2010 - 01:20 AM

Who wants the updated source code?

#17 User is offline   Jagraw 

  • Newbie
  • Group: Validating
  • Posts: 1
  • Joined: 16-July 08
  • Gender:Male
  • Location:Phoenix, AZ

Posted 18 February 2010 - 10:18 PM

View PostBitByteBit, on 13 January 2010 - 05:20 PM, said:

Who wants the updated source code?


Is it too late to still get the Source Code for Version 3?
I'm very interested to see how you did the color recognition logic.

I play farmville a lot and it saves me lots of time. Thanks.

JAGRAW

#18 User is offline   BinaryCortex 

  • Newbie
  • Group: Members
  • Posts: 2
  • Joined: 21-February 10

Posted 21 February 2010 - 05:09 AM

View PostBitByteBit, on 13 January 2010 - 05:20 PM, said:

Who wants the updated source code?


Me Me Me! Would it be possible to get the source code for version 3 or even the 3.1 that your working on? Also when I tried to harvest my aloe vera it tried clicking on the start where my level is located.

Ian

#19 User is offline   tiggere 

  • Newbie
  • Group: Members
  • Posts: 2
  • Joined: 23-February 10

Posted 23 February 2010 - 01:35 AM

Issue...when running this script and trying to save tree locations it keeps telling me that it needs to be in fullscreen...it is in fullscreen until I get the error message telling me that it needs to be in full screen...then clicking ok puts it in fullscreen and clicks the "zoom out" twice...but hovering over a tree and pressing "Alt + Space" gives me the error message again...

I just planted my crops so have not been able to use anything else in the script...

#20 User is offline   NicholasMatthew 

  • Newbie
  • Group: Members
  • Posts: 1
  • Joined: 25-February 10

Posted 25 February 2010 - 08:48 PM

Can I get the source code too please? Thanks alot.

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users