Advertisement
Guest User

Untitled

a guest
Jul 20th, 2016
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.63 KB | None | 0 0
  1. version = "6.0.6"
  2. --RandomMount
  3. --Original Author: Mike Hendricks(AttilaTheFun)
  4. --Continuing Author: t4t3rt0t
  5. --Description:
  6. -- This add-on makes it simple to summon a random mount it takes into account ridding level, cold weather flying,
  7. -- flying areas, Modifiers available, and summons an appropriate mount.
  8. -- It has a simple interface /mnt: /rmount: Will summon riding/flying mounts in the appropriate areas. mnt and rmount are interchangeable
  9. -- /mnt riding: Summons riding mounts in flying areas
  10. -- /mnt flying: Attempt to summon a flying mount
  11. -- /mnt help: Display help
  12. -- /mnt r or f (search Term): Summons a mount based on specified search term
  13. -- example: to summon a skeletal warhorse type: /mnt skeletal
  14. -- /mnt config: Prints the current configuration
  15. -- /mnt rfilter: Toggle mount filtering
  16. -- /mnt safefly: Toggle double click to dismount while flying
  17. -- /mnt rfilters: List current filters
  18. -- /mnt locfilter: Toggle filter to summon only specific mounts in specific locations
  19. -- /mnt addloc % (zone:mount name1, mount name2, ...): Add locations and mounts to location checking. Separate mounts with commas. Use * as a wildcard to specify all mounts.
  20. -- /mnt removeloc % (zone:mount name1, mount name2, ...): Removes locations and mounts from location checking. Separate mounts with commas.
  21. -- /mnt loctable: Print the current location filtering table.
  22. -- /mnt clearloc: Clears location filters
  23. -- /mnt remove %: Remove all mounts matching % if rfilter is enabled
  24. -- /mnt clear: Clears all filters
  25. -- /mnt clearrem: Clears the mount removal table
  26. -- /mnt whereami: Prints your zone and mini-map zone.
  27. -- /mnt title: Enable or disable random title change.
  28. -- /mnt icon: Enable or disable changing random mount macro icons to the last summoned mount.
  29. -- /mnt setweight # %: Sets a weight # (0 to 1000) for any mounts matching %. Omitting % will set the default weight for mounts without specified weights.
  30. -- /mnt PrintHelp("druid: Create a macro for druids that will cancel your form before trying to summon a mount.
  31. -- /mnt debug: Toggle debug printing for posting error messages
  32. -- /mnt No Flag: Summon a appropriate mount for the area
  33.  
  34. -- Addon namespace
  35. RMount = {}
  36.  
  37. -- Create frame for event handling
  38. local RMountFrame = CreateFrame("FRAME", "RMountFrame")
  39. RMountFrame:RegisterEvent("ADDON_LOADED")
  40. function RMount.OnEvent(this, event, ...)
  41. local arg1 = ...;
  42. if event == "ADDON_LOADED" and arg1 == "RandomMountContinued" then
  43. RMount:OnLoad()
  44. end
  45. end
  46. RMountFrame:SetScript("OnEvent", RMount.OnEvent)
  47.  
  48. -- Get the Frame that is housing the UIErrorsFrame
  49. local originalOnEvent = UIErrorsFrame:GetScript("OnEvent")
  50. -- Listen for SYSTEM Errors from the UIErrorsFrame
  51. UIErrorsFrame:SetScript("OnEvent", function(self, event, message, r, g, b, ...)
  52. -- Check the Error Message
  53. if message == SPELL_FAILED_NOT_HERE or message == SPELL_FAILED_ONLY_UNDERWATER then
  54. -- Set mountError to true
  55. mountError = true
  56. mountErrorMsg = message
  57. else
  58. -- Set mountError to false
  59. mountError = false
  60. mountErrorMsg = nil
  61. -- If error is not what we are looking for then return it to the original Frame
  62. return originalOnEvent(self, event, message, r, g, b, ...)
  63. end
  64. end)
  65.  
  66. -- Sea Mount Database
  67. -- GetCompanionInfo("MOUNT", i) doesn't provide a way to distinguish between (fast land/slow sea) and (slow land/fast sea)
  68. local seaMounts = {
  69. 30174, --Riding Turtle
  70. 64731, --Sea Turtle
  71. --the following should be detected as sea only, added anyways as fallback
  72. 98718, --Subdued Seahorse
  73. 75207 --Abyssal Seahorse
  74. }
  75.  
  76. -- Waterwalking Mount Database
  77. -- GetCompanionInfo("MOUNT", i) doesn't provide a way to distinguish waterwalking mounts
  78. local striderMounts = {
  79. 118089 --Azure Water Strider
  80. }
  81.  
  82.  
  83.  
  84.  
  85. --Old Saved Variables <1.06.13
  86. debug = false --display debug info if enabled
  87. notWanted = {} --Mounts that are not wanted to be summoned
  88. removeMount = false --Enable or disable notWanted mounts
  89. locationChk = true --enable or disable specific mounts in special locations
  90. locations = {} --locations to summon specific mounts(specialMounts)
  91. specialMounts = {} --special mounts to summon if in a specific location
  92. rndTitle = false --Randomly change the title when summoning a mount
  93. safeFly = false --Safe flying dismount if flying
  94. macroIcon = false --Update the macro icon with last summoned mount
  95. zones = {} --Contains the list of location filters
  96. mountError = false
  97. mountErrorMsg = nil
  98.  
  99.  
  100. --New Saved Variables >=1.06.13
  101. local defaultVars = {
  102. --only change version if DB format changes
  103. version = 1,
  104. useGVars = true,
  105. weights = {},
  106. defaultWeight = 100
  107. }
  108.  
  109. --upvars
  110. local mountCache = {} --cache data from GetCompanionInfo("MOUNT", i)
  111. local mountCount = {} --# of mounts, rebuild mountCache if it changes
  112. local lastTime = GetTime() --Safe flying last time that dismount was called
  113. local tailorSkill = 0
  114. local engineerSkill = 0
  115. local hasStrider = false
  116.  
  117. --bindings
  118. BINDING_HEADER_RANDOMMOUNT = "Random Mount"
  119. BINDING_NAME_RANDOMMOUNT_REG = "Auto Summon"
  120. BINDING_NAME_RANDOMMOUNT_RIDING = "Summon Riding"
  121. BINDING_NAME_RANDOMMOUNT_FLYING = "Summon Flying"
  122. BINDING_NAME_RANDOMMOUNT_SWIMMING = "Summon Swimming"
  123.  
  124. -- Run at Load
  125. function RMount:OnLoad()
  126. SlashCmdList["RandomMount"] = RMount.FindMount;
  127. SLASH_RandomMount1 = "/mnt";
  128. SLASH_RandomMount2 = "/rmount";
  129.  
  130. --Handle SavedVariables
  131. if not rMountCVars then
  132. rMountCVars = {}
  133. end
  134. RMount.CopyDefaultVars(defaultVars, rMountCVars)
  135. if not rMountGVars then
  136. rMountGVars = {}
  137. end
  138. RMount.CopyDefaultVars(defaultVars, rMountGVars)
  139. if rMountCVars.useGVars then
  140. rMountVars = rMountGVars
  141. else
  142. rMountVars = rMountCVars
  143. end
  144.  
  145. --[[ -- Save data for research purposes
  146. mountDB = {}
  147. for i=1, C_MountJournal.GetNumMounts() do
  148. local _, _, _, _, mountTypeID = C_MountJournal.GetMountInfoExtraByID(i)
  149. local mountName, spellID = C_MountJournal.GetMountInfoByID(i)
  150. if mountTypeID ~= 248 and mountTypeID ~= 230 and mountTypeID ~= 241 then
  151. tinsert(mountDB, {mountName, spellID, mountTypeID})
  152. end
  153. end
  154. ]]
  155. --[[
  156. local _, b, c, _, _, f = GetCompanionInfo("MOUNT", i)
  157. if not mountDB[f] then
  158. mountDB[f] = {}
  159. end
  160. if not mountDB[f][c] then
  161. mountDB[f][c] = {}
  162. end
  163. mountDB[f][c] = b
  164. if not (f == 7) and not (f == 12) and not (f == 15) and not (f == 23) and not (f == 29) and not (f == 31) then
  165. PrintHelp("Detected unknown mount mountTypeID flag: " .. f, "FFff0000")
  166. PrintHelp("Please help improve RandomMount by submitting this number on curse.com", "FFff0000")
  167. end
  168. end
  169. --]]
  170. end
  171.  
  172. function RMount.CopyDefaultVars(src, dst)
  173. if not src then return { } end
  174. if not dst then dst = { } end
  175. for k, v in pairs(src) do
  176. if type(v) == "table" then
  177. dst[k] = RMount.CopyDefaultVars(v, dst[k])
  178. elseif type(v) ~= type(dst[k]) then
  179. dst[k] = v
  180. end
  181. end
  182. return dst
  183. end
  184.  
  185. -- Build mountCache
  186. --[[
  187. mountTypeID 5th return of C_MountJournal.GetMountInfoExtraByID
  188. 284 (100011100) for 2 American Chopper bikes
  189. 269 (100001101) for 2 Water Striders (Azure and Crimson)
  190. 254 (11111110) for 1 Subdued Seahorse
  191. 248 (11111000) for 163 "typical" flying mounts, including those that change based on level (Tyreal's Charger, Celestial Steed)
  192. 247 (11110111) for 1 Red Flying Cloud (flying mount)
  193. 242 (11110010) for 2 Swift Spectral Gryphon/Rylak (the one we fly while dead? 10th return (hideOnChar) of GetMountInfo is true)
  194. 241 (11110001) for 4 Qiraji Battle Tanks (Blue, Green, Red and Yellow)
  195. 232 (11101000) for 1 Vashj'ir Seahorse
  196. 231 (11100111) for 2 Turtles (Riding and Sea)
  197. 230 (11100110) for 298 land mounts
  198. ]]--
  199. function BuildMountCache()
  200. mountCache = {air={}, land={}, sea={}, strider={}, all={}, find={}}
  201. mountCount = {air=0, land=0, sea=0, strider=0, all=0, find={}}
  202. mountCount.all = C_MountJournal.GetNumMounts()
  203. for i=1, mountCount.all do
  204. --local creatureID, mountName, spellID, icon, _, mountFlags = GetCompanionInfo("MOUNT", i) -- 5.0 api
  205. local mountName, spellID, icon, active, isUsable, sourceType, isFavorite, isFactionSpecific, faction, hideOnChar, isCollected = C_MountJournal.GetMountInfoByID(i)
  206. local creatureDisplayID, descriptionText, sourceText, isSelfMount, mountTypeID = C_MountJournal.GetMountInfoExtraByID(i)
  207. if mountTypeID == 247 or mountTypeID == 248 then
  208. mountCache.air[i] = rMountVars.weights[spellID] or rMountVars.defaultWeight
  209. mountCount.air = mountCount.air + 1
  210. elseif mountTypeID == 231 or mountTypeID == 254 or IsSeaMount(spellID) then
  211. mountCache.sea[i] = rMountVars.weights[spellID] or rMountVars.defaultWeight
  212. mountCount.sea = mountCount.sea + 1
  213. end
  214. if mountTypeID == 230 or mountTypeID == 241 or mountTypeID == 269 then
  215. mountCache.land[i] = rMountVars.weights[spellID] or rMountVars.defaultWeight
  216. mountCount.land = mountCount.land + 1
  217. end
  218. if mountTypeID == 269 or IsStriderMount(spellID) then
  219. mountCache.strider[i] = rMountVars.weights[spellID] or rMountVars.defaultWeight
  220. mountCount.strider = mountCount.strider + 1
  221. hasStrider = true
  222. end
  223. mountCache.all[i] = {
  224. mountName,
  225. spellID,
  226. icon,
  227. mountTypeID,
  228. isCollected,
  229. faction
  230. }
  231. --[[
  232. --Check if mountTypeID flags don't match any known values
  233. if not (mountTypeID == 7) and not (mountTypeID == 12) and not (mountTypeID == 15) and
  234. not (mountTypeID == 23) and not (mountTypeID == 29) and not (mountTypeID == 31) then
  235. if debug then PrintHelp("Detected unknown mount mountTypeID flag: " .. mountTypeID, "FFff0000") end
  236.  
  237. --Determine land/air mountTypeID at least
  238. if bit.band(2,mountTypeID) == 2 then
  239. mountCache.air[i] = rMountVars.weights[spellID] or rMountVars.defaultWeight
  240. mountCount.air = mountCount.air + 1
  241. end
  242. if bit.band(16,mountTypeID) == 16 then
  243. mountCache.land[i] = rMountVars.weights[spellID] or rMountVars.defaultWeight
  244. mountCount.land = mountCount.land + 1
  245. end
  246. end
  247. ]]--
  248. end
  249. end
  250.  
  251. -- todo: combine BuildSearchCache with BuildMountCache
  252. -- todo: create function - mountTypes = DecodeMountTypes(mountTypeID)
  253. -- Create cache of mounts matching search pattern
  254. function BuildSearchCache(search)
  255. local spellID
  256. if not mountCache.find[search] then
  257. mountCache.find[search] = {air={}, land={}, sea={}, all={}}
  258. else
  259. -- bail if cache already exists
  260. return
  261. end
  262. if not mountCount.find[search] then
  263. mountCount.find[search] = {air=0, land=0, sea=0, all=0}
  264. end
  265.  
  266. for i=1,mountCount.all do
  267. local searchComponents = splitString(",%s*", search)
  268. for _, searchComponent in ipairs(searchComponents) do
  269. if strfind(strlower(mountCache.all[i][1]), strlower(searchComponent)) then
  270. creatureSpellID = mountCache.all[i][2]
  271. mountTypeID = mountCache.all[i][4]
  272. mountCache.find[search].all[i] = rMountVars.weights[creatureSpellID] or rMountVars.defaultWeight
  273. mountCount.find[search].all = mountCount.find[search].all + 1
  274. if mountTypeID == 247 or mountTypeID == 248 then
  275. mountCache.find[search].air[i] = rMountVars.weights[creatureSpellID] or rMountVars.defaultWeight
  276. mountCount.find[search].air = mountCount.find[search].air + 1
  277. elseif mountTypeID == 231 or mountTypeID == 254 or IsSeaMount(spellID) then
  278. mountCache.find[search].sea[i] = rMountVars.weights[creatureSpellID] or rMountVars.defaultWeight
  279. mountCount.find[search].sea = mountCount.find[search].sea + 1
  280. end
  281. if mountTypeID == 230 or mountTypeID == 241 or mountTypeID == 269 then
  282. mountCache.find[search].land[i] = rMountVars.weights[creatureSpellID] or rMountVars.defaultWeight
  283. mountCount.find[search].land = mountCount.find[search].land + 1
  284. end
  285. end
  286. end
  287. end
  288. return
  289. end
  290.  
  291. -- Select a mount
  292. function GetRandomMount(type, ridingSK, zoneText, canFly, search, inLocation, zoneChk)
  293. local count
  294. local lastMount
  295. local s = false
  296. local chance
  297. if search ~= '' then
  298. t = mountCache.find[search][type]
  299. else
  300. t = mountCache[type]
  301. end
  302. local total = GetMountWeightTotal(t)
  303.  
  304. for i=1, 10000 do
  305. count = random(0, total)
  306. for j, weight in pairs(t) do
  307. count = count - weight
  308. lastMount = j
  309. if count <= 0 then
  310. chance = weight * 100 / total
  311. break
  312. end
  313. end
  314. -- Test Mount
  315. s = TestMount(lastMount, ridingSK, zoneText, canFly, inLocation, zoneChk, chance)
  316. if s then
  317. break
  318. end
  319. end
  320. local casting = UnitCastingInfo("player")
  321. -- Summon Mount
  322. if s then
  323. C_MountJournal.SummonByID(lastMount)
  324. if not mountError and not casting then
  325. -- Set Icon of the Mount
  326. RMount.SetMacroIcon(lastMount)
  327. end
  328. end
  329. end
  330.  
  331. -- Count total of all weights
  332. function GetMountWeightTotal(mountTable)
  333. local total = 0
  334. for _, weight in pairs(mountTable) do
  335. total = total + weight
  336. end
  337. return total
  338. end
  339.  
  340. -- Check if mount can swim fast
  341. function IsSeaMount(spellID)
  342. for _, value in ipairs(seaMounts) do
  343. if value == spellID then
  344. return true
  345. end
  346. end
  347. return false
  348. end
  349.  
  350. -- Check if mount can waterwalk
  351. function IsStriderMount(spellID)
  352. for _, value in ipairs(striderMounts) do
  353. if value == spellID then
  354. return true
  355. end
  356. end
  357. return false
  358. end
  359.  
  360. -- Set weight of mounts matching nameSearch
  361. function SetMountWeights(weight, nameSearch)
  362. if weight then
  363. weight = min(floor(abs(weight)), 1000)
  364. end
  365. if nameSearch == '' then
  366. local oldweight = rMountVars.defaultWeight or 100
  367. rMountVars.defaultWeight = weight
  368. PrintHelp("Default weight changed from " .. oldweight .. " to " .. weight, "FF00ffff")
  369. else
  370. for i=1, mountCount.all do
  371. if strfind(strlower(mountCache.all[i][1]), strlower(nameSearch)) then
  372. local spellID = mountCache.all[i][2]
  373. local oldweight = rMountVars.weights[spellID] or rMountVars.defaultWeight
  374. rMountVars.weights[spellID] = weight
  375. if weight then
  376. PrintHelp(mountCache.all[i][1] .. " weight changed from " .. oldweight .. " to " .. weight, "FF00ffff")
  377. else
  378. PrintHelp(mountCache.all[i][1] .. " weight reset from " .. oldweight .. " to default " .. rMountVars.defaultWeight, "FF00ffff")
  379. end
  380. end
  381. end
  382. end
  383. --Rebuild cache with new weights
  384. BuildMountCache()
  385. end
  386.  
  387. -- Check if you can use a Sea mount in this zone
  388. function CanSwimHere()
  389. zone = GetCurrentMapAreaID()
  390. if mountCount.sea > 0 then
  391. for i, _ in pairs(mountCache.sea) do
  392. local spellID = mountCache.all[i][2]
  393. if spellID == 75207 and zone ~= 614 and zone ~= 615 and zone ~= 610 and mountCount.sea == 1 then
  394. return false
  395. end
  396. end
  397. return true
  398. end
  399. return false
  400. end
  401.  
  402. -- Check if you can fly in this zone
  403. function CanFlyHere()
  404. if mountCount.air == 0 then
  405. if debug then PrintHelp("No air mounts detected", "FFff0000") end
  406. return false
  407. end
  408. SetMapToCurrentZone()
  409. local zoneID = GetCurrentMapAreaID()
  410. -- local zoneNum = GetCurrentMapZone()
  411. local continent = GetCurrentMapContinent()
  412. local ridingSkill, classicLicense, coldLicense, pandaLicense, serpentLicense, dreanorLicense = GetRidingSkill()
  413.  
  414. -- Check for flyable area
  415. if not IsFlyableArea() then
  416. return false
  417. else
  418. -- ban flying in Throne of the Four Winds, The Deadmines
  419. if zoneID == 773 or zoneID == 756 then
  420. return false
  421. else
  422. -- Zone Check
  423. if classicLicense and (continent == 1 or continent == 2 or continent == 5) then
  424. return true
  425. elseif ridingSkill >= 225 and continent == 3 then
  426. return true
  427. elseif coldLicense and continent == 4 then
  428. return true
  429. elseif pandaLicense and continent == 6 then
  430. return true
  431. elseif dreanorLicense and continent == 7 then
  432. return true
  433. end
  434. end
  435.  
  436. if debug then PrintHelp("No flight license found for zoneID: ".. zoneID ..", continent: ".. continent, "FFff0000") end
  437. return false
  438. end
  439. end
  440.  
  441. -- Get your Riding Skill Level
  442. function GetRidingSkill()
  443. local ridingSkill = 0
  444. local classicLicense = false
  445. local coldLicense = false
  446. local pandaLicense = false
  447. local serpentLicense = false
  448. local dreanorLicense = false
  449.  
  450. if IsSpellKnown(90265) then
  451. ridingSkill = 375
  452. elseif IsSpellKnown(34091) then
  453. ridingSkill = 300
  454. elseif IsSpellKnown(34090) then
  455. ridingSkill = 225
  456. elseif IsSpellKnown(33391) then
  457. ridingSkill = 150
  458. elseif IsSpellKnown(33388) then
  459. ridingSkill = 75
  460. end
  461. if IsSpellKnown(90267) then
  462. classicLicense = true
  463. end
  464. if IsSpellKnown(54197) then
  465. coldLicense = true
  466. end
  467. if IsSpellKnown(115913) then
  468. pandaLicense = true
  469. end
  470. if IsSpellKnown(130487) then
  471. serpentLicense = true
  472. end
  473. if IsSpellKnown(191645) then
  474. dreanorLicense = true
  475. end
  476. return ridingSkill, classicLicense, coldLicense, pandaLicense, serpentLicense, dreanorLicense
  477. end
  478.  
  479. -- Get your Profession Skill Level
  480. function GetProfessionSkill()
  481. local prof1, prof2 = GetProfessions()
  482. prof1 = prof1 or 0
  483. prof2 = prof2 or 0
  484. local _, _, skill1, _, _, _, skillLine1 = GetProfessionInfo(prof1)
  485. local _, _, skill2, _, _, _, skillLine2 = GetProfessionInfo(prof2)
  486. skillLine1 = skillLine1 or 0
  487. skillLine2 = skillLine2 or 0
  488. if skillLine1 == 197 then
  489. tailorSkill = skill1 or 0
  490. elseif skillLine2 == 197 then
  491. tailorSkill = skill2 or 0
  492. end
  493. if skillLine1 == 202 then
  494. engineerSkill = skill1 or 0
  495. elseif skillLine2 == 202 then
  496. engineerSkill = skill2 or 0
  497. end
  498. end
  499.  
  500. -- Check Special Mounts
  501. function lfmChk(mountName)
  502. if locationChk then
  503. for j, k in ipairs(specialMounts) do
  504. if strfind(strlower(mountName), strlower(k)) then
  505. return true
  506. end
  507. end
  508. if #locations > 0 then
  509. PrintHelp("Detected location filtering usage. This feature may soon be removed.", "FFff0000")
  510. PrintHelp("If you would like this feature to remain then please comment on curse.com", "FFff0000")
  511. end
  512. end
  513. return false
  514. end
  515.  
  516. -- from http://lua-users.org/wiki/SplitJoin by PeterPrade
  517. function splitString(delimiter, text)
  518. local list = {}
  519. local pos = 1
  520. if strfind("", delimiter, 1) then -- this would result in endless loops
  521. error("delimiter matches empty string!")
  522. end
  523. while 1 do
  524. local first, last = strfind(text, delimiter, pos)
  525. if first then -- found?
  526. tinsert(list, strsub(text, pos, first-1))
  527. pos = last+1
  528. else
  529. tinsert(list, strsub(text, pos))
  530. break
  531. end
  532. end
  533. return list
  534. end
  535.  
  536. -- Add Mount to Locations List
  537. function AddLocF(info)
  538. if string.len(info) > 0 then
  539. local i = strfind(info, ":");
  540. local locVar = strsub(info, 0, i - 1)
  541. local mntVar = splitString(",", strsub(info, i + 1));
  542. if not zones[strlower(locVar)] then
  543. zones[strlower(locVar)] = {}
  544. end
  545. for i, v in ipairs(mntVar) do
  546. local found = false
  547. for n, item in ipairs(zones[strlower(locVar)]) do
  548. if v == item then
  549. PrintHelp(v .. " already added.", "FF00ff00")
  550. found = true
  551. break
  552. end
  553. end
  554. if not found then
  555. tinsert(zones[strlower(locVar)], v)
  556. end
  557. end
  558. PrintHelp("When in " .. strlower(locVar) .. " mounts with " .. table.concat(zones[strlower(locVar)], ",") .. " will be summoned.", "FF00ff00")
  559. end
  560. end
  561.  
  562. -- Print the Location List
  563. function printLocF()
  564. PrintHelp("Location Mount database", "FFff00ff")
  565. for i, v in pairs(zones) do
  566. PrintHelp(i .. ":", "FF00ff00")
  567. for j, w in ipairs(zones[i]) do
  568. PrintHelp(" " .. w, "FF00ff99")
  569. end
  570. end
  571. end
  572.  
  573. -- Remove a Filtered Location
  574. function removeLocF(info)
  575. if string.len(info) > 0 then
  576. local i = strfind(info, ":");
  577. --if : not found then remove zone table
  578. if not i then
  579. PrintHelp("Zone " .. info .. " is no longer filtered.", "FF00ff00")
  580. zones[info] = nil
  581. else
  582. local locVar = strsub(info, 0, i - 1)
  583. local mntVar = splitString(",", strsub(info, i + 1))
  584. for i, v in ipairs(mntVar) do
  585. local found = false
  586. for n, item in ipairs(zones[locVar]) do
  587. if v == item then
  588. PrintHelp(v .. " removed from " .. locVar .. ".", "FF00ff99")
  589. tremove(zones[locVar], n)
  590. found = true
  591. break
  592. end
  593. end
  594. if not found then
  595. PrintHelp(v .. " not found in " .. locVar .. ".", "FF00ff99")
  596. end
  597. end
  598. if #zones[locVar] == 0 then
  599. PrintHelp(locVar .. " removed because it has no mounts.", "FF00ff00")
  600. zones[locVar] = nil
  601. end
  602. end
  603. end
  604. -- if : found then remove zone table elements, not entire table, if table is empty place * to signify empty
  605. end
  606.  
  607. -- Change the Character Title
  608. function RMount.SetCharTitle()
  609. if rndTitle then
  610. local titles = {}
  611. for i=1,GetNumTitles() do
  612. if IsTitleKnown(i) then
  613. tinsert(titles, i)
  614. end
  615. end
  616. SetCurrentTitle(titles[random(#titles)])
  617. end
  618. end
  619.  
  620. -- Check to see if we are Swimming or in Vashj'ir
  621. function checkSwimming()
  622. local zone = GetCurrentMapAreaID()
  623. if IsSwimming() then
  624. return true
  625. elseif not IsSwimming() and (zone == 614 or zone == 615 or zone == 610) then
  626. return true
  627. else
  628. return false
  629. end
  630. end
  631.  
  632. -- Change the Macro Icon
  633. function RMount.SetMacroIcon(r)
  634. if macroIcon then
  635. local _, _, icon = C_MountJournal.GetMountInfoByID(r)
  636. -- loop to change the icons of macros that are calling /rmount
  637. local numglobal,numperchar = GetNumMacros()
  638. for j=1,numglobal do
  639. local mbody = GetMacroBody(j)
  640. if strfind(mbody,"/rmount") or strfind(mbody,"/mnt") then
  641. EditMacro(j,nil,strsub(icon,17),nil,nil)
  642. end
  643. end
  644. for j=37,numperchar+36 do
  645. local mbody = GetMacroBody(j)
  646. if strfind(mbody,"/rmount") or strfind(mbody,"/mnt") then
  647. EditMacro(j,nil,strsub(icon,17),nil,true)
  648. end
  649. end
  650. end
  651. end
  652.  
  653. -- Main Mount Call
  654. function RMount.FindMount(arg1)
  655. -- Check Profession Skills
  656. GetProfessionSkill()
  657. -- Check if # of mounts changed
  658. if (mountCount.all ~= C_MountJournal.GetNumMounts) then
  659. BuildMountCache()
  660. end
  661. local s = 0
  662. local r
  663. local search = ""
  664. local zoneText = GetRealZoneText() -- Get Zone Text
  665. local canFly = CanFlyHere() -- Check if can fly
  666. local outdoors = IsOutdoors() -- Check if outdoors
  667. local ridingSK = GetRidingSkill() -- Set Riding Skill
  668. local inLocation = false --Used to check for location
  669. local zoneChk = true
  670. local removeMountPrev = removeMount
  671. local mountType = nil --air/land/sea mount
  672.  
  673. -- Check for macro modifiers
  674. argv, _ = SecureCmdOptionParse(arg1)
  675. -- Bail if no macro conditions matched
  676. if argv == nil then return end
  677.  
  678. -- Check argument after /mnt or /rmount
  679. if argv == "help" then
  680. PrintHelp("Random Mount " .. version .. " optional flags:", "FFFFFF00")
  681. PrintHelp("/mnt: /rmount: Will summon swimming/riding/flying mounts in the appropriate areas. mnt and rmount are interchangeable", "FFFFFF00")
  682. PrintHelp("riding: Attempt to summon a ground mount", "FFFFFF00")
  683. PrintHelp("flying: Attempt to summon a flying mount", "FFFFFF00")
  684. PrintHelp("swimming: Attempt to summon a swimming mount", "FFFFFF00")
  685. PrintHelp("help: Display help", "FFFFFF00")
  686. PrintHelp("[mod:Modifier Name]: Use any Modifier Blizzard Supports", "FFFFFF00")
  687. PrintHelp("r %: Summons a ground mount matching % search term \rexample: to summon a skeletal warhorse type: /mnt r skeletal", "FFFFFF00")
  688. PrintHelp("f %: Summons a flying mount matching % search term \rexample: to summon a proto-drake type: /mnt f proto", "FFFFFF00")
  689. PrintHelp("s %: Summons a swimming mount matching % search term \rexample: to summon a turtle type: /mnt s turtle", "FFFFFF00")
  690. PrintHelp("config: Prints the current configuration", "FFFFFF00")
  691. PrintHelp("safefly: Toggle double click to dismount while flying", "FFFFFF00")
  692. PrintHelp("rfilters: List current filters", "FFFFFF00")
  693. PrintHelp("locfilter: Toggle filter to summon only specific mounts in specific locations", "FFFFFF00")
  694. PrintHelp("addloc % (zone:mount name1, mount name2, ...): Add locations and mounts to location checking. Separate mounts with commas. Use * as a wildcard to specify all mounts.", "FFFFFF00")
  695. PrintHelp("removeloc % (zone:mount name1, mount name2, ...): Removes locations and mounts from location checking. Separate mounts with commas.", "FFFFFF00")
  696. PrintHelp("loctable: Print the current location filtering table.", "FFFFFF00")
  697. PrintHelp("clearloc: Clears location filters", "FFFFFF00")
  698. PrintHelp("remove %: Remove all mounts matching % if rfilter is enabled", "FFFFFF00")
  699. PrintHelp("clear: Clears all filters", "FFFFFF00")
  700. PrintHelp("clearrem: Clears the mount removal table", "FFFFFF00")
  701. PrintHelp("whereami: Prints your zone and mini-map zone, and map coordinates.", "FFFFFF00")
  702. PrintHelp("title: Enable or disable random title change.", "FFFFFF00")
  703. PrintHelp("icon: Enable or disable changing random mount macro icons to the last summoned mount.", "FFFFFF00")
  704. PrintHelp("setweight # %: Sets a weight # (0 to 1000) for any mounts matching %. \rOmitting % will set the default weight to # for mounts without specified weights. \rOmitting # will clear any weights set for any mounts matching %.", "FFFFFF00")
  705. PrintHelp("debug: Toggle debug printing for posting error messages", "FFFFFF00")
  706. return
  707. elseif argv == "config" then
  708. if debug then
  709. PrintHelp("Debug: Enabled", "FF00ff00")
  710. else
  711. PrintHelp("Debug: Disabled", "FFff0000")
  712. end
  713. if removeMount then
  714. PrintHelp("Mounts filtered: " .. table.concat(notWanted, ", "), "FF00ff00")
  715. else
  716. PrintHelp("Mount Removal Disabled.", "FFff0000")
  717. end
  718. if safeFly then
  719. PrintHelp("Safe flying enabled. Double click to dismount while flying", "FF00ff00")
  720. else
  721. PrintHelp("Safe flying disabled.", "FFff0000")
  722. end
  723. if rndTitle then
  724. PrintHelp("Random title enabled.", "FF00ff00")
  725. else
  726. PrintHelp("Random title disabled.", "FFff0000")
  727. end
  728. if macroIcon then
  729. PrintHelp("Icon changing enabled.", "FF00ff00")
  730. else
  731. PrintHelp("Icon changing disabled.", "FFff0000")
  732. end
  733. return
  734. elseif argv == "whereami" then
  735. local posX, posY = GetPlayerMapPosition("player")
  736. PrintHelp("You are in " .. zoneText .. ", " .. GetMinimapZoneText() .. ", " .. posX .. ", " .. posY, "FF00ff00")
  737. return
  738. elseif argv == "debug" then
  739. if debug == false then
  740. debug = true
  741. PrintHelp("Debug information enabled.", "FF00ff00")
  742. elseif debug == true then
  743. debug = false
  744. PrintHelp("Debug information disabled.", "FFff0000")
  745. end
  746. return
  747. elseif argv == "locfilter" then
  748. if locationChk == false then
  749. locationChk = true
  750. PrintHelp("Location mount filtering enabled.", "FF00ff00")
  751. elseif locationChk == true then
  752. locationChk = false
  753. PrintHelp("Location mount filtering disabled.", "FFff0000")
  754. end
  755. return
  756. elseif argv == "rfilter" then
  757. if removeMount == false then
  758. removeMount = true
  759. removeMountPrev = removeMount
  760. PrintHelp("Mount removal enabled.", "FF00ff00")
  761. elseif removeMount == true then
  762. removeMount = false
  763. removeMountPrev = removeMount
  764. PrintHelp("Mount removal disabled.", "FFff0000")
  765. end
  766. return
  767. elseif argv == "safefly" then
  768. if safeFly == false then
  769. safeFly = true
  770. PrintHelp("Safe flying enabled. Double click to dismount while flying", "FF00ff00")
  771. elseif safeFly == true then
  772. safeFly = false
  773. PrintHelp("Safe flying disabled.", "FFff0000")
  774. end
  775. return
  776. elseif argv == "rfilters" then
  777. if removeMount then
  778. PrintHelp("Mounts filtered: " .. table.concat(notWanted, ", "), "FF00ffff")
  779. else
  780. PrintHelp("Mount removal disabled.", "FFff0000")
  781. end
  782. return
  783. elseif argv == "title" then
  784. if rndTitle == false then
  785. rndTitle = true
  786. PrintHelp("Random title enabled.", "FF00ff00")
  787. elseif rndTitle == true then
  788. rndTitle = false
  789. PrintHelp("Random title disabled.", "FFff0000")
  790. end
  791. return
  792. elseif argv == "icon" then
  793. if macroIcon == false then
  794. macroIcon = true
  795. PrintHelp("Icon changing enabled.", "FF00ff00")
  796. elseif macroIcon == true then
  797. macroIcon = false
  798. PrintHelp("Icon changing disabled.", "FFff0000")
  799. end
  800. return
  801. elseif argv == "clear" then
  802. notWanted = {}
  803. zones = {}
  804. PrintHelp("All tables cleared.", "FF00ffff")
  805. return
  806. elseif argv == "clearrem" then
  807. notWanted = {}
  808. PrintHelp("Remove mount table cleared.", "FF00ffff")
  809. return
  810. elseif argv == "clearloc" then
  811. zones = {}
  812. PrintHelp("Special location table cleared.", "FF00ffff")
  813. return
  814. elseif argv == "loctable" then
  815. printLocF()
  816. return
  817. elseif argv:find("removeloc") then
  818. PrintHelp(strsub(argv, 11), "FF00ff99")
  819. if string.len(strsub(argv, 11)) > 0 then
  820. removeLocF(strsub(argv, 11))
  821. end
  822. return
  823. elseif argv == "riding" then
  824. mountType = "land"
  825. elseif argv == "flying" then
  826. mountType = "air"
  827. elseif argv == "swimming" then
  828. mountType = "sea"
  829. elseif argv:find("addloc") then
  830. if string.len(strsub(argv, 8)) > 0 then
  831. AddLocF(strsub(argv, 8))
  832. end
  833. return
  834. elseif argv:find("remove") then
  835. local found = false
  836. if strlen(strsub(argv, 8)) > 0 then
  837. for n, notW in ipairs(notWanted) do
  838. if strsub(argv, 8) == notW then
  839. PrintHelp(strsub(argv, 8) .. " already added.", "FF00ffff")
  840. found = true
  841. break
  842. end
  843. end
  844. --PrintHelp(table.concat(notWanted, ", "), "FF00ffff")
  845. if not found then
  846. PrintHelp("Mounts matching " .. strsub(argv, 8) .. " will no longer be summoned.", "FF00ff00")
  847. tinsert(notWanted, strsub(argv, 8))
  848. end
  849. end
  850. return
  851. elseif argv:find("setweight") then
  852. argv = strsub(argv, 11) or ""
  853. if strlen(argv) > 0 then
  854. local weight = string.match(argv, "%d+")
  855. local nameSearch = string.match(argv, "%a[%a%s]*%a$") or ""
  856. SetMountWeights(weight, nameSearch)
  857. end
  858. return
  859. -- elseif argv == "rnd" then
  860. -- r = random(C_MountJournal.GetNumMounts)
  861. -- PrintHelp(r, "FF00ffff")
  862. elseif strfind(argv, "r%s", 1) then
  863. mountType = "land"
  864. search = strlower(strsub(argv, 3))
  865. elseif strfind(argv, "f%s", 1) then
  866. mountType = "air"
  867. search = strlower(strsub(argv, 3))
  868. elseif strfind(argv, "s%s", 1) then
  869. mountType = "sea"
  870. search = strlower(strsub(argv, 3))
  871. else
  872. search = strlower(strsub(argv, 1))
  873. end
  874. -- Check if we are Mounted
  875. if IsMounted() then
  876. if safeFly and IsFlying() then
  877. local curTime = GetTime()
  878. if curTime < (lastTime + 0.5) then
  879. Dismount()
  880. return
  881. else
  882. lastTime = curTime
  883. return
  884. end
  885. else
  886. Dismount()
  887. return
  888. end
  889. elseif CanExitVehicle() then
  890. VehicleExit()
  891. return
  892. end
  893. -- Run Random Title
  894. RMount.SetCharTitle()
  895. -- Bail if no riding skill, no mounts, or if all-terrain mounts(land/sea/air) are not currently usable
  896. if ridingSK < 75 or mountCount.all == 0 or not IsUsableSpell(121838) then return end
  897. -- Process Search Mount
  898. if search ~= '' then
  899. if mountType == nil then
  900. mountType = "all"
  901. end
  902. BuildSearchCache(search, mountType)
  903. if mountCount.find[search][mountType] > 0 then
  904. GetRandomMount(mountType, ridingSK, zoneText, canFly, search, inLocation, zoneChk)
  905. else
  906. PrintHelp("No matching mount found.", "FF00ffff")
  907. end
  908. return
  909. end
  910.  
  911. -- If type specified then use it
  912. if mountType then
  913. GetRandomMount(mountType, ridingSK, zoneText, canFly, search, inLocation, zoneChk)
  914. -- Check if swimming and not at the surface/can't fly
  915. elseif checkSwimming() and not IsUsableSpell(130092) then
  916. -- Check if have usable sea mounts
  917. if CanSwimHere() then
  918. GetRandomMount("sea", ridingSK, zoneText, canFly, search, inLocation, zoneChk)
  919. else
  920. -- We might be under the surface with no sea mounts, or we can't fly
  921. -- Try to get an air mount first but few air mounts also work underwater
  922. if canFly then
  923. GetRandomMount("air", ridingSK, zoneText, canFly, search, inLocation, zoneChk)
  924. -- Check if we have a waterwalking mount
  925. elseif hasStrider then
  926. GetRandomMount("strider", ridingSK, zoneText, canFly, search, inLocation, zoneChk)
  927. end
  928. end
  929. -- Some indoor places in Vashj'ir like Nespirah can only use land mounts even though swimming checks all pass
  930. -- So try to get a land mount in case we're indoors in Vashj'ir or at the surface and can't fly
  931. -- It might summon the land mount even if another is already being summoned
  932. GetRandomMount("land", ridingSK, zoneText, canFly, search, inLocation, zoneChk)
  933. -- Check if we can fly
  934. elseif canFly then
  935. GetRandomMount("air", ridingSK, zoneText, canFly, search, inLocation, zoneChk)
  936. else
  937. GetRandomMount("land", ridingSK, zoneText, canFly, search, inLocation, zoneChk)
  938. end
  939.  
  940. --[[
  941. -- Check if you Can Fly, IsUsableSpell used for swimming on surface check
  942. if canFly and IsUsableSpell(88744) then
  943. -- Repeat picking a Mount until one is found that is appropriate
  944. GetRandomMount("air", ridingSK, zoneText, canFly, search, inLocation, zoneChk)
  945. -- Check if Summon Failed
  946. if mountError then
  947. canFly = false
  948. -- Check if you are Swimming
  949. if checkSwimming() then
  950. -- Get Sea Mount
  951. GetRandomMount("sea", ridingSK, zoneText, canFly, search, inLocation, zoneChk)
  952. end
  953. -- Reset mountError
  954. mountError = false
  955. -- Repeat picking a Mount until one is found that is appropriate
  956. GetRandomMount("air", ridingSK, zoneText, canFly, search, inLocation, zoneChk)
  957. -- Check if Summon Failed
  958. if mountError then
  959. PrintHelp("Cannot Summon Mount", "FFff0000")
  960. end
  961. end
  962. else
  963. -- Check if you are Swimming
  964. if checkSwimming() then
  965. -- Get Sea Mount
  966. GetRandomMount("sea", ridingSK, zoneText, canFly, search, inLocation, zoneChk)
  967. end
  968. mountError = false
  969. if mountCount.land ~= 0 then
  970. -- Repeat picking a Mount until one is found that is appropriate
  971. GetRandomMount("land", ridingSK, zoneText, canFly, search, inLocation, zoneChk)
  972. -- Check if Summon Failed
  973. if mountError then
  974. PrintHelp("Cannot Summon Mount", "FFff0000")
  975. end
  976. end
  977. end
  978. ]]--
  979.  
  980. return
  981. end
  982.  
  983. -- Test the Mount
  984. function TestMount(r, ridingSK, zoneText, canFly, inLocation, zoneChk, chance)
  985. local mountName = mountCache.all[r][1]
  986. local spellID = mountCache.all[r][2]
  987. local mountTypeID = mountCache.all[r][4]
  988. local isCollected = mountCache.all[r][5]
  989. local faction = mountCache.all[r][6]
  990. local realZone = GetCurrentMapAreaID()
  991.  
  992. -- Check if we have it
  993. if not isCollected then
  994. if debug then PrintHelp("Mount is not collected - Name: " .. mountName .. ", ID: " .. spellID, "FFff0000") end
  995. return false
  996. end
  997. -- Check if unusable (does not ensure it's usable)
  998. local usable = IsUsableSpell(spellID)
  999. if not usable then
  1000. if debug then PrintHelp("IsUsableSpell() returned false - Name: " .. mountName .. ", ID: " .. spellID, "FFff0000") end
  1001. return false
  1002. end
  1003. -- Check if our faction can use it
  1004. local factionGroup = UnitFactionGroup("player")
  1005. if (factionGroup == "Horde" and faction == 1) or (factionGroup == "Alliance" and faction == 0) then
  1006. if debug then PrintHelp("Mount is other faction - Name: " .. mountName .. ", ID: " .. spellID, "FFff0000") end
  1007. return false
  1008. end
  1009. --Remove Mount processing
  1010. if removeMount then
  1011. for n, notW in ipairs(notWanted) do
  1012. if strfind(strlower(mountName), strlower(notW)) or spellID == tonumber(notW) then
  1013. return false
  1014. end
  1015. end
  1016. end
  1017. --Abyssal Seahorse
  1018. if spellID == 75207 and realZone ~= 614 and realZone ~= 615 and realZone ~= 610 then
  1019. return false
  1020. end
  1021. --profession mounts
  1022. if (spellID == 44153 and engineerSkill < 300) or
  1023. (spellID == 44151 and engineerSkill < 375) or
  1024. (spellID == 61451 and tailorSkill < 300) or
  1025. (spellID == 75596 and tailorSkill < 425) or
  1026. (spellID == 61309 and tailorSkill < 425) then
  1027. if debug then PrintHelp("Profession skill too low - Name: " .. mountName .. ", ID: " .. spellID, "FFff0000") end
  1028. return false
  1029. end
  1030. --Zone Checking
  1031. if locationChk and zoneChk then
  1032. miniMapZone = GetMinimapZoneText()
  1033. local found = false
  1034. if zones[strlower(miniMapZone)] then
  1035. zoneChk = false
  1036. for i, type in ipairs(zones[strlower(miniMapZone)]) do
  1037. if strfind(strlower(mountName), strlower(type)) or type == "*" then
  1038. zoneChk = true
  1039. found = true
  1040. if debug then PrintHelp(type .. " : " .. mountName .. " is found", "FFffff00") end
  1041. break
  1042. end
  1043. end
  1044. end
  1045. -- Check your Zone
  1046. if zones[strlower(zoneText)] then
  1047. if not found then
  1048. zoneChk = false
  1049. for i, type in ipairs(zones[strlower(zoneText)]) do
  1050. if strfind(strlower(mountName), strlower(type)) or type == "*" then
  1051. zoneChk = true
  1052. if debug then PrintHelp(type .. " : " .. mountName .. " is found", "FFffff00") end
  1053. break
  1054. end
  1055. end
  1056. end
  1057. end
  1058. if not zoneChk then
  1059. return false
  1060. end
  1061. end
  1062. --flying mounts
  1063. if canFly then
  1064. if inLocation then
  1065. if lfmChk(mountName) then
  1066. if debug then PrintSummon("FF00ffff", mountName, r, ridingSK, mountTypeID, zoneText, canFly, spellID, chance, 11) end
  1067. return true
  1068. end
  1069. else
  1070. if debug then PrintSummon("FF00ffff", mountName, r, ridingSK, mountTypeID, zoneText, canFly, spellID, chance, 10) end
  1071. return true
  1072. end
  1073. --Regular Mounts
  1074. else
  1075. if inLocation then
  1076. if lfmChk(mountName) then
  1077. if debug then PrintSummon("FF00ffff", mountName, r, ridingSK, mountTypeID, zoneText, canFly, spellID, chance, 51) end
  1078. return true
  1079. end
  1080. else
  1081. if debug then PrintSummon("FF00ffff", mountName, r, ridingSK, mountTypeID, zoneText, canFly, spellID, chance, 50) end
  1082. return true
  1083. end
  1084. end
  1085. end
  1086.  
  1087. -- Print Help
  1088. function PrintHelp(cmd, color)
  1089. print(format('|c%s%s|r', color, cmd))
  1090. end
  1091.  
  1092. -- Print in Summon Color
  1093. function PrintSummon(color, mountName, r, ridingSK, mountTypeID, zoneText, canFly, spellID, chance, errorNum)
  1094. canFly = tostring(canFly)
  1095. print(format("|c%s%s - Mnt#:%s - Skill: %s - type:%s - %s - %s - flyZone:%s - cID:%s - chance:%.2f%% - cond:%s|r", color, mountName, r, ridingSK, mountTypeID, zoneText, GetMinimapZoneText(), canFly, spellID, chance, errorNum))
  1096. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement