是否可以结合 pixelsearch 和 pixelgetcolor

is it possible to combine pixelsearch and pixelgetcolor

在这个 MMO 游戏中,如果我的角色生命值低,它应该传送回城镇并与治疗 NPC 交谈。它不起作用,我不明白为什么 - 当我尝试 运行 我的脚本时出现错误。

http://i61.tinypic.com/swqltw.jpg

CoordMode, Pixel, Relative
CoordMode, Mouse, Relative
Home:: ;press home to start ahk


Loop   

PixelSearch, X, Y, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0x00ff00, 0, fast ;<<<--this is the monster color to attack
if(ErrorLevel=0) 
Sleep, 200
Send, {F4}
Sleep, 200
MouseClick, left, 392, 289
Sleep, 8000


else 

   PixelGetColor, healthbar, 51, 82 ;heres my health bar coordinates

  if (healthbar = 0xDEDED6) ;if my hp bar goes low it will go teleport to town and click to healer npc
       Send !3 ;alt 3 to teleport to town
       Sleep 5000 ;lets wait 5seconds for waiting game loading.
       MouseClick, left, 755, 341 ;click the healer npc
       sleep, 1500
       Send {F5} ;some self skill buffs and stuffs
       sleep, 1500
       Send {F5}
       sleep, 1500
       MouseClick, left, 755, 341   ;click to healer npc again to heal mana
       sleep, 500
       MouseClick, left, 713, 281 ;click to teleporter npc to get back to dungeon to kill monsters
       sleep, 500
       Send {Enter}
       sleep, 1500
       Send {Enter}
else 
       Send {F8} ;if no monster present in screen, use random teleport skill to search for monsters


F11::Pause
End::ExitApp ; alt+x to exit ahk

您遗漏了所有非低级编程语言中非常重要的编程部分:大括号。 (在 AutoIt 中,我认为你不使用大括号,而是使用 ifendif / wends 等,而这基本上是相同的

了解 AutoHotkey 中的编译器不关心脚本中的缩进很重要。

快速示例:

if(healthbar = 0xDEDED6)
send, !3
sleep, 5000

将与

相同
if(healthbar = 0xDEDED6)
{
    send !3
}
sleep, 5000

。因此,sleep, 5000 将以任何方式执行,而不管 if 语句!如果您根本不使用任何大括号,任何 if 语句、loops、else 部分等将只计算 一行 .因此,永远不要省略大括号,只有在只有 one 行要执行的情况下。

如果您想确定,请尽可能使用大括号。

另一件事:如果您以 home:: 等热键触发器开始任何部分,请务必在最后用 return 括起来。

这是您的源代码示例。我还更改了一些缩进,但请注意,它们不是必需的,只是为了更好的可读性。

CoordMode, Pixel, Relative
CoordMode, Mouse, Relative

Home:: ;press home to start ahk

Loop
{

    PixelSearch, X, Y, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0x00ff00, 0, fast ;<<<--this is the monster color to attack
    if(ErrorLevel=0)
    {
        Sleep, 200
        Send, {F4}
        Sleep, 200
        MouseClick, left, 392, 289
        Sleep, 8000
    }
    else
    {
        PixelGetColor, healthbar, 51, 82 ;heres my health bar coordinates
        if (healthbar = 0xDEDED6) ;if my hp bar goes low it will go teleport to town and click to healer npc
        {
           Send !3 ;alt 3 to teleport to town
           Sleep 5000 ;lets wait 5seconds for waiting game loading.
           MouseClick, left, 755, 341 ;click the healer npc
           sleep, 1500
           Send {F5} ;some self skill buffs and stuffs
           sleep, 1500
           Send {F5}
           sleep, 1500
           MouseClick, left, 755, 341   ;click to healer npc again to heal mana
           sleep, 500
           MouseClick, left, 713, 281 ;click to teleporter npc to get back to dungeon to kill monsters
           sleep, 500
           Send {Enter}
           sleep, 1500
           Send {Enter}
        }
        else 
           Send {F8} ;if no monster present in screen, use random teleport skill to search for monsters
    }

}

return  ; ------ end of HOME hotkey


F11::Pause
End::ExitApp ; alt+x to exit ahk

但是,这并不能保证您的代码现在可以正常工作