Hello everyone,
I just made a small PVP script for Arms Warriors. It's my first script, if hope it can be useful.
There may still have some bugs, and it's far from perfect.
If you have any suggestions, please let me know : [email protected]
Code:
function IsCastable(Name, target)
local _, duration, _ = GetSpellCooldown(Name)
if target then
if IsUsableSpell(Name) and duration == 0 and IsSpellInRange(Name, target) == 1 then
return 0
else
return nil
end
else
if IsUsableSpell(Name) and duration == 0 then
return 0
else
return nil
end
end
end
function Equip(item_type)
-- item_types are : "INVTYPE_SHIELD"; "INVTYPE_WEAPON"; "INVTYPE_2HWEAPON"
for s=1,3 do
local i=GetContainerItemLink(0,s)
if i then n,_,r,L,_,t,z,_,e=GetItemInfo(i);
if e==item_type then PickupContainerItem(0,s);AutoEquipCursorItem();
end
end
end
end
local pHP =(UnitHealth("Player")/UnitHealthMax("Player"))
local HP =(UnitHealth("Target")/UnitHealthMax("Target"))
if not UnitBuff("player", "shield wall") then Equip("INVTYPE_2HWEAPON") end
if not UnitBuff("player", "battle shout") then CastSpellByName("battle shout") end
if UnitDebuff("player", "kidney shot") or UnitDebuff("player", "cheap shot") then
if IsCastable("every man for himself") then CastSpellByName("every man for himself") end
if IsCastable("berserker rage") then
SpellStopCasting()
CastSpellByName("berserker rage")
SpellStopCasting()
end
end
if UnitBuff("target", "evasion") and IsCastable("retaliation") then
CastSpellByName("retaliation")
end
local _, duration_sw, _ = GetSpellCooldown("shield wall")
if UnitBuff("target", "evasion") or UnitBuff("target", "divine shield") then
print("should cast shield wall")
if duration_sw == 0 then
Equip("INVTYPE_WEAPON")
Equip("INVTYPE_SHIELD")
if IsCastable("shield wall") then CastSpellByName("shield wall") end
end
end
if IsCastable("enraged regeneration") then CastSpellByName("enraged regeneration") end
if IsCastable("charge", "target") then
CastSpellByName("Charge")
SpellStopCasting()
if IsCastable("Colossus smash", "target") then CastSpellByName("colossus smash") end
SpellStopCasting()
end
if IsUsableSpell("victory rush") and pHP < 0.85 then CastSpellByName("victory rush") end
if not UnitDebuff("target", "rend") and HP > 0.3 and IsCastable("rend", "target") then CastSpellByName("Rend") end
if IsCastable("Mortal strike", "target") and HP > 0.2 then CastSpellByName("mortal strike")
elseif IsCastable("execute", "target") and HP < 0.2 then CastSpellByName("execute")
elseif IsCastable("Overpower", "target") then CastSpellByName("Overpower")
elseif IsCastable("Colossus smash", "target") and UnitMana("player") > 30 then CastSpellByName("colossus smash")
end
local cast = UnitCastingInfo("target")
local chan = UnitChannelInfo("target")
if cast or chan then
if IsCastable("throwdown", "target") then
CastSpellByName("throwdown")
print("should decast with throwdown")
elseif IsCastable("intimidating shout", "target") then
SpellStopCasting()
CastSpellByName("intimidating shout")
SpellStopCasting()
print("should decast with shout")
elseif IsCastable("pummel", "target") then
SpellStopCasting()
CastSpellByName("pummel")
SpellStopCasting()
print("should decast with pummel")
end
end
if pHP < 0.6 then
if IsCastable("Rallying cry") then
SpellStopCasting()
CastSpellByName("Rallying cry")
SpellStopCasting()
end
if IsCastable("Retaliation") then
CancelUnitBuff("player", "recklessness")
print("should cast retaliation")
SpellStopCasting()
CastSpellByName("Retaliation")
SpellStopCasting()
end
end
if not CheckInteractDistance("target", 2) and not IsCastable("charge", "target")
and not IsCastable("Heroic leap") and InCombatLockdown() then
if IsCastable("heroic throw", "target") then CastSpellByName("heroic throw") end
if GetUnitSpeed("player") == 0 then
if IsCastable("shattering throw", "target") then
print("should cast throw")
CastSpellByName("shattering throw")
end
if duration_sw == 0 then
Equip("INVTYPE_WEAPON")
Equip("INVTYPE_SHIELD")
if IsCastable("shield wall") then CastSpellByName("shield wall") end
end
end
end
if not UnitDebuff("target", "hamstring") and not UnitDebuff("target", "piercing howl") then
if IsCastable("Hamstring", "target") then
CastSpellByName("hamstring")
elseif IsCastable("piercing howl") and UnitMana("player") > 50 then
CastSpellByName("piercing howl")
end
end
if UnitMana("player") < 20 and InCombatLockdown() then
if GetSpellCooldown("Deadly calm") == 0 then
CastSpellByName("Deadly calm")
elseif GetSpellCooldown("Battle shout") == 0 then
CastSpellByName("Battle shout")
end
end
if UnitMana("player") > 60 or UnitBuff("player", "deadly calm") then
if IsCastable("Inner rage") then SpellStopCasting(); CastSpellByName("Inner rage"); end
if IsCastable("recklessness") then SpellStopCasting(); CastSpellByName("recklessness") end
if IsCastable("heroic strike", "target") then SpellStopCasting(); CastSpellByName("heroic strike")
elseif not UnitDebuff("target", "demoralizing shout") then SpellStopCasting(); CastSpellByName("demoralizing shout")
else SpellStopCasting(); CastSpellByName("thunder clap")
end
end
And I also made a quick anti-fear that works as an addOn:
Code:
--Handle loss of control
local frame, events = CreateFrame("Frame"), {};
function events:PLAYER_ENTERING_WORLD(...)
-- handle PLAYER_ENTERING_WORLD here
print("hello")
end
function events:PLAYER_CONTROL_LOST(...)
--handle PLAYER_CONTROL_LOST here
local _, duration_br, _ = GetSpellCooldown("berserker rage")
print("enter combat")
if duration_br == 0 then CastSpellByName("Berserker rage")
else CastSpellByName("every man for himself")
end
end
frame:SetScript("OnEvent", function(self, event, ...)
events[event](self, ...); -- call one of the functions above
end);
for k, v in pairs(events) do
frame:RegisterEvent(k); -- Register all events for which handlers have been defined
end