Hàm WaitSwitch: Dùng để đợi nhân vật chuyển thành. Thông thường khi kết thúc hàm ClickText thì nhân vật sẽ bị lag, hoặc chạy sai khi qua thành, map mới. Ở Vulan thì nhân vật sẽ chạy loạn xạ. - Code:
WaitSwitch = function() nMap = map.GetID() local nTimeBegin = os.clock() local nTimeWait = 4 local nTimeWaitRevive = 1 while player.GetName() == "" do -- timer.Sleep(10) end while (nMap == map.GetID() or map.GetID() == 0) and os.clock() - nTimeBegin < nTimeWait do -- timer.Sleep(10) end if nDebug == 1 then system.Print("§· chuyÓn Map: "..map.GetName()) end player.SetMoveFrame(1) nMoveFrame = player.GetMoveFrame() if nDebug == 1 then system.Print("Move Frame HiÖn t¹i: "..nMoveFrame) end while nMoveFrame == player.GetMoveFrame() and os.clock() - nTimeBegin < nTimeWaitRevive do -- timer.Sleep(10) end if nDebug == 1 then system.Print("Move Frame Thay §æi: "..nMoveFrame) end player.ReturnCity() end Mình add thêm Script Bán Hàng tự động đi Reset cây giờ (Đã định). Kết hợp vài hàm ClickText, WaitSwitch để làm. - Code:
pGeneralLib = system.GetScriptFolder().."\\LIB\\General.lua" IncludeFile(pGeneralLib) -- Load Lib --------------------------------------------------------------------------------------- nMoneyGet = 99999 -- Tinh bang Luong
len_thanh = function() General.TalkToNPC("Xa phu") General.ClickText(1, "Nh÷ng thµnh thÞ ®· ®i qua", 1) General.ClickText(1, "T¬ng D¬ng Phñ", 1) General.WaitSwitch() end
xuong_thon = function() General.TalkToNPC("Xa phu") General.ClickText(1, "Nh÷ng thµnh thÞ ®· ®i qua", 1) General.ClickText(1, "Ba L¨ng huyÖn", 1) General.WaitSwitch() end
function main() control.PauseAll() --Dung moi dieu khien cua auto nDebug = 0 while true do local nX, nY = player.GetMapPos() nTimeWait = 4 * 60 * 60 -- 4h = 14400 nTimeBegin = os.clock() while player.GetOnlineTime() < nTimeWait do timer.Sleep(10) stall.Announcement(1) -- Ngoi ban end stall.Announcement(0) -- Dung day --system.Print(map.GetName(map.GetID()).." - "..nX.."/"..nY) player.PathMoveTo(0, 0, "Xa phu") local nMoney = player.GetMoney(0) -- Hanh Trang if nMoney > nMoneyGet then -- Rut 5000 luong nMoney = nMoney - nMoneyGet player.ExchangeMoney(1, nMoney) else local nMoneyBox = player.GetMoney(1) nMoney = nMoneyBox > 1000 and nMoneyGet - nMoney or nMoneyBox if nMoneyBox < 1000 then error("Tæng sè tiÒn ph¶i cã lµ 1000!") end player.ExchangeMoney(0, nMoney) end xuong_thon() -- player.PathMoveTo(0, 0, "Xa phu") len_thanh() --system.Print(map.GetName(map.GetID()).." - "..nX.."/"..nY) player.PathMoveTo(nX, nY, "") General.MoveTo(nX, nY) timer.Sleep(1000) if stall.IsVisible() == 0 then stall.Announcement(1) -- Ngoi ban end system.Print("Hoµn Thµnh!") -- control.ResetAll() end end
Lúc Vulan ở phiên bản cũ hàm player.FindRoom bị lỗi G. G đã thay thế nó bằng hàm PlacePut. - Code:
-- [b]nType[/b]: Loai Place đặt vật phẩm -- [b]nItem[/b]: Tên vật phẩm hoặc nIndex của vật phẩm -- [b]nLenght[/b]: Độ dài của Rương chứa [i](Place để)[/i] -- [b]@return[/b]: nPlace, nX, nY [i](Ngăn chứa, tọa độ X, tọa độ Y)[/i] PlacePut = function(nType, nItem, nLenght) local nArray = {} local nCapacity = {} local nWidth, nHeight nLenght = nLenght or 60
for i = 0, nLenght - 1 do table.insert(nCapacity, i) end if nDebug == 1 then system.Print(nType) end local nIndex, nPlace, nX, nY = item.GetFirst() while nIndex ~= 0 do if type(nItem) == "string" and nItem == item.GetName(nIndex) then nItem = nIndex end if nPlace == nType then nWidth, nHeight = item.GetSize(nIndex) if nDebug == 1 then system.Print(item.GetName(nIndex).."-"..nWidth.."x"..nHeight) end for nW = 0, (nWidth - 1) do for nH = 0, (nHeight - 1) do nWeight = nX + nW + (nY + nH) * 6 end end table.remove(nCapacity, nWeight) end nIndex, nPlace, nX, nY = item.GetNext() end local nWidth, nHeight = item.GetSize(nItem) local nRtnX, nRtnY = 0, 0 local nWeightChk for _, i in ipairs(nCapacity) do nCount = 0 nRtnX, nRtnY = 0, 0 for nW = 0, nWidth - 1 do for nH = 0, nHeight - 1 do local nY = math.floor(i / 6) local nX = i - nY * 6 if nRtnX == 0 and nRtnY == 0 then nRtnX, nRtnY = nX, nY end nWeightChk = nX + nW + (nY + nH) * 6 if nCapacity[nWeightChk] ~= nil then nCount = nCount + 1 end end end if nCount == nWidth * nHeight then return nType, nRtnX, nRtnY end end return 0, 0, 0 end Bạn nào Pro hơn một tý thì lưu ý việc kiểm tra vòng While khi check đồ trong Rương (nPlace Put) lưu ra mãng riêng và kiểm tra chặt chẽ quá trình xuất, nhận Item để Tăng tốc tốc độ xử lý của Hàm. (Dựa theo cơ chế chuyển đồ của Vulan Ctrl + A)G xin kết thúc Topic này tại đây. G đã không còn chơi Game Võ Lâm nữa nên việc viết Code của G cũng kết thúc theo. Sẵn G chia sẻ thêm Script Tín Sứ có thể chạy file của Kid Tin Sứ nhưng cực kỳ dỡ khi xài cho Vulan và VAuto bởi vì Vulan không thể check Skill Buff bằng Script, kiểm tra thời gian đi Tín Sứ. Ở Kid Tín Sứ có rất nhiều điểm mạnh, Script của G không thể nào làm được như thế. - Code:
dwGeneral = system.GetScriptFolder().."\\LIB\\General.lua" IncludeFile(dwGeneral)
-- nPath: Lua chon Path chay toa do nDebug = 1 nIndex_Pos = 0 nRange = 50 nRandAttack = 300 nPath = 3 szFilePath = { {"Nguoc_Duoi_Full.pth", 1}, {"Nguoc_Duoi.pth", 1}, {"PhongKyPhiaDuoi.pth", 2} } szFolder = { "ToaDo", "ToaDoKid" }
-- Thong Bao HBK nEnbleNotice = 0
function HideDialog() while dialog.IsVisible() == 1 do dialog.Close() end end
-- ham tim thong bao toa do Ho Bao Ky neu phat hien tren kenh to doi --danh sach cac HBK da thong bao tNotices = {} function HBK() local nX, nY = 0, 0 local nXMap, nYMap local dwSeries, dwChat = "", "" local nCurLife, nMaxLife local nPlrX, nPlrY = 0, 0 local nSctX, nSctY, nSctIndex = 0, 0, 0 for i = 2, 255 do if npc.IsExists(i) then Switch(Trim(npc.GetName(i))){ ["Kim Quèc Hæ B¸o Kþ"] = function() if nEnbleNotice == 1 then if InArray(tNotices, "nIndex", nIndex) == 0 then nX, nY = npc.GetMapPos(i) nXMap, nYMap = math.floor(nX/256), math.floor(nY/512) dwSeries, dwChat = "", "" nCurLife, nMaxLife = npc.GetLife(i) dwSeries = General.GetNameSeries(i) dwChat = "Hång B¸o Kú ("..dwSeries..") Täa ®é "..nPX.."/"..nPY.." ("..math.floor(nCurLife/nMaxLife*100).."% M¸u)" -- General.Chat("CH_TEAM", dwChat) system.Print(dwChat) table.insert(tNotices, {nIndex = nIndex}) end end end, ["Täa ®é trinh s¸t"] = function() nPlrX, nPlrY = player.GetMapPos() -- Hide Dialog nSctX, nSctY = npc.GetMapPos(i) nDistance = General.GetDistance(nPlrX, nPlrY, nSctX, nSctY) if math.sqrt(nDistance) < nRandAttack then Attack(i) end end } end end end
nCountScout = 0
function Attack(nIndex_Pos) local nNpcX, nNpcY = npc.GetMapPos(nIndex_Pos) nLevelAttach = 1 MoveTo(nNpcX, nNpcY) while nLevelAttach > 0 do -- system.Print(nLevelAttach) if npc.IsExists(nIndex_Pos) == 1 then Switch(nLevelAttach){ [1] = function() player.DialogNpc(nIndex_Pos) end, [2] = function() player.SetPeopleIndex(nIndex_Pos) end, [3] = function() player.FollowPeople(nIndex_Pos) end, default = function() nLevelAttach = 0 end, } else break end if dialog.IsVisible() == 0 then nLevelAttach = nLevelAttach + 1 else nCountScout = nCountScout + 1 system.Print("Täa ®é: "..nCountScout.." - TÝn sø: "..(nCountScout*3)) nIndex_Pos = 0 break end end end
-- ham tim toa do trong path tin su gan diem dang dung nhat -- tra ve: thu tu cua toa do trong path
function FindPosIndex(nX, nY) local nDtc, nDtcMin, nIndex local nSize = #tPath for i = 1, nSize do nDtc = General.GetDistance(nX, nY, tPath[i].nX, tPath[i].nY) if tPath[i].nAttack ~= 1 then tPath[i].nAttack = 0 end if nDtcMin == nil or nDtcMin > nDtc then nDtcMin = nDtc nIndex = i end end return nIndex end
nSctIndex = 0
-- Type: nil, 0 - Next -- Type: 1 - Prev -- Return: Index Pos trong Map function FindNext(nPosIdx) nType = (nType == nil) and 0 or nType local nSize = #tPath local nPosPrevIdx nPosPrevIdx = (nPosIdx == 1) and nSize or nPosIdx - 1 local nIndex local i = nPosIdx while i ~= nPosPrevIdx do if tPath[i].nAttack == 1 then return i end i = (i == nSize) and 1 or i + 1 end end
function FindPrev(nNextIdx) local nSize = #tPathScout for i = 1, nSize do if tPathScout[i].nIdx == nNextIdx then i = (i == 1) and nSize or i - 1 return tPathScout[i].nIdx end end end
nNextIdx = nil function NextPos() local nPlrX, nPlrY = player.GetMapPos() local nPosIdx = FindPosIndex(nPlrX, nPlrY) local nSizeSct = #tPathScout local nSize = #tPath nNextIdx = (nNextIdx == nil) and FindNext(nPosIdx) or nNextIdx local nPrevIdx = FindPrev(nNextIdx) local nIdx = nPrevIdx local nDtc, nDtcMin local nMoveIdx = 0 -- system.Print("Next: "..nNextIdx..": "..math.floor(tPath[nNextIdx].nX/256).."/"..math.floor(tPath[nNextIdx].nY/512)) -- system.Print("Prev: "..nPrevIdx..": "..math.floor(tPath[nPrevIdx].nX/256).."/"..math.floor(tPath[nPrevIdx].nY/512)) local nVectorNN, nVectorNP = {}, {} local nDtcNN, nDtcNP, nMulVector while nIdx ~= nNextIdx do nPlrX, nPlrY = player.GetMapPos() nPrev = nIdx nNext = (nIdx == nSize) and 1 or nIdx + 1 nDtcNN = General.GetDistance(nPlrX, nPlrY, tPath[nNext].nX, tPath[nNext].nY) nDtcNN = math.sqrt(nDtcNN) nDtcNP = General.GetDistance(tPath[nPrev].nX, tPath[nPrev].nY, tPath[nNext].nX, tPath[nNext].nY) nDtcNP = math.sqrt(nDtcNP) nVectorNN = { nX = nPlrX - tPath[nNext].nX, nY = nPlrY - tPath[nNext].nY } nVectorNP = { nX = tPath[nPrev].nX - tPath[nNext].nX, nY = tPath[nPrev].nY - tPath[nNext].nY } nMulVector = nVectorNN.nX * nVectorNP.nX + nVectorNN.nY * nVectorNP.nY nAlpha = math.acos(nMulVector/(nDtcNN*nDtcNP)) nDtc = math.floor(nDtcNN*math.sin(nAlpha)) if nDtcMin == nil or nDtcMin > nDtc then -- system.Print(nDtcMin) nDtcMin = nDtc nMoveIdx = nIdx end nIdx = (nIdx == nSize) and 1 or nIdx + 1 end HideDialog() nPlrX, nPlrY = player.GetMapPos() -- system.Print("Move "..nMoveIdx..": "..math.floor(tPath[nMoveIdx].nX/256).."/"..math.floor(tPath[nMoveIdx].nY/512)) local nDtcNext, nDtcPrev, nNextPosIdx nPlrX, nPlrY = player.GetMapPos() nNextPosIdx = (nMoveIdx == nSize) and 1 or nMoveIdx + 1 nDtcNext = General.GetDistance(tPath[nNextPosIdx].nX, tPath[nNextPosIdx].nY, nPlrX, nPlrY) nDtcPrev = General.GetDistance(tPath[nNextPosIdx].nX, tPath[nNextPosIdx].nY, tPath[nMoveIdx].nX, tPath[nMoveIdx].nY) nDtcNext = math.floor(math.sqrt(nDtcNext)) nDtcPrev = math.floor(math.sqrt(nDtcPrev)) nDtc = General.GetDistance(tPath[nMoveIdx].nX, tPath[nMoveIdx].nY, nPlrX, nPlrY) nDtc = math.floor(math.sqrt(nDtc)) nMoveIdx = (nDtcNext > nDtcPrev and nDtc > nRange) and nMoveIdx or nNextPosIdx if tPath[nMoveIdx].nAttack == 1 then nMoveIdx = (nMoveIdx == nSize) and 1 or nMoveIdx + 1 nNextIdx = FindNext(nMoveIdx) HBK() end return tPath[nMoveIdx].nX, tPath[nMoveIdx].nY end tPath = {} tPathScout = {} function LoadMap() tChoose = szFilePath[nPath] szPath = system.GetScriptFolder().."\"..szFolder[tChoose[2]].."\"..tChoose[1] local nTypePath = tChoose[2] if nTypePath == 1 then if nDebug == 1 then system.Print("Path: "..szPath) end IncludeFile(szPath) local nSizeSct = #tPathScout local nSctX, nSctY local nIndex local nSize for i = 1, nSizeSct do nSctX, nSctY = tPathScout[i].nX, tPathScout[i].nY nIndex = FindPosIndex(nSctX, nSctY) nSize = #tPath nIndex = (nIndex == nSize) or 1 and nIndex + 1 table.insert(tPath, nIndex, {nX = nSctX, nY = nSctY, nAttack = 1}) tPathScout[i].nIdx = nIndex end elseif nTypePath == 2 then file = io.open(szPath,"r") local i = 0 while true do line = file:read() if not line then break end for a, x, y in string.gmatch(line, "%d+=(%a) (%d+)/(%d+)") do a = Switch(a){ ["a"] = 1, ["A"] = 1, default = 0 } i = i + 1 -- system.Print(x..", "..y.."\"..i) table.insert(tPath, {nX = x, nY = y, nAttack = a}) if a == 1 then table.insert(tPathScout, {nX = x, nY = y, nAttack = a, nIdx = i}) end end end file:close() end end
function main() local nStatusPos, i local nX, nY = 0, 0 control.PauseAll() control.PauseAutoFight() LoadMap() nX, nY, nPthIndex = NextPos() -- Lay toa do chay while true do player.MoveTo(nX, nY) nX, nY = NextPos() HideDialog() end end Trong Script này G sử dụng Tam Giác để tìm độ cao AH (Smile) từ đó xác định Nhân vật đang gần vị trí nào nhất thông qua cách tính 3 điểm tạo thành tam giác (Nhân vật là điểm ở giữa). Có thể áp dụng rất nhiều thuật toán để tự vẽ ra đường đi cong, vòng G chỉ lấy script tính theo Tam giác share cho các bạn (Tất cả thuật toán khác nằm trong diễn đàn các bạn tự tìm tòi học hỏi nhe). Script này sử dụng file Map của Kid Tín Sứ hoặc file viết tay. - Code:
-- Table Patch = { -- {nX, nY, nAction} -- } -- nAction: Toa do can Click Muc Tieu tbPath={ {nX = 49728, nY = 99360, nAction = 0}, {nX = 49600, nY = 99520, nAction = 0}, {nX = 49440, nY = 99744, nAction = 0}, {nX = 49312, nY = 100032, nAction = 0}, {nX = 49216, nY = 100288, nAction = 0}, {nX = 49024, nY = 100608, nAction = 0}, {nX = 48896, nY = 100704, nAction = 0}, {nX = 48416, nY = 100832, nAction = 0}, {nX = 48160, nY = 100768, nAction = 0}, {nX = 47904, nY = 100832, nAction = 0}, {nX = 47680, nY = 100960, nAction = 0}, {nX = 47424, nY = 100992, nAction = 1} -- Tim Pos
- Code:
-- szFilePath: Là tên Map -- {"<Tên Map>", "<Mã Thư mục>"} szFilePath = { {"Nguoc_Duoi_Full.pth", 1}, {"Nguoc_Duoi.pth", 1}, {"PhongKyPhiaDuoi.pth", 2} }
-- szFolder: Thư mục chứa map szFolder = { "ToaDo", "ToaDoKid" } Ví dụ: File Nguoc_Duoi_Full.pth nằm trong thư mục "ToaDoKid" thì để: - Code:
-- szFilePath: Là tên Map -- {"<Tên Map>", "<Mã Thư mục>"} szFilePath = { {[b]"Nguoc_Duoi_Full.pth"[/b], [b]2[/b]}, {"Nguoc_Duoi.pth", 1}, {"PhongKyPhiaDuoi.pth", 2} }
-- szFolder: Thư mục chứa map szFolder = { "ToaDo", "ToaDoKid" } - Code:
[b]nPath = 3[/b] nPath là Chọn Scritp thứ mấy trong szFilePath. Hiện tại thì G đang xài "PhongKyPhiaDuoi". Bạn nào đọc được hiểu được thì tốt. Không hiểu thì hãy hỏi người khác chỉ cho. G sẽ không reply Topic này nữa vì những gì G làm G đã chia sẻ hết rồi (Trình độ của G chỉ có vậy thôi à). Thân chào các bạn. P/S: G chưa test Code ở phía trên lại với Vulan và VAuto phiên bản mới có thể có lỗi. |