Jump to content

Need some beginners help!


Scinner
 Share

Recommended Posts

PS - Do you just want the read fucntion executed continuosly? calling "read" recursively may be neat, but it's "crazy ivan" spaghetti coding and about the biggest violation of structured programming in existence. You should avoid it like the plague, unless it's absolutely necessary. It'll also overflow your stack in no time. You need to explain what you're wanting to do with the read function, and rethink a cleaner method of achieving it.

Edit: PPS - I assume there is more to this script? An entry point, an exit point? You really need to nix all but one call to the read function, just put the one call into a loop that suits your needs.

CODE

Global $AttackPoints[20][2] = [[725, 295],[725, 315],[725, 333],[725, 355],[725, 375],[725, 394],[725, 417],[725, 436], _

[725, 455],[725, 476],[725, 496],[725, 516],[725, 536],[725, 555],[725, 577],[725, 596], _

[725, 615],[725, 636],[725, 657],[725, 676]]

Man oh man, do i have a long way to go or what. :) All my codeing experiance comes from "learn by doing" and "trial and error". I have no education in this feeld what so ever. Theres a good swedish(?) saying, directly translated: I have taken water over my head :lmao: Don't know if im able to understand this but i sure will try :think:

A link to AutoIt for extra dumb dummys annyone?

Edited by Scinner
Link to comment
Share on other sites

Nothing wrong with hands-on learning, it's how I picked up most of my experience.

There are a lot of great script examples in the autoit/examples folder, and they are also accessible from SciTE's "help" system. Checking those out, modifying and playing with (copies of) them would likely get you a lot more comfortable with Autoit.

You know a lot more English than i know Swedish. All I know is "Yeg elsker dem" and I'm NOT saying that to you! :) Come to think of it, that may be Danish.

Link to comment
Share on other sites

Nothing wrong with hands-on learning, it's how I picked up most of my experience.

There are a lot of great script examples in the autoit/examples folder, and they are also accessible from SciTE's "help" system. Checking those out, modifying and playing with (copies of) them would likely get you a lot more comfortable with Autoit.

You know a lot more English than i know Swedish. All I know is "Yeg elsker dem" and I'm NOT saying that to you! :think: Come to think of it, that may be Danish.

Im working on at least 5 diffrent scripts and this one is the most dificult of them all. When i get stuck with one script for over an hour i start fiddeling with another and so on. And then when i get back to the previous script i often can see it from another point of wiev. I like problem solving but this is getting a bit rich. :) But im stubbern as a donkey. AutoIt is addictive for sure. Spent 10 hours a day the last couple of days.

What im trying to do with this script is: The read function reads how many troops i got in my village, if i got more than a certain number then it will attack a neighbour village. Read again to se if i got enoughf troops to attack the next village and so on and so forth. All the mouseclicks are shortcuts to the attack page for every village. But as i said before im no gamer but im very fascinated by the fact that you can write code that will do all those things for you.

My first successful script was a little login script for my internet bank with the mouseclick and send commands. My imagination is a little bit poor though, thats wy i ended up trying to do a game bot. Its the problem solving that keeps me going. Well enough about me allready :lmao: This was a well needed break. Back to my script.

Thanks for your tips, i will try to figure it out in one way or another!

Link to comment
Share on other sites

I have tried to avoid Arrays up to now. It looks a little bit to advanced for me but now there's no escape. I'll be back in a month or so when i've figured out how arrays works :)

Thank you all for helping me and giving me tips!

Edit: Not that I think that annyone would do it, but please dont finish my script. Im here to learn!

Edited by Scinner
Link to comment
Share on other sites

What's the test.txt file all about?

I supose that you could call it my way of an array? :)

I paste the number of troops i get from the readbody in the test.txt and then i use FileRead so i can use the "more than/less than" If statement. :lmao: I know there's probably a much better/simpler way to do it but its the only way i know at this point.

Edited by Scinner
Link to comment
Share on other sites

Im also trying to do this script for IE with those great _IE commands. But i must read up on arrays, i understand that it is a very importent part of AutoIt. Here's what i have come up whith so far.

#include <IE.au3>
Sleep(500)
$oIE = _IECreate ("http://s4.travian.se/login.php")
_IELoadWait ($oIE)
MouseClick("left", 432, 545, 1)
_IELoadWait ($oIE)
$sText = _IEBodyReadText ($oIE)
$Start = StringInStr($sText, "r:")           ;here i will try the _StringBetween() instead when i get the hang of it
$End = StringInStr($sText, "Klubb")
$Quote = StringMid($sText,$Start,$End-$Start)
$Final = StringStripWS($Quote, 8)
Sleep(200)
ShellExecute("D:\Mikee\AutoIt Script + Div\test.txt")
Sleep(1000)
Send("{DEL 6}")
Sleep(500)
Send($Final)
Send("{HOME}")
Send("{DEL 2}")
Send("^s")
Sleep(1000)
Local $File = "D:\Mikee\AutoIt Script + Div\test.txt"
$Read = FileRead($File)
If $Read >= 20 Then ;över 5
    Send("Över")
ElseIf $Read < 20 Then ;under 5
    Send("Under")
EndIf
Edited by Scinner
Link to comment
Share on other sites

I'm off to bed, but I tried to organize the script a little...

The for...next loop in attack(), will execute all 20 attacks the way it is now , you could easily change that

It's hard to guess what works or doesn't, since I can't execute this script.

Your usage of test.txt does seem a bit strange.

; Initialization

Global $AttackPoints[20][2] = [[725, 295],[725, 315],[725, 333],[725, 355],[725, 375],[725, 394],[725, 417],[725, 436], _
                               [725, 455],[725, 476],[725, 496],[725, 516],[725, 536],[725, 555],[725, 577],[725, 596], _
                               [725, 615],[725, 636],[725, 657],[725, 676]]




; Main loop ----------------------------------------------------
While 1
    $Read()
    If $Soldiers > 5 Then
        Attack()
        Sleep(2000)
    Else
        ExitLoop
    Endif
WEnd
Exit

; Called Functions ---------------------------------------------
Func read();this function is a home made Firefox reader that will tell me if i got more than 5 soldiers in my village
    Sleep(3000);60000*5
    WinActivate("Travian se4 - Mozilla Firefox")
    MouseClick("left", 195, 185, 1)
    Sleep(3000)
    Send("^a")
    Send("^c")
    ShellExecute("D:\Mikee\AutoIt Script + Div\test.txt")
    Sleep(1000)
    Send("^v")
    Sleep(500)
    Send("^f")
    Sleep(500)
    Send("Trupper:")
    Sleep(500)
    Send("!u")
    Sleep(500)
    Send("{ENTER}")
    Send("{DEL}")
    Send("{SHIFTDOWN}")
    Send("{UP 14}")
    Send("{SHIFTUP}")
    Send("{DEL 4}")
    Send("{RIGHT 2}")
    Send("{SHIFTDOWN}")
    Send("{PGDN 3}")
    Send("{SHIFTUP}")
    Send("{DEL}")
    Send("{HOME}")
    Sleep(500)
    Local $File = @ScriptDir & "\test.txt"
    $Soldiers = StringStripWS(FileRead($File),8)
    WinKill("* D:\Mikee\AutoIt Script + Div\test.txt - Notepad2")
EndFunc

Func attack()
    WinActivate("Travian se4 - Mozilla Firefox")
    For $x = 0 to 19
        MouseClick("left", $AttackPoints[$x][0],$AttackPoints[$x][1], 1)  ;all these cases are diffrent targets i want to attack
        Sleep(1000)                      
        MouseClick("left", 200, 330, 1)
        Sleep(500)
        Send("7")
        Sleep(500)
        Send("{ENTER}")
        Sleep(1000)
        MouseClick("left", 180, 474, 1)
    Next
EndFunc
Link to comment
Share on other sites

i think my script it similar, though i just want to script something that will respond to the "OK" button that is displayed after registering a .dll

i have tried the following but am getting a Line -1 Error parsing function call:

regsvr32 urlmon.dll

Sleep (random("RegSvr32"))

Send("{Enter}")

regsvr32 mshtml.dll

Sleep (random("RegSvr32"))

Send("{Enter}")

regsvr32 actxprxy.dll

Sleep (random ("RegSvr32"))

send("{Enter}")

regsvr32 oleaut32.dll

Sleep (random ("RegSvr32"))

send("{Enter}")

regsvr32 shell32.dll

Sleep (random ("RegSvr32"))

Send("{Enter}")

regsvr32 shdocvw.dll

sleep (random ("RegSvr32"))

Send("{Enter}")

Hi there,

Maybe something like this:

thank you for your help.

Link to comment
Share on other sites

I'm off to bed, but I tried to organize the script a little...

The for...next loop in attack(), will execute all 20 attacks the way it is now , you could easily change that

It's hard to guess what works or doesn't, since I can't execute this script.

Your usage of test.txt does seem a bit strange.

Thanks man! Are there somwhere i can read about how to code and make it look nice, like you? Rules or guidelines I mean.

I wrote a post explaining my thinking regarding the test.txt yesterday but when I was allmost finished my computer crashed :) The thing is that I know Im doing it wrong but until my AutoIt skills improve I'll try it this way. I'm reading up on Arrays as we speak and I think it may not be that complicated that i thought at my first glens at it, at least Im trying to persuade myself it isn't :lmao: Well here's me trying to explain the crazy test.txt thingie:

$sText = _IEBodyReadText ($oIE)
$Start = StringInStr($sText, "r:"); Here I want to get the number of troops present in my village (118 See atachment below) 
$End = StringInStr($sText, "Klubb");When I use SiS it returns "r:    118" so I paste it to .txt and edit it with Send(Del).
$Quote = StringMid($sText,$Start,$End-$Start); I will try doing this with _StringBetwen as soon as I master that command.
$Final = StringStripWS($Quote, 8)

;---------------------------------------------------------

Local $File = "D:\Mikee\AutoIt Script + Div\test.txt"
$Read = FileRead($File)
If $Read >= 20 Then ;over or equal to 20 soldiers
    Send("Över");This is just a temporary command to see if it works, here I want the attack funtion.
ElseIf $Read < 20 Then ;under 20 troops
    Send("Under");Will be a sleep command because if less than 20 troops I dont wan't to attack I want to wait 10min then read again. 
EndIf
;So in short: 
; Read, if more than 20 troops attack vilage nr1 (if less than 20 wait 10 min then read again)
; Read, if more than 20 troops attack vilage nr2
; Read, if more than 20 troops attack vilage nr3
; And so on and so forth.

post-21314-1232479312_thumb.png

Edited by Scinner
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...