sky.light9530
11-05-12, 08:04 PM
szNpcName = "Tho ren"
tbClickLine = {6, 2, 2, 2}
nRepeat = 0
--------------------------------------------------------------------------------
nDelay = 100
TalkToNpc = function(szNpcName)
local nPlrX, nPlrY = player.GetMapPos()
local nNpcX, nNpcY = 0, 0
local nIndex = 0
local nDistance = 10000
for i = 2, 255 do
if system.MatchString(npc.GetName(i), szNpcName) ~= 0 then
nNpcX, nNpcY = npc.GetMapPos(i)
if (nPlrX - nNpcX) * (nPlrX - nNpcX) + (nPlrY - nNpcY) * (nPlrY - nNpcY) < nDistance * nDistance then
nDistance = math.sqrt((nPlrX - nNpcX) * (nPlrX - nNpcX) + (nPlrY - nNpcY) * (nPlrY - nNpcY))
nIndex = i
end
end
end
nNpcX, nNpcY = npc.GetMapPos(nIndex)
if (nPlrX - nNpcX)*(nPlrX - nNpcX) + (nPlrY - nNpcY) * (nPlrY - nNpcY) > 65 * 65 then
player.MoveTo(nNpcX, nNpcY)
else
player.DialogNpc(nIndex)
end
end
IsMenuVisible = function()
if menu.IsVisible(0) ~= 0 or menu.IsVisible(1) ~= 0 then
return 1
end
return 0
end
GetMenuText = function(nIndex)
if menu.IsVisible(0) ~= 0 then
return menu.GetText(0, nIndex)
end
if menu.IsVisible(1) ~= 0 then
return menu.GetText(1, nIndex)
end
return ""
end
ClickMenuIndex = function(nIndex)
if menu.IsVisible(0) ~= 0 then
menu.ClickIndex(0, nIndex)
end
if menu.IsVisible(1) ~= 0 then
menu.ClickIndex(1, nIndex)
end
end
DoScript = function()
local szBuffer = ""
local nCount = 0
while true do
while dialog.IsVisible() ~= 0 do dialog.Close() timer.Sleep(nDelay) end
while IsMenuVisible() == 0 do TalkToNpc(szNpcName) timer.Sleep(nDelay) end
for i = 1, table.maxn(tbClickLine) do
szBuffer = GetMenuText(0)
ClickMenuIndex(tbClickLine[i] - 1)
if i < table.maxn(tbClickLine) then
while (szBuffer == GetMenuText(0) or IsMenuVisible() == 0) do timer.Sleep(nDelay) end
end
end
nCount = nCount + 1
if nRepeat > 0 and nCount >= nRepeat then break end
end
end
function StopTimer()
end
function main()
DoScript()
end
tbClickLine = {6, 2, 2, 2}
nRepeat = 0
--------------------------------------------------------------------------------
nDelay = 100
TalkToNpc = function(szNpcName)
local nPlrX, nPlrY = player.GetMapPos()
local nNpcX, nNpcY = 0, 0
local nIndex = 0
local nDistance = 10000
for i = 2, 255 do
if system.MatchString(npc.GetName(i), szNpcName) ~= 0 then
nNpcX, nNpcY = npc.GetMapPos(i)
if (nPlrX - nNpcX) * (nPlrX - nNpcX) + (nPlrY - nNpcY) * (nPlrY - nNpcY) < nDistance * nDistance then
nDistance = math.sqrt((nPlrX - nNpcX) * (nPlrX - nNpcX) + (nPlrY - nNpcY) * (nPlrY - nNpcY))
nIndex = i
end
end
end
nNpcX, nNpcY = npc.GetMapPos(nIndex)
if (nPlrX - nNpcX)*(nPlrX - nNpcX) + (nPlrY - nNpcY) * (nPlrY - nNpcY) > 65 * 65 then
player.MoveTo(nNpcX, nNpcY)
else
player.DialogNpc(nIndex)
end
end
IsMenuVisible = function()
if menu.IsVisible(0) ~= 0 or menu.IsVisible(1) ~= 0 then
return 1
end
return 0
end
GetMenuText = function(nIndex)
if menu.IsVisible(0) ~= 0 then
return menu.GetText(0, nIndex)
end
if menu.IsVisible(1) ~= 0 then
return menu.GetText(1, nIndex)
end
return ""
end
ClickMenuIndex = function(nIndex)
if menu.IsVisible(0) ~= 0 then
menu.ClickIndex(0, nIndex)
end
if menu.IsVisible(1) ~= 0 then
menu.ClickIndex(1, nIndex)
end
end
DoScript = function()
local szBuffer = ""
local nCount = 0
while true do
while dialog.IsVisible() ~= 0 do dialog.Close() timer.Sleep(nDelay) end
while IsMenuVisible() == 0 do TalkToNpc(szNpcName) timer.Sleep(nDelay) end
for i = 1, table.maxn(tbClickLine) do
szBuffer = GetMenuText(0)
ClickMenuIndex(tbClickLine[i] - 1)
if i < table.maxn(tbClickLine) then
while (szBuffer == GetMenuText(0) or IsMenuVisible() == 0) do timer.Sleep(nDelay) end
end
end
nCount = nCount + 1
if nRepeat > 0 and nCount >= nRepeat then break end
end
end
function StopTimer()
end
function main()
DoScript()
end