Sign in to follow this  
Followers 0
Sparrowhawk

Noobie here, can someone check this block of code real quick?

13 posts in this topic

#1 ·  Posted (edited)

$myhealth = PixelGetColor(145,48)
$mymana = PixelGetColor(109,57)
$enemyhp = PixelGetColor(209,49)

Func ChkHp()
$myhealth = PixelGetColor(145,48)
If 
    NOT $myhealth = 16730933
    Then 
        send ("8" , 0)
    Else
        EndIf
EndFunc

Func ChkMP()
$mymana = PixelGetColor(109,57)
If 
    NOT $mymana = 3196911
    Then
        send ("6" , 0)
    Else
        EndIf
EndFunc

Func AttackMove()
    send ("{TAB}" , 0)
    sleep (500)
    send ("1" , 0)
    while $enemyhp = 16755355
        ChkHP()
        $enemyhp = PixelGetColor(209, 49)
        WEnd
EndFunc

$key = 1

While $key = 1
    AttackMove()
WEnd

When I go to check for syntax errors it returns:

ERROR: syntax error

If

ERROR: multi-line 'If' missing 'Then'.

If

I put the 'thens' in there, but perhaps I'm using NOT wrong? I wanted the equivalent of != and I found people using NOT instead.

[edit] - Another thing I just noticed--

while $enemyhp = 16755355
        ChkHP()
        $enemyhp = PixelGetColor(209, 49)
        WEnd

Will this end after one loop because I put WEnd in there? Should I just leave the WEnd off, and once enemyhp != 16755355 it will cause the loop to end on its own?

Regards,

Sparrowhawk

Edited by Sparrowhawk

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Technically, you have your syntax correct, but the AutoIt parser wants to see "If" and "Then" on the same physical line, i.e.:

If Not $mymana = 3196911 Then
    send ("6" , 0)
EndIf
Edited by Spiff59

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

If $myhealth <> 16730933 Then

AutoIt uses <> for not-equal-to.

Be sure to fix any other If statements. If expression Then goes on one line.

Also, While-WEnd is how you create a loop. WEnd tells the interpreter where the bottom of the looped code is.

Edited by Richard Robertson

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Ahhh, thanks!

Also, While-WEnd is how you create a loop. WEnd tells the interpreter where the bottom of the looped code is.

Hehe sorry I'm *very* rusty, got a bit of a jumble in my head about how things go :P

Edited by Sparrowhawk

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

...and wend just marks the end of the "while" loop, it does NOT cause the loop to exit- that would be ExitLoop. The while loop will continue until the condition after "While" is not met, or ExitLoop (or Exit, which would quit the whole script) is called.

Edit: too slow :P

Edited by james3mg

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

0 error(s), 0 warning(s)

>Exit code: 0 Time: 0.229

:P

[edit] - Ok new question now...

Testing it first hand, it's stuck in an endless loop of tabbing.

The way I envisioned it working was tabbing once, then being stuck in the loop until ENEMY dies, then repeating... but it seems to skip that altogether.

Which leads me to believe it might be a conversion problem with PixelGetColor... the output as far as I know is in decimal, I had to find the color I wanted using the Window Info mouse tab, which turned up:

0xFFAA9B

which should be

16755355 in decimal if I'm not mistaken

If that's correct, then there's a problem in the code I can't see.

Edited by Sparrowhawk

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

:P

[edit] - Ok new question now...

Testing it first hand, it's stuck in an endless loop of tabbing.

The way I envisioned it working was tabbing once, then being stuck in the loop until ENEMY dies, then repeating... but it seems to skip that altogether.

Which leads me to believe it might be a conversion problem with PixelGetColor... the output as far as I know is in decimal, I had to find the color I wanted using the Window Info mouse tab, which turned up:

0xFFAA9B

which should be

16755355 in decimal if I'm not mistaken

If that's correct, then there's a problem in the code I can't see.

Ok it was a problem in the conversion... I ended up just writing a separate script for each one and letting autoit print out the numbers to my chat screen so I knew those were 100% the right ones... Worked. But now the script only executes the entirety once and seems to get stuck in an infinite loop after one go... Not sure where the problem is now, only reason I think/know it's an infinite loop is because the window lags up and the script doesn't close itself after the first run.

[edit2] - Ok found the problem once again, but I don't know how to explain it... PixelGetColor returns the same value no matter what color is at that position... I tried with a red hp bar, and it returns 527635... But if the enemy hp bar isn't there and say its just some green grass... it also returns the 527635.

[edit3] - I'm thinking maybe it has to do with pixelgetcolors coordinates... perhaps its not reading them right relative to where they actually are? The game screen is in 800x600 and in windowed mode. I've just been moving it around under the assumption that since I have WinWaitActive that it only picks pixels within the 800x600 boundary of the window that is defined.

Edited by Sparrowhawk

Share this post


Link to post
Share on other sites

What application are you trying to use PixelGetColor() on?? Is this for a game?? Many games are created to make it as hard as possible to do this kind of stuff to prevent bots and stuff, so you may have to go to "extreme" measures to get it working (like vmware)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

What application are you trying to use PixelGetColor() on?? Is this for a game?? Many games are created to make it as hard as possible to do this kind of stuff to prevent bots and stuff, so you may have to go to "extreme" measures to get it working (like vmware)

True, I found another tidbit though that suggests using Coord mode: Client instead of Coord Mode: Window which is what I had before... for accuracy.

So I'm going to retry it the new way and get the coordinates again.

If that doesn't work I might just have to take other measures. :P

[edit] - Nope still returning the same values... Any clues on what kind of "protection" could cause this? or perhaps just another problem on my end...

Edited by Sparrowhawk

Share this post


Link to post
Share on other sites

this loop will repeat until PixelGetColor isnt 16755355 I guess this means you will check your hp and then check to see if monster is dead and then repeat. You will only exit this loop when monster is dead. If you need to keep calling a attack move the monster will never die since you are not attacking. Im not sure how the game is set up or what you are looking to do.

while $enemyhp = 16755355 
        ChkHP()
        $enemyhp = PixelGetColor(209, 49)
    Wend

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

this loop will repeat until PixelGetColor isnt 16755355 I guess this means you will check your hp and then check to see if monster is dead and then repeat. You will only exit this loop when monster is dead. If you need to keep calling a attack move the monster will never die since you are not attacking. Im not sure how the game is set up or what you are looking to do.

while $enemyhp = 16755355 
        ChkHP()
        $enemyhp = PixelGetColor(209, 49)
    Wend
That's intended... The game automatically keeps attacking after you press the basic attack skill (assigned to 1 in this case, and it sends "1" before it goes into a loop of checking enemy HP).

But for this specific problem, this is in fact the problem because I either can't find the right coordinates or the game has protection from autoit reading the pixelgetcolor... because the value never changes. I can get different values at different individual pixel positions oddly enough, but each pixel seems to have a value to it that doesn't change.

The original idea being that it would just be auto attacking away while stuck in an infinite loop checking the color... Once the HP Bar drops you're just left with a hollow blue tube (so the color would go from red to blue once the enemy was dead if you got the pixel color at the very end of the enemies HP bar)... But since the value doesn't appear to change no matter what I do in this case, I'll have to devise another method...

[editx] - Alright, ended up just trashing the pixelgetcolor idea and letting it depend on timing... Sloppy but works, for now.

Edited by Sparrowhawk

Share this post


Link to post
Share on other sites

Use PixelSearch and search for the red color. Where there is no more red (I think you said it turns to all blue) then the monster is dead. Thats what I did and it works for me.

Share this post


Link to post
Share on other sites

If Not $myhealth = 16730933 Then
    Send("8", 0)
Else
    ; nothing for the ELSE part
EndIfoÝ÷ Ûú®¢×ºÚ"¶«±ë-ébë-jצz{[ÊËZµéÔ¨Ü"W!yÉ*ºb~z-Ó~¦ÊØjºm¡·­®ç¨­ö¥±ì!z·²¢ç±¥ç-¶!yÉ*ºb~z-Ó~¦ÊØ

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
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
Sign in to follow this  
Followers 0