[Lua] 纯文本查看 复制代码 function BeeGroupMinFastScript(String, StrReturn, group) -- 小队或者团队里最小的数值的人物信息
if not(group == "party" or group == "partypet" or group == "raid" or group == "raidpet" or group == "arena" or group == "arenapet") then
print("|cffff0000 group 参数不对") -- 如果group参数不正确,则打印错误信息
return false
end
if String == nil or StrReturn == nil then
print("|cffff0000 String 或 StrReturn 参数不能为空") -- 如果String或StrReturn参数为空,则打印错误信息
return false
end
local vname = "BeeGroupMinFast"; -- 定义一个局部变量vname,用作后面脚本的标识
local str = 'function TEMP_BeeGroupMinFast(name,class,race,spell,unit,guid,spellcd) if ' .. String .. ' then return ' .. StrReturn .. '; else return false; end end'
-- 定义一个字符串str,它是一个Lua函数的源代码,这个函数后面会被执行
if BeeGetVariable(vname .. "_Str", str) then
if BeeGetVariable(vname .. "_Str", str) ~= str then
RunScript(str); -- 如果之前存储的函数源代码与新的str不同,则执行新的函数源代码
end
else
RunScript(str); -- 如果之前没有存储函数源代码,则执行函数源代码
BeeSetVariable(vname .. "_Str", str); -- 存储函数源代码
end
local unit;
local Members, minimum, temp_unit;
local temp_n = nil;
if group == "party" or group == "partypet" then
Members = GetNumPartyMembers() + 1; -- 如果是小队或小队宠物,则计算成员数
elseif group == "raid" or group == "raidpet" then
Members = GetNumRaidMembers(); -- 如果是团队或团队宠物,则计算成员数
elseif group == "arena" then
Members = 5; -- 如果是竞技场,则成员数为5
elseif group == "arenapet" then
Members = 5; -- 如果是竞技场宠物,则成员数为5
end
for i = 1, Members do
if i == Members and group == "party" then
unit = "player"; -- 如果是最后一个小队成员,则检查玩家自己
elseif i == Members and group == "partypet" then
unit = "pet"; -- 如果是最后一个小队宠物,则检查宠物
else
unit = group .. tostring(i); -- 否则构造单元的名称
end
if UnitName(unit) then
minimum = TEMP_BeeGroupMinFast(unit); -- 调用之前定义的函数,传入当前单元
if minimum then
if temp_n == nil then
temp_n = minimum; -- 如果是第一个有效的最小值,则保存
temp_unit = unit;
elseif minimum < temp_n then
temp_n = minimum; -- 如果当前值更小,则更新保存的值
temp_unit = unit;
end
end
end
end
if temp_unit then
BeeSetVariable(vname .. "_Unit", temp_unit); -- 如果找到了有效的单元,则存储它
return temp_unit; -- 返回找到的单元
end
return false -- 如果没有找到,则返回false
end |