You are not connected. Please login or register

Xem chủ đề cũ hơn Xem chủ đề mới hơn Go down Thông điệp [Trang 1 trong tổng số 1 trang]

Admin
Admin
Admin
Code:
function Switch(case)
        return function(block)
                local func
                func = block[case] or block.default or block["default"]
                if func then
                        if type(func) == "function" then
                                return func()
                        else
                                if nDebugFunc == 1 then
                                        system.Print(case.." is not function!")
                                end
                                return func
                        end
                end
        end
end

Hàm Switch dùng để thay thế cho nhiều hàm If Else cùng một lúc.

1 Vài ví dụ và hàm Switch:
Code:
nType = 1
local nAction = Switch(nType){
        [2] = function() return 2 end,
        [3] = function() return 3 end,
        defautl = 4
}
-- > nAction = 4
-- nType = 2 thì nAction  = 2
Ứng dụng hàm Switch tạo ra hàm chuyển đổi ANSI dùng cho system.SendKey.
Code:
ASCII = function(char)
        return Switch(type(char)){
                ["table"] = function()
                        local dwArray = {}
                        if nDebug == 1 then
                                system.Print("Cã c¸c ký tù: ")
                        end
                        for _, i in pairs(char) do
                                table.insert(dwArray, ASCII(i))
                        end
                        return dwArray
                end,
               
                default = function()
                       
                        if nDebug == 1 then
                                system.Print("Ký tù: "..char.." lo¹i "..type(char))
                        end
                        local nASCII = Switch(type(char)){
                                ["number"] = string.byte(char),
                                ["string"] = function() return Switch(char){
                                                                ["NUL"] = 0, -- Char special
                                                                ["SOH"] = 1,
                                                                ["STX"] = 2,
                                                                ["ETX"] = 3,
                                                                ["EOT"] = 4,
                                                                ["ENQ"] = 5,
                                                                ["ACK"] = 6,
                                                                ["BEL"] = 7,
                                                                ["BS"] = 8,
                                                                ["TAB"] = 9,
                                                                ["LF"] = 10,
                                                                ["VT"] = 11,
                                                                ["FF"] = 12,
                                                                ["CR"] = 13,
                                                                ["SO"] = 14,
                                                                ["SI"] = 15,
                                                                ["DLE"] = 16,
                                                                ["DC1"] = 17,
                                                                ["DC2"] = 18,
                                                                ["DC3"] = 19,
                                                                ["DC4"] = 20,
                                                                ["NAK"] = 21,
                                                                ["SYN"] = 22,
                                                                ["ETB"] = 23,
                                                                ["CAN"] = 24,
                                                                ["EM"] = 25,
                                                                ["SUB"] = 26,
                                                                ["ESC"] = 27,
                                                                ["FS"] = 28,
                                                                ["GS"] = 29,
                                                                ["RS"] = 30,
                                                                ["US"] = 31,
                                                                [" "] = 32,
                                                                ["DEL"] = 127,
                                                                default = string.byte(char)
                                                        } end,
                                default = char
                        }
                        if nDebug == 1 then
                                system.Print(nDebug)
                        end
                        return nASCII
                end
        }
end
Ví dụ:
Code:
function main()
        print(ANSI("a", "b", "c"))
-- 97 98 99
end
Hàm ANSI này dùng để kết chuyển ký tự Alpha bình thường thành các Ký tự ANSI để sử dụng cho hàm SendKey(DWORD dwKey, BOOL bKey).
dwKey: mã của phím cần gởi.

bKey: chứa 2 giá trị 1 là phím đặc biệt, 0 là phím ký tự.
Khi nào xài bKey:

Nếu các bạn muốn truyền ký tự liên tục thì cho bKey là 0.
Code:
system.SendKey(ASCII(1), 0)
system.SendKey(ASCII(2), 0)
Send phím 1 2 vào Game.



Các bạn muốn truyền 1 ký tự 1 lần sao đó kết thúc một hành động như đóng Dialog, Xác Nhận Dialog thì dùng:
Code:
system.SendKey(ASCII("CR"), 1) -- Xác nhận Dialog

Trong Võ Lâm có vài Event, bắt nhập số vào và nhấn nút xác nhận để nhận.

Cấu trúc loại Dialog đó:

Code:
[Tên Dialog]
[1] -- Nhập số
[Xác nhận] [Hủy bỏ]

Để nhập được số vào Dialog đó thì các bạn phải xóa con số 1 đó trước và gởi vào số lượng các bạn cần vào.

Code:
if dialog.IsVisible() == 1 then
        system.SendKey(8, 0) -- BS: BackSpace
        system.SendKey(49, 0) -- Gởi phím 1
        system.SendKey(51, 0) -- Gởi phím 3
-- Nhap vao so 13

-- Xac nhan
        -- system.SendKey(13, 1) -- CR: Carriage Return, Enter

end

Có thể chuyển và dạng dễ hiểu hơn khi sử dụng hàm ANSI ở trên:

Code:
if dialog.IsVisible() == 1 then
        system.SendKey(ASCII("BS"), 0) -- BS: BackSpace
-- Gởi phím:
        system.SendKey(ASCII(1), 0) -- 1
        system.SendKey(ASCII(3), 0) -- 3
-- Gởi phím Enter:
        -- system.SendKey(ASCII("CR"), 1) -- CR: Carriage Return, Enter
end

Để tiện hơn nữa có thể khai báo hàm SendKey:

Code:
General.SendKey = function(dwKey, bKey)
        if nDebug == 1 then
                system.Print("Hµm SendKey!")
        end
        if type(dwKey) == "table" then
                for _, iKey in ipairs(dwKey) do
                        if nDebug == 1 then
                                system.Print("Send Key: "..iKey)
                        end
                        system.SendKey(iKey)
                end
        else
                if nDebug == 1 then
                        system.Print("Send Key: "..dwKey)
                end
                system.SendKey(dwKey, bKey)
        end
       
end

Cách sử dụng hàm General.SendKey (Hàm SendKey này sử dụng giống như system.SendKey nhưng được mở rộng hơn Send 1 lúc nhiều Ký tự):

Code:
if dialog.IsVisible() == 1 then
-- Xóa số 1, và gởi số 1 3 vào
        General.SendKey(ASCII("BS", 1, 3), 0) -- 3
-- Gởi phím Enter kết thúc quá trình:
        -- General.SendKey(ASCII("CR"), 1) -- CR: Carriage Return, Enter
end

http://newbie.us.to
Admin
Admin
Admin
Hàm RunPath bên JXQuest có thể được định nghĩa lại như (Không có cơ chế chống lag hữu hiệu khi đi đường dài):
Code:
nAutoRideHorse = 1
nDelay = 10 -- 10s
nRange = 100 -- Pham vi 100
RunPath = function(tbPath)
        local nSize = table.maxn(tbPath)
        local i = 1
        while i < nSize do
                if nAutoRideHorse == 1 then -- Kick chuc nang len ngua
                        while  player.IsRideHorse() == 0 and item.GetEquipmentIndex(10) ~= 0 do
                                player.ExecuteScript("Switch([[horse]])") timer.Sleep(500)
                        end
                end
                i = (General.MoveTo(tbPath[i][1],tbPath[i][2]) == 0) and i - 1 or i + 1
                if i == 0 then return end
        end
end

General.MoveTo = function(nX, nY)
        local nPlrX, nPlrY = player.GetMapPos()
        local nTimeBegin = os.clock()
        while General.GetDistance(nPlrX, nPlrY, nX, nY) > nRange * nRange do
                player.MoveTo(nX, nY)
                nPlrX, nPlrY = player.GetMapPos()
                if os.clock() - nTimeBegin > nDelay then
                        return 0 -- Lag
                end
        end
        return 1
end

General.GetDistance = function(nX, nY, nX2, nY2)
        return (nX - nX2) * (nX - nX2) + (nY - nY2) * (nY - nY2)
end

Cách sử dụng:
Code:
RunPath(tbInside)

http://newbie.us.to
Admin
Admin
Admin
Hàm LeftTrim, RightTrim, Trim: (Dùng để cắt khoảng trắng tiện lợi cho việc lấy tên Menu, Dialog,...)
Code:
LeftTrim = function(stText)
        if stText == nil or stText == "" then
                return ""
        end
        return string.gsub(stText, "^(%s*)(%w*)", "%2")
end

RightTrim = function(stText)
        if stText == nil or stText == "" then
                return ""
        end
        return string.gsub(stText, "(%w*)(%s*)$", "%1")
end

Trim = function(stText)
        if stText == nil or stText == "" then
                return ""
        end
        return LeftTrim(RightTrim(stText))
end

Trim: (Cắt bỏ khoảng trắng ở 2 đầu Text).

Code:
system.Print(Trim("      a    "))
 -- > "a"

RightTrim: (Cắt bỏ khoảng trắng ở bên Phải).

Code:
system.Print(RightTrim("      a    "))
 -- > "      a"

LeftTrim: (Cắt bỏ khoảng trắng ở bên Trái).

Code:
system.Print(LeftTrim("      a    "))
 -- > "a    "

http://newbie.us.to
Admin
Admin
Admin
Sẵn đây G xin chia sẻ thêm 1 hàm ClickText() đã loại bỏ qua 1 số giai đoạn Sleep() để tăng tốc Script đến mức nhanh nhất có thể.

Hàm WaitTitleOther: Dùng để đợi menu khác xuất hiện. Trong quá trình thi hành Click Menu sẽ có khoảng thời gian để chờ menu khác xuất hiện. Nếu các bạn không sử dụng hàm timer.Sleep(xxxx) thì sẽ thông báo lỗi hoặc nhấn nhầm Menu vừa nhấp (Vì menu đó chưa kịp mất hẳn). Hàm này G sẽ lồng vào hàm Click để tiện cho việc nhấp Menu.

Code:
-- nType: Loai menu
stNameTitle = nil
WaitTitleOther = function(nType)
        checkName = menu.GetTitle(nType)
        while checkName == nil or stNameTitle == checkName or Trim(checkName) == "" do
                nType = General.IsMenu
                if menu.IsVisible(0) == 1 then
                        nType = 0
                elseif menu.IsVisible(1) == 1 then
                        nType = 1
                end
                checkName = menu.GetTitle(nType)
        end
        stNameTitle = checkName
        return checkName
end

Hàm ClickIndex: Click theo Index đã định.

Code:
ClickIndex = function(nType, nIndex)
        WaitTitleOther(nType)
        stNameTitle = (stNameTitle ~= nil) and stNameTitle or ""
       
        menu.ClickIndex(nIndex)
       
        stNameTitle = menu.GetTitle(nType)
        return stNameTitle
end

Hàm FindText: Dùng để tìm Menu được lặp lại 2 đến 3 lần, hoặc loại Menu tương đối.
nType: Loại menu.
nText: Dòng tên menu. (G đã sai khi đặt tên biến là số nguyên)
nAbsolute: Tìm kiếm dạng tương đối (Khác nil, 0 là tìm Tuyệt đối phải đúng hết tất cả chữ trên dòng)
nPos: Vị trí dòng (Giả sử như là Phôc L­u ®éng (Phục Lưu Động) thường thì trong xa phu sẽ lưu lại 2 ~ 3 dòng, nên việc Click sẽ khó khăn cho những ai làm Script Mua Thổ Địa Phù)
Hàm trả ra Index của menu được tìm thấy.

Code:
FindText = function(nType, nText, nAbsolute, nPos)
        local nIdLast
        assert(nType, "H·y nhËp lo¹i Menu muèn t×m Text")
       
        nPos = (nPos) and nPos - 1 or 0
        for nIndex = 0, menu.GetCount(nType) - 1 do
                if not nAbsolute then
                        if Trim(menu.GetText(nType, nIndex)) == Trim(nText) then
                                if nPos == nil or nPos == 0 then
                                        return nIndex
                                else
                                        nIdLast = nIndex
                                        nPos = nPos - 1
                                end
                        end
                else
                        if nDebugFunc == 1 then
                                system.Print(Trim(menu.GetText(nType, nIndex)).." - "..Trim(nText))
                        end
                        if system.MatchString(Trim(menu.GetText(nType, nIndex)), Trim(nText)) == 1 then
                                if nPos == nil or nPos == 0 then
                                        return nIndex
                                else
                                        nIdLast = nIndex
                                        nPos = nPos - 1
                                end
                        end
                end
        end
        if nLast ~= nil or nLast ~= 1 then
                return nIdLast
        end
        return nil
end

Hàm ClickText: Được kết hợp hàm WaitTitleOther, Trim, FindText
nType: Loại Menu.
stText: Tên dòng Menu.
nAbsolute: Bật tắt tính năng Tìm kiếm tương đối (Mở: 1, Tắt: 0, nil hoặc bỏ Trống)
nPos: Vị trí dòng Menu. (Đầu tiên: Bỏ tróng, Ở cuối: -1, ở những vị trí khác thì để vào).

Code:
ClickText = function(nType, stText, nAbsolute, nPos)
        if nDebugFunc == 1 then
                system.Print(nType.. - "..tostring(stText).." - "..tostring(stNameTitle).." - "..tostring(nAbsolute).." - "..tostring(nLast))
        end
        WaitTitleOther(nType)
       
        nAbsolute = (nAbsolute == nil) and 0 or nAbsolute
        nPos = (nPos ~= nil) and nPos or 0
        -- Tìm o  -1: Cuoi
        stNameTitle = (stNameTitle ~= nil) and stNameTitle or ""
       
        if not nAbsolute then
                menu.ClickText(nType, stText)
        else
                if nDebugFunc == 1 then
                        system.Print(nType.." - "..tostring(stText).." - "..tostring(stNameTitle).." - "..tostring(nAbsolute).." - "..tostring(nLast))
                end
                menu.ClickIndex(nType, FindText(nType, stText, nAbsolute, nPos))
        end
        stNameTitle = menu.GetTitle(nType)
        return stNameTitle
end

Cách sd:

Code:
while menu.IsVisible(1) == 0 do
if menu.IsVisible(1) == 0 then player.SetPeopleIndex(nNpcIndex) end
end
ClickIndex(1, 0)
ClickIndex(0, 0)
ClickIndex(0, 0)

http://newbie.us.to
Admin
Admin
Admin
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 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 VAuto phiên bản mới có thể có lỗi.

http://newbie.us.to
Admin
Admin
Admin
Bên VAuto, Vulan, cả hai đều không có tương tác nhiều với TONG (Bang hội), thành ra không thể Viết bằng Script. Như Auto Kid thì có hàm xử lý bên ngoài không phụ thuộc vào các Công Thức Hàm LUA của Võ Lâm nên muốn làm sao cũng được.

Sẵn tiện, G chia sẻ cho các bạn Script Mua Thổ Địa phù trên Đào Hoa Nguyên Đảo (Script làm theo nhân vật của G). Ở Script này phải nhớ Cửa Động Phục Lưu Động
gần nhất. Xa hơn thì Script này không chạy được. Đây là Script lúc đó G
viết dành riêng cho các acc Cày tiền thôi. Các bạn nào cần thì Hãy sữa
lại cho phù hợp với Player của bạn.

Code:
pGeneralLib = system.GetScriptFolder().."\\LIB\\General.lua"
IncludeFile(pGeneralLib) -- Load Lib
---------------------------------------------------------------------------------------
--Duong di co the chua chuan, nguoi dung co the dieu chinh lai cho phu hop
nPath = {
                        {49322,98384}, -- cua vao Vulangson
                        {50187,99146},
                        {51214,100104},
                        {52329,101090},
                        {53428,99728},
                        {54854,98258},
                        {55609,97266},
                        {55523,96682},
                        {54479,95770},
                        {53534,94954},
                        {52683,94298},
                        {51547,93186},
                        {50609,92562},
                        {50368,92672},
                        {50068,92472}, -- >Dao Hoa Nguyen
                       
                        {54097,104596}, -- nga 3 DHN
                        {53186,104342},
                        {52620,103792}, -- cong vao
                        {52261,103300},
                        {52101,102814},
                        {52115,102788}-- Tiem tap hoa
}
---------------------------------------------------------------------------------------
BuyTDP = function(nCount)
        --system.Print(nCount)
       
        nMoney = player.GetMoney(1) -- Hanh Trang
        player.ExchangeMoney(0, 100000)
        General.TalkToNPC("Chñ tiÖm t¹p hãa")
       
        General.ClickText(1, "Giao dÞch", 1)
       
        MountOrg = General.CountItem(3,"Thæ ®Þa phï")
        TownPortalCurrent = MountOrg
        timer.Sleep(1000)
        for i = 1, nCount do
                shop.Sell(0)
                while General.CountItem(3,"Thæ ®Þa phï") == MountOrg do
                        timer.Sleep(5)
                end
                MountOrg = General.CountItem(3,"Thæ ®Þa phï")
        end
       
        shop.Close()
end

XaPhu_To_DaoHoaNguyen =function()
        player.PathMoveTo(0,0,"Xa phu")
        General.TalkToNPC("Xa phu")
       
        General.ClickText(1, "Nh÷ng n¬i ®· ®i qua", 1)
       
        General.ClickText(1, "Phôc L­u ®éng", 1, 1)
       
        General.WaitSwitch()
end
---------------------------------------------------------------------------------------
To_DaoHoaNguyen = function()
        local nSize = table.maxn(nPath)
        local i = 1
        while i < nSize do
                while player.IsRideHorse() == 0 and item.GetEquipmentIndex(10) ~= 0 do
                        player.ExecuteScript("Switch([[horse]])") timer.Sleep(200)
                end
                local bOke = General.MoveTo(nPath[i][1],nPath[i][2])
                if bOke == 0 then i = i - 1  --TimeOut->quay lui
                else i = i + 1 end
                if i == 0 then return end
        end
end
---------------------------------------------------------------------------------------
ReturnCityBuyTDP = function()
        nMoney = player.GetMoney(0) -- Hanh Trang
        -- system.Print("Sè tiÒn: "..nMoney)
       
        if nMoney > 5000 then
                nMoney = nMoney - 5000
                player.ExchangeMoney(1, nMoney)
        else
                nMoney = 5000 - nMoney
                player.ExchangeMoney(0, nMoney)
        end
        General.MoveTo(52261,103300)
        General.MoveTo(52620,103792) -- cong vao
        General.MoveTo(52880,103964)
        General.Use(3, "Thæ ®Þa phï")
end
---------------------------------------------------------------------------------------
function main()
        control.PauseAll()      --Dung moi dieu khien cua auto
        -- if GetKillerStatus() ~= 0 then
                control.ResetAutoFight()
        -- end
        nMoney = player.GetMoney(0) -- Hanh Trang
        system.Print("Sè tiÒn: "..nMoney)
        local nCount = 0 -- 0 Full
        local nEmpty = General.IsEmpty(3)
        nCount = (nCount == 0) and nEmpty or ((nCount > nEmpty) and nEmpty or nCount)
       
        if nMoney > 5000 then
                nMoney = nMoney - 5000
                player.ExchangeMoney(1, nMoney)
        else
                nMoney = 5000 - nMoney
                player.ExchangeMoney(0, nMoney)
        end
       
        if map.GetID() == 55 then
                BuyTDP(nCount)
                ReturnCityBuyTDP()
        elseif map.GetID() == 73 then
                To_DaoHoaNguyen()
                BuyTDP(nCount)
                ReturnCityBuyTDP()
        else
                XaPhu_To_DaoHoaNguyen()
                To_DaoHoaNguyen()
                BuyTDP(nCount)
                ReturnCityBuyTDP()
        end
        system.Print("Hoµn Thµnh!")
end
---------------------------------------------------------------------------------------

http://newbie.us.to
Admin
Admin
Admin
@Zindo: Bạn thử sử dụng hàm System.etKey() thử xem. Hàm này phải đưa vào vòng lặp thì phải. Hàm này chỉ đành cho VAuto thôi (Vulan không có). Nếu đúng thì ta sẽ có hàm tương ứng với các giá trị.

Code:
Keyname                                Scancode (hex)
"escape"                                0x01
"f1"                                    0x3b
"f2"                                    0x3c
"f3"                                    0x3d
"f4"                                    0x3e
"f5"                                    0x3f
"f6"                                    0x40
"f7"                                    0x41
"f8"                                    0x42
"f9"                                    0x43
"f10"                                  0x44
"f11"                                  0x57
"f12"                                  0x58
"f13"                                  0x64
"f14"                                  0x65
"f15"                                  0x66
"f16"                                  0x67
"f17"                                  0x68
"f18"                                  0x69
"f19"                                  0x6a
"f20"                                  0x6b
"f21"                                  0x6c
"f22"                                  0x6d
"f23"                                  0x6e
"f24"                                  0x76
"printscreen"                          0x137
"scrolllock"                            0x46
"pause"                                0x146
"tilde"                                0x29
"1"                                    0x02
"2"                                    0x03
"3"                                    0x04
"4"                                    0x05
"5"                                    0x06
"6"                                    0x07
"7"                                    0x08
"8"                                    0x09
"9"                                    0x0a
"0"                                    0x0b
"minus"                                0x0c
"equal"                                0x0d
"backspace"                            0x0e
"tab"                                  0x0f
"q"                                    0x10
"w"                                    0x11
"e"                                    0x12
"r"                                    0x13
"t"                                    0x14
"y"                                    0x15
"u"                                    0x16
"I"                                    0x17
"o"                                    0x18
"p"                                    0x19
"lbracket"                              0x1a
"rbracket"                              0x1b
"backslash"                            0x2b
"capslock"                              0x3a
"a"                                    0x1e
"s"                                    0x1f
"d"                                    0x20
"f"                                    0x21
"g"                                    0x22
"h"                                    0x23
"j"                                    0x24
"k"                                    0x25
"l"                                    0x26
"semicolon"                            0x27
"quote"                                0x28
"enter"                                0x1c
"lshift"                                0x2a
"non_us_slash"                          0x56
"z"                                    0x2c
"x"                                    0x2d
"c"                                    0x2e
"v"                                    0x2f
"b"                                    0x30
"n"                                    0x31
"m"                                    0x32
"comma"                                0x33
"period"                                0x34
"slash"                                0x35
"numstar"                              0x37
"numminus"                              0x4a
"num7"                                  0x47
"num8"                                  0x48
"num9"                                  0x49
"numplus"                              0x4e
"num4"                                  0x4b
"num5"                                  0x4c
"num6"                                  0x4d
"num1"                                  0x4f
"num2"                                  0x50
"num3"                                  0x51
"numenter"                              0x11c
"num0"                                  0x52
"numperiod"                            0x53

muốn bắt sự kiện nhấn tổ hợp phím dạng như Ctrl + phím nào đó ta phải dùng vòng lặp while do
VD:
Code:
  if system.GetKey() == 17 then
      while system.GetKey() == 17 do timer.Sleep(10) end
      if system.GetKey() == 65 then
        bạn cần gọi hàm nào thì bỏ vào đây
      end
  end

ở đây là dùng tổ hợp phím ctrl + a nếu bạn dùng phím khác thì thay code ASCII của phím đó vào.
ta dùng hàm if kiểm tra nếu phím ctrl được nhấn thì dùng vòng lặp while
đợi, nếu phím khác được nhấn thì lặp tức thoát vòng lặp và xử lý phím
tiếp theo. Nguyên lý là như vậy.

http://newbie.us.to
langtu1o

chào anh ! em có xem qua các script của anh box rồi.thật sự thì em muốn làm auto võ lâm miễn phí.có script của anh đó nhưng em ko biết làm sao để thực thi hết và để tạo như bác ngọc hoặc bác phương hết.mong anh chỉ rỏ giùm em với nha.cảm ơn anh . anh co thể giúp em qua mail chuyentinh5o@gmail.com. nha anh

Sponsored content

Xem chủ đề cũ hơn Xem chủ đề mới hơn Về Đầu Trang Thông điệp [Trang 1 trong tổng số 1 trang]

Permissions in this forum:
Bạn không có quyền trả lời bài viết