Lua语言---手游脚本---主线脚本循环框架
今天共享一个几年前,编写的一个手游脚本,脚本的功能就是到指定地图几个地点打怪,死亡自动买药,自动拾取,自动返回,自动交易。
脚本主线循环结构框架演示:
UserVar txt_map="无量山" "输入打怪地图名称"
'主循环,主线,相当于一本书的目录,目录里该写什么,不该写什么我想大家都明白
Do
If 人物死亡() = True Then
If 复活操作() = True Then
Call 买药补给()
End If
Else
If 判断地图(txt_map) = True Then
If 选怪() = True Then
TracePrint "选怪成功"
If 打怪操作() = True Then
TracePrint "怪物死亡,开始捡物"
Call 捡物操作()
Else
TracePrint "怪物未死,打怪超时或异常,前往下个坐标"
Call 前往下个坐标(x, y)
End If
Else
TracePrint "选怪失败,前往下个坐标"
Call 前往下个坐标(x, y)
End If
Else
Call 执行跨地图寻路()
End If
End If
Loop
EndScript
'以下都是各个函数功能模块分好的,各个功能都要清晰合理的写好,需要的时候主循环调用
Function 人物死亡()
人物死亡 = False
If 获得血量() = 0 Then
人物死亡 = True
End If
End Function
Function 复活操作()
复活操作 = False
'点击确认复活等操作
If 获得血量() > 0 Then
'操作完毕
复活操作 = True
End If
End Function
Function 买药补给()
If 前往NPC("药店商人") = True Then
'购买药品操作等……
End If
End Function
Function 前往NPC(name)
前往NPC = False
'判断自动寻路列表,寻找药店NPC点击寻路等操作
If 判断到打开交易界面() = True Then
前往NPC = True
End If
End Function
Function 判断地图(name)
判断地图 = False
If 判断右上角地图名称是否为(name) = True Then
判断地图 = True
End If
End Function
Function 执行跨地图寻路()
'计算路线,打开寻路列表操作,等等……
End Function
Function 前往下个坐标(x, y)
If 补给不足() = True Then
If 回城寻路() = True Then
'到达买药等等操作……
End If
Else
'执行当前地图坐标寻路
End If
End Function
'后面就不写了,例子差不多大家看明白了吧……
