fireicelj 发表于 2014-10-28 13:12:38

useItem()函數的BUG

使用useItem()函數時,例子:
if BeeUnitHealth("player","%")<50 then
      useItem(5512);
      return;
end

“5512”為治療石的ID。由於useItem()函數沒有返回值,當物品為空或沒有時,會卡技能。

建議代碼如下修改:
function useItem(itemID)
        if GetItemCount(itemID,false,false) > 0 then
                if select(2,GetItemCooldown(itemID))==0 then
                        RunMacroText("/use "..tostring(select(1,GetItemInfo(itemId))));
                        return true;
                end
        end
        return false;
end

代碼修改后,使用例子如下:
if BeeUnitHealth("player","%")<50 then
    if useItem(5512) then
      return;
    end
end

修改后可正常施放技能。

{:5_236:}

丁丁 发表于 2014-10-28 13:41:36

哇~~~~~{:5_124:}

玄月无尘 发表于 2014-10-28 14:11:04

非常认真,但是不能那样改,会影响到其他函数的参数格式,GH尽量不使用RunMacroText。

wdbw 发表于 2016-12-30 17:34:17

页: [1]
查看完整版本: useItem()函數的BUG