function keypressEx(keycode)
hWar3 = getwar3window()
sendmessage(hWar3, 256, keycode, 0)
sleep(10)
sendmessage(hWar3, 257, keycode, 0)
end
function hasRes(hHD)
hasPurif_=false
for i=0,5,1 do
gHD,gID,gNUM= getunititem(hHD,i)
if gID==sRes and gNUM>0 then
hasPurif_ = true
end
end
return hasPurif_
end
function search(heroID)
distHero = nil
haResHero = 0
keypressEx(112)
sleep(tSleep)
hnID,hnHD = getcurrentunit()
if hID==heroID then
distHero = 'F1'
end
if hasRes(hnHD) then
haResHero = 112
end
for iPos=1,4,1 do
hoID = hnID
keypressEx(112+iPos)
iTick = gettickcount()
while true do
hnID,hnHD = getcurrentunit()
if hnID~=hoID or (gettickcount()-iTick)>tSleep then
break
end
end
if hnID==hoID then
break
end
iPos = iPos + 1
if hnID==heroID then
distHero = 'F'..iPos
end
if hasRes(hnHD) then
haResHero = 112+iPos-1
end
end
return distHero,haResHero
end
function searchPosition(heroID)
keypressEx(112)
sleep(tSleep)
hnID,hnHD = getcurrentunit()
if hnID==heroID then
return 'F1'
end
for iPos=1,4,1 do
hoID = hnID
keypressEx(112+iPos)
iTick = gettickcount()
while true do
hnID,hnHD = getcurrentunit()
if hnID~=hoID or (gettickcount()-iTick)>tSleep then
break
end
end
if hnID==hoID then
break
end
iPos = iPos + 1
if hnID==heroID then
return 'F'..iPos
end
end
return nil
end
setkeywatch('keyhookfunc')
function keyhookfunc(keycode, controlkey, downorup)
if 0==iswar3front() then return 0 end
if 1==ischat() then return 0 end
if keycode==192 and 16==controlkey then
hID,hHD = getcurrentunit()
if hID~=nil and hID~='' then
hDestID = hID
end
return 1
end
if keycode==ClickKey and downorup==0 then
hoID = ''
hoHD = ''
hnID = ''
hnHD = ''
thisdistH = ''
thisHaRes = 0
hcurID, hcurHD = getcurrentunit()
thisdistH, thisHaRes = search(hDestID)
if thisdistH~= nil then
if thisHaRes~=0 then
sleep(1)
keypressEx(thisHaRes)
sleep(tSleep)
runkeys('使用物品'..sRes..' 左击英雄头像'..thisdistH)
end
if isReturnCur then
sleep(tSleep)
hcerHero = searchPosition(hcurID)
if hcerHero~=nil then
sleep(tSleep)
runkeys('左击英雄头像'..hcerHero..' 左击英雄头像'..hcerHero)
end
end
end
return 1
end
return 0
end 作者: ychqb_123 时间: 2012-8-29 21:51
如果想改成对敌方使用这个道具 要需要修改哪些?