annotate MyLilPony.lua @ 11:9052b32b69c3

Added support for conditionals in slash command.
author syzler
date Sat, 09 Apr 2011 03:15:21 +0000
parents 7dfbf42c2d60
children cca898af07b4
rev   line source
syzler@1 1 -- MyLilPony
syzler@1 2 -- Copyright (c) 2011 Syzler
syzler@1 3 --
syzler@1 4 -- This program is free software: you can redistribute it and/or modify
syzler@1 5 -- it under the terms of the GNU General Public License as published by
syzler@1 6 -- the Free Software Foundation, either version 3 of the License, or
syzler@1 7 -- (at your option) any later version.
syzler@1 8 --
syzler@1 9 -- This program is distributed in the hope that it will be useful,
syzler@1 10 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
syzler@1 11 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
syzler@1 12 -- GNU General Public License for more details.
syzler@1 13 --
syzler@1 14 -- You should have received a copy of the GNU General Public License
syzler@1 15 -- along with this program. If not, see <http://www.gnu.org/licenses/>.
syzler@1 16
syzler@1 17 function MyLilPony.OnLoad()
syzler@1 18 SlashCmdList["MyLilPony"] = MyLilPony.SlashHandler;
syzler@1 19 SLASH_MyLilPony1 = "/pony";
syzler@1 20 SLASH_MyLilPony2 = "/mlp";
syzler@1 21 SLASH_MyLilPony3 = "/mylilpony";
syzler@1 22
syzler@1 23 MyLilPony.Log(format("Version %s loaded", MYLILPONY_VERSION));
syzler@1 24 MyLilPony.LoadDefaults();
syzler@1 25 end
syzler@1 26
syzler@1 27 function MyLilPony.LoadDefaults()
syzler@1 28 if MyLilPony.AutoDismount == nil then MyLilPony.AutoDismount = true end
syzler@1 29 end
syzler@1 30
syzler@1 31 function MyLilPony.AutoMount()
syzler@1 32 if UnitIsDead("player") or UnitIsGhost("player") then
syzler@1 33 MyLilPony.Log("You are dead");
syzler@1 34 return;
syzler@1 35 end
syzler@1 36
syzler@1 37 if InCombatLockdown() then
syzler@1 38 MyLilPony.Log("You are in combat");
syzler@1 39 return;
syzler@1 40 end
syzler@1 41
syzler@1 42 if IsMounted() and not MyLilPony.AutoDismount then
syzler@1 43 MyLilPony.Log("You are already mounted");
syzler@1 44 return;
syzler@1 45 end
syzler@1 46
syzler@1 47 if IsMounted() and IsFlying() then
syzler@1 48 MyLilPony.Log("You are already flying");
syzler@1 49 return;
syzler@1 50 end
syzler@1 51
syzler@1 52 local zone = GetRealZoneText();
syzler@1 53
syzler@1 54 -- player is in Temple of Ahn'Qiraj (AQ40)
syzler@1 55 if zone == "Ahn'Qiraj" then
syzler@1 56 if not IsModifierKeyDown() and MyLilPony.CallMountByRegex("Qiraji Battle Tank") then
syzler@1 57 return
syzler@1 58 end
syzler@1 59 end
syzler@1 60
syzler@1 61 -- player is in Wintergrasp
syzler@1 62 if zone == "Wintergrasp" then
syzler@1 63 -- always call ground mount if Wintergrasp is in progress
syzler@1 64 local _, _, wintergraspInProgress, _, _, _ = GetWorldPVPAreaInfo(1);
syzler@1 65 if wintergraspInProgress and MyLilPony.CallGroundMount() then
syzler@1 66 return;
syzler@1 67 end
syzler@1 68 end
syzler@1 69
syzler@1 70 -- player is swimming in Vash'jir
syzler@1 71 if IsSwimming() and (zone == "Shimmering Expanse" or zone == "Kelp'thar Forest" or zone == "Abyssal Depths") then
syzler@1 72 -- normal behaviour in Vash'jir is to call the Abyssal Seahorse
syzler@1 73 -- modified behaviour is to attempt flight (i.e. you're at the surface)
syzler@1 74 if not IsModifierKeyDown() and MyLilPony.CallMountByName("Abyssal Seahorse") then
syzler@1 75 return;
syzler@1 76 elseif MyLilPony.CanFlyHere() and MyLilPony.CallFlyingMount() then
syzler@1 77 return;
syzler@1 78 elseif MyLilPony.CallAquaticMount() then
syzler@1 79 return;
syzler@1 80 end
syzler@1 81 end
syzler@1 82
syzler@1 83 -- player is in flyable area and knows how to fly here too
syzler@1 84 if MyLilPony.CanFlyHere() and not IsModifierKeyDown() then
syzler@1 85 -- normal behaviour in flyable area is to call flying mount
syzler@1 86 if MyLilPony.CallFlyingMount() then
syzler@1 87 return;
syzler@1 88 end
syzler@1 89 end
syzler@1 90
syzler@1 91 -- player is swimming
syzler@1 92 if IsSwimming() and not IsModifierKeyDown() then
syzler@1 93 -- normal behaviour while swimming is to call aquatic mount
syzler@1 94 if MyLilPony.CallAquaticMount() then
syzler@1 95 return;
syzler@1 96 end
syzler@1 97 end
syzler@1 98
syzler@1 99 MyLilPony.CallGroundMount();
syzler@1 100 end
syzler@1 101
syzler@11 102 function MyLilPony.SlashHandler(args)
syzler@11 103 local arg = SecureCmdOptionParse(args);
syzler@1 104 if MyLilPony.StringMatchIgnoreCase(arg, "^auto$") then
syzler@1 105 MyLilPony.AutoMount();
syzler@1 106 elseif MyLilPony.StringMatchIgnoreCase(arg, "^random$")
syzler@1 107 or MyLilPony.StringMatchIgnoreCase(arg, "^rand$")
syzler@1 108 or MyLilPony.StringMatchIgnoreCase(arg, "^rng$")
syzler@1 109 or MyLilPony.StringMatchIgnoreCase(arg, "^r$") then
syzler@1 110 MyLilPony.CallMount();
syzler@1 111 elseif MyLilPony.StringMatchIgnoreCase(arg, "^ground$")
syzler@1 112 or MyLilPony.StringMatchIgnoreCase(arg, "^g$") then
syzler@1 113 MyLilPony.CallGroundMount();
syzler@1 114 elseif MyLilPony.StringMatchIgnoreCase(arg, "^flying$")
syzler@1 115 or MyLilPony.StringMatchIgnoreCase(arg, "^fly$")
syzler@1 116 or MyLilPony.StringMatchIgnoreCase(arg, "^air$")
syzler@1 117 or MyLilPony.StringMatchIgnoreCase(arg, "^a$") then
syzler@1 118 MyLilPony.CallFlyingMount();
syzler@1 119 elseif MyLilPony.StringMatchIgnoreCase(arg, "^aquatic$")
syzler@1 120 or MyLilPony.StringMatchIgnoreCase(arg, "^aqua$")
syzler@1 121 or MyLilPony.StringMatchIgnoreCase(arg, "^swim$")
syzler@1 122 or MyLilPony.StringMatchIgnoreCase(arg, "^s$") then
syzler@1 123 MyLilPony.CallAquaticMount();
syzler@1 124 elseif MyLilPony.StringMatchIgnoreCase(arg, "^target$")
syzler@1 125 or MyLilPony.StringMatchIgnoreCase(arg, "^tgt$")
syzler@1 126 or MyLilPony.StringMatchIgnoreCase(arg, "^t$") then
syzler@1 127 local result = MyLilPony.CallMountByMatch("target");
syzler@1 128 if not result then
syzler@1 129 MyLilPony.Log("No matching mounts were found");
syzler@1 130 end
syzler@1 131 elseif MyLilPony.StringMatchIgnoreCase(arg, "^exact .+$")
syzler@1 132 or MyLilPony.StringMatchIgnoreCase(arg, "^x .+$") then
syzler@1 133 local param = MyLilPony.StringMatchIgnoreCase(arg, "^.+ (.+)$");
syzler@1 134 local result = MyLilPony.CallMountByName(param);
syzler@1 135 if not result then
syzler@1 136 MyLilPony.Log(format("No matching mounts were found with NAME='%s'", param));
syzler@1 137 end
syzler@1 138 elseif MyLilPony.StringMatchIgnoreCase(arg, "^list .+$")
syzler@1 139 or MyLilPony.StringMatchIgnoreCase(arg, "^find .+$")
syzler@1 140 or MyLilPony.StringMatchIgnoreCase(arg, "^l .+$") then
syzler@1 141 local param = MyLilPony.StringMatchIgnoreCase(arg, "^.+ (.+)$");
syzler@1 142 local result = MyLilPony.ListMountsByPattern(param);
syzler@1 143 if not result then
syzler@1 144 MyLilPony.Log(format("No matching mounts were found with NAME like '%s'", param));
syzler@1 145 else
syzler@1 146 for _, name in pairs(result) do
syzler@1 147 MyLilPony.Print(name);
syzler@1 148 end
syzler@1 149 end
syzler@1 150 elseif MyLilPony.StringMatchIgnoreCase(arg, "^%d+$") then
syzler@1 151 local result = MyLilPony.CallMountById(tonumber(arg));
syzler@1 152 if not result then
syzler@1 153 MyLilPony.Log(format("No matching mounts were found with ID=%s", arg));
syzler@1 154 end
syzler@1 155 elseif MyLilPony.StringMatchIgnoreCase(arg, "^.+$") then
syzler@1 156 local result = MyLilPony.CallMountByPattern(arg);
syzler@1 157 if not result then
syzler@1 158 MyLilPony.Log(format("No matching mounts were found with NAME like '%s'", arg));
syzler@1 159 end
syzler@1 160 else
syzler@1 161 MyLilPony.Print(format("MyLilPony %s", MYLILPONY_VERSION));
syzler@1 162 MyLilPony.Print("Slash Command: /mylilpony (/pony, /mlp)");
syzler@1 163 MyLilPony.Print(" /mylilpony auto - Summons a \"suitable\" mount");
syzler@1 164 MyLilPony.Print(" /mylilpony random - Summons random mount");
syzler@1 165 MyLilPony.Print(" /mylilpony ground - Summons random ground mount");
syzler@1 166 MyLilPony.Print(" /mylilpony flying - Summons random flying mount");
syzler@1 167 MyLilPony.Print(" /mylilpony aquatic - Summons random aquatic mount");
syzler@1 168 MyLilPony.Print(" /mylilpony target - Summons same mount as targeted unit");
syzler@1 169 MyLilPony.Print(" /mylilpony list <NAME> - Lists mounts matching name");
syzler@1 170 MyLilPony.Print(" /mylilpony exact <NAME> - Summons mount by exact name");
syzler@1 171 MyLilPony.Print(" /mylilpony <ID> - Summons mount by spell or creature ID");
syzler@1 172 MyLilPony.Print(" /mylilpony <NAME> - Summons random mount matching name");
syzler@1 173 end
syzler@1 174 end