autohotkey - 是否可以将pixelsearch和pixelgetcolor结合起来

标签 autohotkey

在这款 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/wend 等,而这基本上是相同的

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

简单示例:

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

将与

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

。因此,sleep, 5000 将以任何方式执行,无论 if 语句如何!如果您根本不使用任何大括号,则任何 if 语句、loopelse 部分等将仅计入 一行。因此,只有在只有一行要执行的情况下,才不要省略大括号。

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

另一件事:如果您使用像 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

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

关于autohotkey - 是否可以将pixelsearch和pixelgetcolor结合起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30314117/

相关文章:

resize - 使用子窗口调整窗口大小的自动热键

conditional - 如何在 AutoHotKey 脚本中使用 'or' s?

autohotkey - 配置Autohotkey以使用Notepad++编辑脚本

autohotkey - 如何在 AutoHotkey 中暂时禁用鼠标左键激活的代码?

javascript - AHK 网页元素按钮按下

windows - Autohotkey Windows 10 虚拟桌面

keyboard-shortcuts - 使用字母激活自动热键

arrays - 如何在 Autohotkey 中发送数组变量的值?

autohotkey - 上面最左边的字符在表达式中是非法的

lotus-notes - 为 "reply to all with history"创建 Lotus Notes 热键/快捷键