|
战士的姿态机制让战士这个技能少到可怜的职业有了更多的玩法,而且防御姿态常驻20%减伤的效果更让战士成了PVP里最肉的职业,但是战士的怒气获取只有在战斗姿态下才能大量获得,所以利用战斗记录的函数很好的解决了这个问题。
我要实现的效果就是,如果目标在攻击距离内,并且我的平砍CD已经结束,那么切换到战斗姿态砍一刀,否则,永远防御姿态。
首先写一个战斗记录的提取函数:
- [mw_shl_code=lua,true]function xr_OnLoad()
- if not xrF then
- xrF = CreateFrame("Frame");
- xrF:SetScript("OnUpdate", xr_OnUpdate);
- xrF:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
- xrF:SetScript("OnEvent",xrF_OnEvent);
- end
- end
- function xrF_OnEvent(self,event,...)
-
- local subEvent
- local sourceGUID
- local sourceName
- local destGUID
- local destName
- local destFlags
- local destRaidFlags
- local spellID
- local spellName
- local auraType
- local extraSpellName
- local auraType2
- if event == "COMBAT_LOG_EVENT_UNFILTERED" then
- subEvent = select(2,...)
- sourceGUID = select(4,...)
- sourceName = select(5,...)
- destGUID = select(8,...)
- destName = select(9,...)
- destFlags = select(10,...)
- destRaidFlags = select(11,...)
- spellID = select(12,...)
- spellName = select(13,...)
- auraType = select(15,...)
- extraSpellName = select(16,...)
- auraType2 = select(18,...)
- end
-
- if subEvent == "SWING_DAMAGE" and sourceName == UnitName("player") then
- swingtimer = GetTime()
- swingtimer = (GetTime() + UnitAttackSpeed("player") - getLatency())
- end[/mw_shl_code]
复制代码 用xr_OnLoad()这个函数来激活战斗记录提取模块,你可以把这个函数的位置写到你的插件核心层,也可以写到职业脚本层,此模块会大量消耗CPU和内存,建议在大型战场上不要使用。
function xrF_OnEvent(self,event,...)是用来把战斗记录分类的,从中提取你想要的战斗信息点。
下面这段代码用来判定我们的平砍CD是否结束
if subEvent == "SWING_DAMAGE" and sourceName == UnitName("player") then
swingtimer = (GetTime() + UnitAttackSpeed("player") - getLatency())
end
subEvent == "SWING_DAMAGE" 用来表示战斗记录中一次平砍动作。
sourceName == UnitName("player") 用来确定这一次平砍动作是由玩家产生的。
swingtimer = (GetTime() + UnitAttackSpeed("player") - getLatency())就是确定平砍CD结束的时间,其中GetTime()用来确认上一次平砍成功的时间,UnitAttackSpeed("player")是玩家的攻击速度,getLatency()是网络延迟函数(这个函数是GH或者BB的,如果你用**插件请相应更改)
完成这些以后,我们可以在脚本中写入下面的函数来实现能平砍一下的时候砍一下,其余时间永远防御姿态:
if swingtimer ~= nil and swingtimer <= GetTime() and getDistance("player","target") <= 4 and getFacing("player","target") and UnitPower("player") <= 78 then if castSpell("player",2457,true,false) then end end if (swingtimer ~= nil and swingtimer > GetTime()) or UnitPower("player") > 78 then if castSpell("player",71,true,false) then end end
以上代码已经过测试,非常好用。在PVP战斗中,如果情况非常紧急,可以加入嘲讽的代码来解除姿态GCD。
|
|