自动种菜lua

  • A+
所属分类:LUA脚本
Auto_Farm={}
Auto_Farm_AutoSellerOn=true
Auto_Farm.SoilID={}
Auto_Farm.SellerID=""--种子商ID
Auto_Farm.NowSel=0--当前农田索引
Auto_Farm.Connect_p=false--是否处于衔接,用于通用农田面板和读条之间的锁定
Auto_Farm.ISDontChange=false--收获完之后锁定农田
Auto_Farm.Connect_p_count=0--衔接锁定计数,超时后解除锁定
Auto_Farm.Item={}
Auto_Farm.Seller={}
Auto_Farm_IsRun=true
Auto_Farm.InnerAutoSellerOn=false


Auto_Farm.Item["翠云草种子"]=true --1级
Auto_Farm.Item["乌蕨种子"]=true
Auto_Farm.Item["马蹄金种子"]=true --2级
Auto_Farm.Item["萱草种子"]=true
Auto_Farm.Item["仙客来种子"]=true

Auto_Farm.Item["雁来红种子"]=true --3级
Auto_Farm.Item["紫绒蒿种子"]=true
Auto_Farm.Item["香雪兰种子"]=true
Auto_Farm.Item["黍米种子"]=true

Auto_Farm.Item["风信子种子"]=true --4级
Auto_Farm.Item["月季种子"]=true
Auto_Farm.Item["蔷薇种子"]=true
Auto_Farm.Item["牡丹种子"]=true

Auto_Farm.Seller["翠云草"]=true --1级
Auto_Farm.Seller["乌蕨"]=true
Auto_Farm.Seller["马蹄金"]=true --2级
Auto_Farm.Seller["萱草"]=true
Auto_Farm.Seller["仙客来"]=true

Auto_Farm.Seller["雁来红"]=true --3级
Auto_Farm.Seller["紫绒蒿"]=true
Auto_Farm.Seller["香雪兰"]=true
Auto_Farm.Seller["黍米"]=true

Auto_Farm.Seller["风信子"]=true --4级
Auto_Farm.Seller["月季"]=true
Auto_Farm.Seller["蔷薇"]=true
Auto_Farm.Seller["牡丹"]=true

TongFarmPanel=TongFarmPanel or {}
Auto_Farm.Fun_old_back=TongFarmPanel.OnFrameBreathe


function TongFarmPanel.OnFrameBreathe()
Auto_Farm.Fun_old_back()
local player = GetClientPlayer()
if not player then
return
end
if (not Auto_Farm_IsRun) or player.bFightState or player.bOnHorse then
return
end
local hFrame = Station.Lookup("Normal/TongFarmPanel")
local hBtnSowing = hFrameookup("Btn_Sowing") --播种
local hBtnKill = hFrameookup("Btn_Kill") --铲除
local hBtnHarvest = hFrameookup("Btn_Harvest") --收获
if hFrame then
Auto_Farm.Connect_p=false--鼠标单击到农场面板解锁
Auto_Farm.Connect_p_count=0-------
end
if hBtnHarvest and hBtnHarvest:IsEnabled() then --自动收获
Auto_Farm.Connect_p=true
local thisSave = this
this=hBtnHarvest
TongFarmPanel.OnLButtonClick()
this = thisSave
Auto_Farm.ISDontChange=true
end
if not hFrame.nSeedItemID or hFrame.nSeedItemID==0 then --自动放种子
Auto_Farm.Connect_p=true
Auto_Farm.SetItemToFarm()
end
if hBtnSowing and hBtnSowing:IsEnabled() then --自动播种
local thisSave = this
this=hBtnSowing
TongFarmPanel.OnLButtonClick()
this = thisSave
end
CloseTongFarmPanel()
end


function Auto_Farm.SetItemToFarm()
local player=GetClientPlayer()

for i=1,5 do
if player.GetBoxSize(i)>0 then
for j=0,player.GetBoxSize(i)-1 do
local item=player.GetItem(i,j)
if item and Auto_Farm.Item[GetItemNameByItem(item)] then
AppendTongFarmItem(i,j)
return
end
end
end
end
end

function Auto_Farm.OnFrameBreathe()
if not Auto_Farm_IsRun then
return
end
--获取地图名称
local player = GetClientPlayer()
if not player then
return
end
local scene = player.GetScene()
if not scene then
return
end
local MapName = Table_GetMapName(scene.dwMapID)
---------
if MapName=="帮会领地" then
--正式代码
for i=1,4 do
if Auto_Farm.Connect_p then--如果处于窗口衔接的锁定之中
if player.GetOTActionState() ~= 0 then--读条中,满足解除锁定
Auto_Farm.Connect_p_count=0
Auto_Farm.Connect_p=false
else
Auto_Farm.Connect_p_count=Auto_Farm.Connect_p_count+1
if Auto_Farm.Connect_p_count>95 then--超时,解除锁定
Auto_Farm.Connect_p_count=0
Auto_Farm.Connect_p=false
end
end

else

if Auto_Farm_AutoSellerOn and Auto_Farm.SellerID then--自动上交检测
local seller=GetNpc(Auto_Farm.SellerID)
if seller then
local distance=GetCharacterDistance(player.dwID, Auto_Farm.SellerID) / 64
if distance<4.5 then
if IsSeedInBag() then
SelectTarget(TARGET.NPC, Auto_Farm.SellerID)
InteractNpc(Auto_Farm.SellerID)
end
Auto_Farm.Connect_p=true
end
end
end
local tobj=GetTargetHandle(GetClientPlayer().GetTarget())
if ( not (player.nMoveState ~= MOVE_STATE.ON_STAND or player.GetOTActionState() ~= 0 or player.bFightState or player.bOnHorse)) and ((not ( tobj and (tobj.szName=="痴呆的毒人" or tobj.szName=="饥饿的毒人" or tobj.szName=="狂乱的毒人"))) or not tobj) then--如果在走动或读条或战斗或骑马等操作时不执行
if not IsTongFarmPanelOpened() then--种植已面板开启

local Num=table.getn(Auto_Farm.SoilID)
if not Auto_Farm.ISDontChange then
Auto_Farm.NowSel=Auto_Farm.NowSel+1

if Auto_Farm.NowSel>Num then--单次循环结束
Auto_Farm.NowSel=0
end
else
Auto_Farm.ISDontChange=false
end
local ID=Auto_Farm.SoilID[Auto_Farm.NowSel]
local soil=GetNpc(ID)
if soil then
local distance=GetCharacterDistance(player.dwID, ID) / 64
if distance<6 then--可以交互
SelectTarget(TARGET.NPC, ID)
InteractNpc(ID)
Auto_Farm.Connect_p=true--鼠标单击到农场面板锁定,防止延时造成收取失败
end
end
end--种植面板开启
end--满足收取状态(无走动等)
end--窗口锁定
end--for
end
end

function IsSeedInBag()
local player=GetClientPlayer()

for i=1,5 do
if player.GetBoxSize(i)>0 then
for j=0,player.GetBoxSize(i)-1 do
local item=player.GetItem(i,j)
if item and Auto_Farm.Seller[GetItemNameByItem(item)] then
Auto_Farm.InnerAutoSellerOn=true
return true
end
end
end
end
Auto_Farm.InnerAutoSellerOn=false
return false
end

function IsTongFarmPanelOpened()
local hFrame = Station.Lookup("Normal/TongFarmPanel")
if hFrame then
return true
end

return false
end
function Auto_Farm.AddTable()
local Npc=GetNpc(arg0)
if Npc then
if Npc.szName=="帮会农田" then
for i=1,table.getn(Auto_Farm.SoilID) do
if Auto_Farm.SoilID[i]==arg0 then
return
end
end
if table.getn(Auto_Farm.SoilID)>=30 then--农场ID发生更改
Auto_Farm.SoilID={}
end
table.insert(Auto_Farm.SoilID,arg0)
end
if Npc.szName=="郭语成" then
Auto_Farm.SellerID=arg0
end
end
end

RegisterEvent("NPC_ENTER_SCENE", Auto_Farm.AddTable)
RegisterEvent("OPEN_WINDOW",function()
if Auto_Farm_AutoSellerOn and Auto_Farm.InnerAutoSellerOn then--打开自动交付
local tobj=GetTargetHandle(GetClientPlayer().GetTarget())
if Auto_Farm.SellerID and tobj.dwID==Auto_Farm.SellerID then--目标为种子商
if string.find(arg1,"上交所有果实") then
GetClientPlayer().WindowSelect(arg0,0)
CloseDialoguePanel(true)
Auto_Farm.Connect_p_count=0--补充锁定
Auto_Farm.Connect_p=true
else
GetClientPlayer().WindowSelect(arg0,0)
CloseDialoguePanel(true)
Auto_Farm.InnerAutoSellerOn=false
end
end
end
end)



Hotkey.AddBinding("AutoFarm", "切换开启状态(默认打开)", "自动农场",
function()
if Auto_Farm_IsRun then
Wnd.CloseWindow("Auto_Farm")
Auto_Farm_IsRun=false
OutputMessage("MSG_SYS","自动农场已关闭\n")
else
Wnd.OpenWindow ("Interface/Auto_Farm/Auto_Farm.ini","Auto_Farm")
Auto_Farm_IsRun=true
OutputMessage("MSG_SYS","自动农场已开启\n")
end
end,
nil)
Hotkey.AddBinding("AutoFarm_AutoSeller", "自动上交状态", nil,
function()
if Auto_Farm_AutoSellerOn then
Auto_Farm_AutoSellerOn=false
OutputMessage("MSG_SYS","自动上交已关闭\n")
else
Auto_Farm_AutoSellerOn=true
OutputMessage("MSG_SYS","自动上交已开启\n")
end
end,
nil)
Wnd.OpenWindow ("Interface/Auto_Farm/Auto_Farm.ini","Auto_Farm")
RegisterCustomData("Auto_Farm_AutoSellerOn")
RegisterCustomData("Auto_Farm_IsRun")

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin

发表评论

您必须登录才能发表评论!