

February | ||||||
---|---|---|---|---|---|---|
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
29 | 30 | 31 | 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 1 | 2 | 3 | 4 |










改了个WOW插件-法师自动补全施法材料
开始重操旧业玩起了WOW,只不过这次玩的是法师。法师有三种施法材料:魔粉,传送符文,传送门符文。用光了会被人质疑为不够专业。材料在包裹里20个一组占一个格子,所以一次买的时候最好买齐20个,省的老是回来补。手动买其实也没啥不方便的,不过能自动还是自动吧,懒人自然有懒想法。
这个功能倒是很常见的功能了,从古到今,带这功能的各种插件和宏都流传了不少。不过我这不是没装嘛。特地去为了这点事情而找个东西,实在太费劲了,不如自己直接添上。我在已经装了的一个叫AutoRepair的插件上开始修改。AutoRepair,顾名思义就是自动修理装备用的,修理装备会需要打开商店界面,用到MERCHANT_SHOW这个事件,这样就省得我自己去注册了。
AutoRepair插件分三个文件,一个AutoRepair.toc,一个AutoRepair.xml,一个AutoRepair.lua。 toc结尾的文件可以无视,xml文件则如下:
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\..\FrameXML\UI.xsd"> <Script file="AutoRepair.lua"/> <Frame name="frmautorepair"> <Scripts> <OnEvent> arEvent(); </OnEvent> <OnLoad> arInit(); </OnLoad> </Scripts> </Frame> </Ui>
很简单明了,arInit() 里面注册了事件,arEvent()则是事件处理。那么很明显,我需要在arEvent()里面加点东西。
AutoRepair.lua的arEvent():
function arevent(self, event) if armode==nil then armode=0; end if (event=="MERCHANT_SHOW" and CanMerchantRepair()==1) then repairAllCost, canRepair = GetRepairAllCost(); if (canRepair==1) then if(armode<=1) then if( repairAllCost<=GetMoney() ) then RepairAllItems(0); DEFAULT_CHAT_FRAME:AddMessage("Your items have been repaired for "..GetCoinText(repairAllCost,", ")..".",255,255,0); else DEFAULT_CHAT_FRAME:AddMessage("You don't have enough money for repair!",255,0,0); end end if(armode==2 or armode==3)then RepairAllItems(1); end if(armode==2) then if( repairAllCost<=GetMoney() ) then RepairAllItems(0); DEFAULT_CHAT_FRAME:AddMessage("Your items have been repaired for "..GetCoinText(repairAllCost,", ")..".",255,255,0); else DEFAULT_CHAT_FRAME:AddMessage("You don't have enough money for repair!",255,0,0); end end end end if (event=="VARIABLES_LOADED") then arStatus(); end end
它把事件处理放在了一个 if 中,只不过后面又跟了个判断是否可以修理的CanMerchantRepair(),这样的话我还是不要直接塞进它的 if 里面,而是跟在最后面比较好。在第二个事件 VARIABLE_LOADED 处理了之后,加上:
if (event =="MERCHANT_SHOW" ) then local itemid = 17020; --魔粉 fillItem(itemid); itemid = 17031; --传送符文 fillItem(itemid); itemid = 17032; -- 传送门符文 fillItem(itemid); end
itemid 是物品编号,这个是从在线数据库查的,肯定准。这里加了一个函数fillItem, 内容如下:
function fillItem(itemid) local item_name = GetItemInfo(itemid); local item_count = GetItemCount(itemid); for i=0,GetMerchantNumItems() do if GetMerchantItemInfo(i) == item_name then BuyMerchantItem(i,20-item_count); DEFAULT_CHAT_FRAME:AddMessage("Buy "..item_name.." "..(20-item_count)); end end end
主要是调用了几个API,查API可以到wowwiki上找,很全很好用。
添加完后,保存关闭,进游戏,找到材料商人,状况良好: