[教程]如何写一个WLK怀旧服的 WA字符串一键输出脚本?

助手阿喜 Games评论8字数 3252阅读10分50秒阅读模式

核心逻辑,如何交互

首先自定义一个WA字符串,设定一个正方形(方便捕捉),然后这个材质位置放在屏幕中间,或者窗口的4个角落的一个位置。文章源自助手阿喜-https://zsaxi.com/5028

然后我们要做的就是,识别角色技能,当前状态,目标状态等信息。然后给这个对外展示的 正方形图标 根据不同需求 定义不同颜色。文章源自助手阿喜-https://zsaxi.com/5028

例如我们在 动作标签页,设置一个叫做 aura_env.KW 动作来定义 W按键,用来打断施法。对应WA的颜色是 (0.36,0.8,0.51,1),文章源自助手阿喜-https://zsaxi.com/5028

aura_env.KW = function()
WeakAuras.regions[aura_env.id].region.texture:SetColorTexture(0.36,0.8,0.51,1) --√ 82CC5C
end文章源自助手阿喜-https://zsaxi.com/5028

对应外部程序如 按键精灵/Python都可以识别指定窗口指定位置的颜色,那么当我们的外部程序文章源自助手阿喜-https://zsaxi.com/5028

识别到 当前颜色是 82CC5C的时候,就向对应窗口发出一次 W按键的命令,文章源自助手阿喜-https://zsaxi.com/5028

aura_env.undo = function()
WeakAuras.regions[aura_env.id].region.texture:SetColorTexture(0.51,0.95,0.65,1) --√ A6F282
end文章源自助手阿喜-https://zsaxi.com/5028

 文章源自助手阿喜-https://zsaxi.com/5028

设置一个 不作操作的命令,也就是程序识别到 这个颜色的时候,不做操作。文章源自助手阿喜-https://zsaxi.com/5028

 文章源自助手阿喜-https://zsaxi.com/5028

那么如何获取技能是否可用等信息呢? 这里我用自带的API写了一个命令。有时候例如 潜行者的 血之饥渴,需要流血状态才能使用,那么我们就不能直接判断 是否能量满足条件,canuse,cancast 两个返回,文章源自助手阿喜-https://zsaxi.com/5028

canuse 代表了,当前角色天赋,可用这个技能,cancast 表示当前角色能量满足条件,并且技能处于冷却状态GCD已经结束。文章源自助手阿喜-https://zsaxi.com/5028

    local function GetSpellinfos(spellname) -- 可以直接写 是否可用, 先判断 GetSpellInfo 是否已学 没学直接返回 false ,在判断 可用还是冷却中,然后判断消耗能量 自身能量是否满足。如果都满足 返回true 反之 false
		local spellcan,spellcool=false,false
		local startTime000,Duration1000=nil,nil
		local needpower=nil
		local cancast =false
		local canuse = false 
		local spellIDs = select(7, GetSpellInfo(spellname))  -- 返回 技能信息,没学的技能返回 nil  
		if spellIDs == nil then
		return canuse,cancast
		end
		canuse = true 
		if spellname ~=nil and spellname~="" then
			spellcan,spellcool = IsUsableSpell(spellname) -- 判断技能是否能释放,还是冷却中,没有学的技能也会显示 IsUsableSpell("闪现")
		end	
		startTime000, Duration1000 = GetSpellCooldown(spellname) --直接返回剩余时间
		if Duration1000~=nil and startTime000~=nil then
		Duration1000 = startTime000 + Duration1000 - GetTime()  
		end
        if spellIDs~=nil then
            local success, cost = pcall(function() return GetSpellPowerCost(spellIDs)[1].cost end)
            if not success then
                needpower = 0
            else
                needpower = GetSpellPowerCost(spellIDs)[1].cost 
            end
        end		 
 
		if spellcan==true and Duration1000<=0 and needpower~=nil and UnitPower("player")>= needpower then
		cancast = true
		else
		cancast = false
		end
		return canuse,cancast
    end

那么下面就是 根据自身对角色的了解,对技能进行排序了。文章源自助手阿喜-https://zsaxi.com/5028

 文章源自助手阿喜-https://zsaxi.com/5028

 文章源自助手阿喜-https://zsaxi.com/5028

那么如果是治疗职业,如何快速找出团队中血量百分比最低的 目标呢?文章源自助手阿喜-https://zsaxi.com/5028

这段代码使用了百分比最为参考目标文章源自助手阿喜-https://zsaxi.com/5028

aura_env.Missed_tars[UnitName(unitName)] ==nil or evnTime *1000-aura_env.Missed_tars[UnitName(unitName)]>=1000  这里使用了 黑名单,如果目标不在视野内,我们将目标拉黑 1秒钟,1秒钟之后才重新来处理这个目标文章源自助手阿喜-https://zsaxi.com/5028

                local health_percentages = {} -- 你的具体实现代码将在此填充该表。
                health_percentages["player"] = UnitHealth("player") / UnitHealthMax("player") *100 
                for i=1,25 do  
                    health_percentages["raid"..i] = UnitHealth("raid"..i) / UnitHealthMax("raid"..i) *100 
                end
                   
                local target = nil  -- 初始时没有目标
                -- 遍历所有单位,查找合适的作为目标的治疗单位
                for unitName, health_percent in pairs(health_percentages) do
                    if health_percent > 0 and not  UnitIsDeadOrGhost(unitName) and IsSpellInRange("你的治疗技能", unitName) == 1  and  health_percent< 100  and  ( aura_env.Missed_tars[UnitName(unitName)] ==nil or evnTime *1000-aura_env.Missed_tars[UnitName(unitName)]>=1000 )  then
                        -- 检查当前单位是否比已知的任何单位血量百分比低(即更紧急)
                        if not target or health_percent < health_percentages[target] then
                            target = unitName  -- 更新目标为当前单位
                        end
                    end
                end

 文章源自助手阿喜-https://zsaxi.com/5028

,如果你要是用掉血血量来作为参考,这一段我们使用掉血多少来判断哪个目标更需要加血。文章源自助手阿喜-https://zsaxi.com/5028

不过一般我们加血都是看框架按照百分比选择目标的。

 local health_percentages = {} -- 你的具体实现代码将在此填充该表。
health_percentages["player"] =   
for i=1,25 do 
health_percentages["raid"..i] =  UnitHealthMax("raid"..i) -UnitHealth("raid"..i) 
end

local target = nil -- 初始时没有目标
-- 遍历所有单位,查找合适的作为目标的治疗单位
for unitName, health_percent in pairs(health_percentages) do
if health_percent > 0 and not UnitIsDeadOrGhost(unitName) and IsSpellInRange("恢复", unitName) == 1 and health_percent< 100 and ( aura_env.Missed_tars[UnitName(unitName)] ==nil or evnTime *1000-aura_env.Missed_tars[UnitName(unitName)]>=1000 ) then
-- 检查当前单位是否比已知的任何单位血量百分比低(即更紧急)
if not target or health_percent < health_percentages[target] then
target = unitName -- 更新目标为当前单位
end
end
end

 

  • 扫码入群
  • 加群获取附件资源,请查看教程说的资源名称查找。
  • weinxin
  • 支持打赏
  • 如果觉得本文对你有帮助,可以打赏任意金额已维持网站运行。
  • weinxin
助手阿喜
  • 本文由 发表于 2024年9月26日 21:44:26