Advertisement
Guest User

Item.lua

a guest
Nov 17th, 2019
1,191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.09 KB | None | 0 0
  1. _addon.name = 'itemdyr'
  2. _addon.author = 'Elidyr'
  3. _addon.version = '1.09182019'
  4. _addon.command = 'item'
  5.  
  6. res = require('resources')
  7. packets = require('packets')
  8. require ('logger')
  9.  
  10. windower.register_event('addon command', function(...)
  11.  
  12. local player = windower.ffxi.get_player()
  13. local command = (...) and (...):lower()
  14. local build = {select(2, ...)}
  15. local commands = ""
  16. local match = {}
  17. local amount = 0
  18. local count = 0
  19.  
  20. -- Build command strings and tables.
  21. if build then
  22.  
  23. for i,v in pairs(build) do
  24. commands = commands .. " " .. v
  25. end
  26.  
  27. commands = commands:sub(2)
  28.  
  29. for w in string.gmatch(commands, "[%a']+") do
  30. table.insert(match, w)
  31. end
  32.  
  33. end
  34.  
  35. if command == 'trade' then
  36.  
  37. if match then
  38.  
  39. local duplicate = {}
  40. local item
  41.  
  42. if match[1] ~= "max" then
  43.  
  44. name = commands
  45. item = bpCheckInventoryForItem(name)
  46.  
  47. if item then
  48. duplicate = {item.id,item.id,item.id,item.id,item.id,item.id,item.id,item.id}
  49. count = select(2, bpFindItem(duplicate[1]))
  50. amount = count * #duplicate
  51. else
  52. windower.add_to_chat(5, 'Unable to find items!')
  53. end
  54.  
  55. else
  56.  
  57. item = bpCheckInventoryForItem(commands:sub(#match[1]+2))
  58.  
  59. if item then
  60. duplicate = {item.id,item.id,item.id,item.id,item.id,item.id,item.id,item.id,item.id}
  61. count = select(2, bpFindItem(duplicate[1]))
  62. amount = count * #duplicate
  63. else
  64. windower.add_to_chat(5, 'Unable to find items!')
  65. end
  66.  
  67. end
  68.  
  69. if item and item.id and windower.ffxi.get_mob_by_target('t') then
  70. local target = windower.ffxi.get_mob_by_target('t')
  71.  
  72. if bpFindItem(duplicate[1]) then
  73. local id = select(3, bpFindItem(duplicate[1]))
  74.  
  75. if bpFindNPC({target.id}) then
  76.  
  77. if math.sqrt(target.distance) < 6 then
  78. bpTradeNPC(bpFindNPC({target.id}), duplicate)
  79. windower.add_to_chat(5, "Trading: " .. amount .. " " .. item.name .. " to target: " .. target.name .. ".")
  80.  
  81. elseif math.sqrt(target.distance) > 6 then
  82. windower.add_to_chat(5, 'Player is to far away!')
  83. end
  84.  
  85. else
  86. windower.add_to_chat(5, 'Unable to find a target!')
  87.  
  88. end
  89.  
  90. else
  91. windower.add_to_chat(5, 'Verify items and target!')
  92.  
  93. end
  94.  
  95. end
  96.  
  97. end
  98.  
  99. elseif command == 'relic' then
  100. windower.add_to_chat(5, 'No max trade allowed!')
  101.  
  102. if match then
  103.  
  104. local duplicate = {}
  105. local item
  106. local amount
  107.  
  108. name = commands
  109. item = bpCheckInventoryForItem(name)
  110.  
  111. if item then
  112. duplicate = {item.id,item.id,item.id,item.id,item.id}
  113. count = select(2, bpFindItem(duplicate[1]))
  114. amount = count * #duplicate
  115. else
  116. windower.add_to_chat(5, 'Unable to find items!')
  117. end
  118.  
  119. if item and item.id and windower.ffxi.get_mob_by_target('t') then
  120. local target = windower.ffxi.get_mob_by_target('t')
  121.  
  122. if bpFindItem(duplicate[1]) then
  123. local id = select(3, bpFindItem(duplicate[1]))
  124.  
  125. if bpFindNPC({target.id}) then
  126.  
  127. if math.sqrt(target.distance) < 6 then
  128. bpTradeNPC(bpFindNPC({target.id}), duplicate)
  129. windower.add_to_chat(5, "Trading: " .. amount .. " " .. item.name .. " to target: " .. target.name .. ".")
  130.  
  131. elseif math.sqrt(target.distance) > 6 then
  132. windower.add_to_chat(5, 'Player is to far away!')
  133. end
  134.  
  135. else
  136. windower.add_to_chat(5, 'Unable to find target!')
  137.  
  138. end
  139.  
  140. else
  141. windower.add_to_chat(5, 'Verify items and target!')
  142.  
  143. end
  144.  
  145. end
  146.  
  147. end
  148.  
  149. elseif command == 'astral' then
  150.  
  151. if match then
  152.  
  153. local oboro = {17784988}
  154. local stones = {}
  155. local item
  156.  
  157. if match[1] ~= "max" then
  158.  
  159. name = commands
  160. item = bpCheckInventoryForItem(name)
  161.  
  162. if item then
  163. stones = {9875,9875,9875,9875,9875,9875,9875,item.id}
  164. count = select(2, bpFindItem(stones[1]))
  165. amount = count * (#stones-1)
  166. else
  167. windower.add_to_chat(5, 'Unable to find that item!')
  168. end
  169.  
  170. else
  171.  
  172. item = bpCheckInventoryForItem(commands:sub(#match[1]+2))
  173.  
  174. if item then
  175. stones = {9875,9875,9875,9875,9875,9875,9875,9875,item.id}
  176. count = select(2, bpFindItem(stones[1]))
  177. amount = count * (#stones-1)
  178. else
  179. windower.add_to_chat(5, 'Unable to find that item!')
  180. end
  181.  
  182. end
  183.  
  184. if bpFindItem(stones[1]) then
  185. local id = select(3, bpFindItem(stones[1]))
  186.  
  187. if bpFindNPC(oboro) then
  188. local target = windower.ffxi.get_mob_by_id(oboro[1])
  189.  
  190. if math.sqrt(target.distance) < 6 then
  191. bpTradeNPC(bpFindNPC(oboro), stones)
  192. windower.add_to_chat(5, "Trading: " .. amount .. " S. Astrals in to: " .. item.name .. ".")
  193.  
  194. elseif math.sqrt(target.distance) > 6 then
  195. windower.add_to_chat(5, 'Oboro is to far away!')
  196.  
  197. end
  198.  
  199. else
  200. windower.add_to_chat(5, 'Unable to find Oboro!')
  201.  
  202. end
  203.  
  204. else
  205. windower.add_to_chat(5, 'Unable to find that item!')
  206.  
  207. end
  208.  
  209. end
  210.  
  211. elseif command == 'astralhq' then
  212.  
  213. if match then
  214.  
  215. local oboro = {17784988}
  216. local stones = {}
  217. local item
  218.  
  219. if match[1] ~= "max" then
  220.  
  221. name = commands
  222. item = bpCheckInventoryForItem(name)
  223.  
  224. if item then
  225. stones = {9876,9876,9876,9876,9876,9876,9876,item.id}
  226. count = select(2, bpFindItem(stones[1]))
  227. amount = count * (#stones-1)
  228. else
  229. windower.add_to_chat(5, 'Unable to find that item!')
  230. end
  231.  
  232. else
  233.  
  234. item = bpCheckInventoryForItem(commands:sub(#match[1]+2))
  235.  
  236. if item then
  237. stones = {9876,9876,9876,9876,9876,9876,9876,9876,item.id}
  238. count = select(2, bpFindItem(stones[1]))
  239. amount = count * (#stones-1)
  240. else
  241. windower.add_to_chat(5, 'Unable to find that item!')
  242. end
  243.  
  244. end
  245.  
  246. if bpFindItem(stones[1]) then
  247. local id = select(3, bpFindItem(stones[1]))
  248.  
  249. if bpFindNPC(oboro) then
  250. local target = windower.ffxi.get_mob_by_id(oboro[1])
  251.  
  252. if math.sqrt(target.distance) < 6 then
  253. bpTradeNPC(bpFindNPC(oboro), stones)
  254. windower.add_to_chat(5, "Trading: " .. amount .. " M. Astrals in to: " .. item.name .. ".")
  255.  
  256. elseif math.sqrt(target.distance) > 6 then
  257. windower.add_to_chat(5, 'Oboro is to far away!')
  258.  
  259. end
  260.  
  261. else
  262. windower.add_to_chat(5, 'Unable to find Oboro!')
  263.  
  264. end
  265.  
  266. else
  267. windower.add_to_chat(5, 'Unable to find that item!')
  268.  
  269. end
  270.  
  271. end
  272.  
  273. elseif command == 'heroism' then
  274.  
  275. if match then
  276.  
  277. local oboro = {17784988}
  278. local stones = {}
  279. local item
  280.  
  281. if match[1] ~= "max" then
  282.  
  283. name = commands
  284. item = bpCheckInventoryForItem(name)
  285.  
  286. if item then
  287. stones = {9877,9877,9877,9877,9877,9877,9877,item.id}
  288. count = select(2, bpFindItem(stones[1]))
  289. amount = count * (#stones-1)
  290. else
  291. windower.add_to_chat(5, 'Unable to find items!')
  292. end
  293.  
  294. else
  295.  
  296. item = bpCheckInventoryForItem(commands:sub(#match[1]+2))
  297.  
  298. if item then
  299. stones = {9877,9877,9877,9877,9877,9877,9877,9877,item.id}
  300. count = select(2, bpFindItem(stones[1]))
  301. amount = count * (#stones-1)
  302. else
  303. windower.add_to_chat(5, 'Unable to find that item!')
  304. end
  305.  
  306. end
  307.  
  308. if bpFindItem(stones[1]) then
  309. local id = select(3, bpFindItem(stones[1]))
  310.  
  311. if bpFindNPC(oboro) then
  312. local target = windower.ffxi.get_mob_by_id(oboro[1])
  313.  
  314. if math.sqrt(target.distance) < 6 then
  315. bpTradeNPC(bpFindNPC(oboro), stones)
  316. windower.add_to_chat(5, "Trading: " .. amount .. " Heroism Crystals in to: " .. item.name .. ".")
  317.  
  318. elseif math.sqrt(target.distance) > 6 then
  319. windower.add_to_chat(5, 'Oboro is to far away!')
  320.  
  321. end
  322.  
  323. else
  324. windower.add_to_chat(5, 'Unable to find Oboro!')
  325.  
  326. end
  327.  
  328. else
  329. windower.add_to_chat(5, 'Unable to find that item!')
  330.  
  331. end
  332.  
  333. end
  334.  
  335. elseif command == 'herohq' then
  336.  
  337. if match then
  338.  
  339. local oboro = {17784988}
  340. local stones = {}
  341. local item
  342.  
  343. if match[1] ~= "max" then
  344.  
  345. name = commands
  346. item = bpCheckInventoryForItem(name)
  347.  
  348. if item then
  349. stones = {9878,9878,9878,9878,9878,9878,9878,item.id}
  350. count = select(2, bpFindItem(stones[1]))
  351. amount = count * (#stones-1)
  352. else
  353. windower.add_to_chat(5, 'Unable to find items!')
  354. end
  355.  
  356. else
  357.  
  358. item = bpCheckInventoryForItem(commands:sub(#match[1]+2))
  359.  
  360. if item then
  361. stones = {9878,9878,9878,9878,9878,9878,9878,9878,item.id}
  362. count = select(2, bpFindItem(stones[1]))
  363. amount = count * (#stones-1)
  364. else
  365. windower.add_to_chat(5, 'Unable to find that item!')
  366. end
  367.  
  368. end
  369.  
  370. if bpFindItem(stones[1]) then
  371. local id = select(3, bpFindItem(stones[1]))
  372.  
  373. if bpFindNPC(oboro) then
  374. local target = windower.ffxi.get_mob_by_id(oboro[1])
  375.  
  376. if math.sqrt(target.distance) < 6 then
  377. bpTradeNPC(bpFindNPC(oboro), stones)
  378. windower.add_to_chat(5, "Trading: " .. amount .. " Heroism Aggregate in to: " .. item.name .. ".")
  379.  
  380. elseif math.sqrt(target.distance) > 6 then
  381. windower.add_to_chat(5, 'Oboro is to far away!')
  382.  
  383. end
  384.  
  385. else
  386. windower.add_to_chat(5, 'Unable to find Oboro!')
  387.  
  388. end
  389.  
  390. else
  391. windower.add_to_chat(5, 'Unable to find that item!')
  392.  
  393. end
  394.  
  395. end
  396.  
  397. elseif command == 'plutons' then
  398.  
  399. if match then
  400.  
  401. local oboro = {17784988}
  402. local stones = {}
  403. local item
  404.  
  405. if match[1] ~= "max" then
  406.  
  407. name = commands
  408. item = bpCheckInventoryForItem(name)
  409.  
  410. if item then
  411. stones = {4059,4059,4059,4059,4059,4059,4059,item.id}
  412. count = select(2, bpFindItem(stones[1]))
  413. amount = count * (#stones-1)
  414. else
  415. windower.add_to_chat(5, 'Unable to find that item!')
  416. end
  417.  
  418. else
  419.  
  420. item = bpCheckInventoryForItem(commands:sub(#match[1]+2))
  421.  
  422. if item then
  423. stones = {4059,4059,4059,4059,4059,4059,4059,4059,item.id}
  424. count = select(2, bpFindItem(stones[1]))
  425. amount = count * (#stones-1)
  426. else
  427. windower.add_to_chat(5, 'Unable to find that item!')
  428. end
  429.  
  430. end
  431.  
  432. if item and item.id then
  433. local target = windower.ffxi.get_mob_by_id(oboro[1])
  434.  
  435. if bpFindItem(stones[1]) then
  436. local id = select(3, bpFindItem(stones[1]))
  437.  
  438. if bpFindNPC(oboro) then
  439.  
  440. if math.sqrt(target.distance) < 6 then
  441. bpTradeNPC(bpFindNPC(oboro), stones)
  442. windower.add_to_chat(5, "Trading: " .. amount .. " Plutons in to: " .. item.name .. ".")
  443.  
  444. elseif math.sqrt(target.distance) > 6 then
  445. windower.add_to_chat(5, 'Target is to far away!')
  446.  
  447. end
  448.  
  449. else
  450. windower.add_to_chat(5, 'Unable to find NPC!')
  451.  
  452. end
  453.  
  454. else
  455. windower.add_to_chat(5, 'Unable to find items!')
  456.  
  457. end
  458.  
  459. end
  460.  
  461. end
  462.  
  463. elseif command == 'beits' then
  464.  
  465. if match then
  466.  
  467. local oboro = {17784988}
  468. local stones = {}
  469. local item
  470.  
  471. if match[1] ~= "max" then
  472.  
  473. name = commands
  474. item = bpCheckInventoryForItem(name)
  475.  
  476. if item then
  477. stones = {4060,4060,4060,4060,4060,4060,4060,item.id}
  478. count = select(2, bpFindItem(stones[1]))
  479. amount = count * (#stones-1)
  480. else
  481. windower.add_to_chat(5, 'Unable to find that item!')
  482. end
  483.  
  484. else
  485.  
  486. item = bpCheckInventoryForItem(commands:sub(#match[1]+2))
  487.  
  488. if item then
  489. stones = {4060,4060,4060,4060,4060,4060,4060,4060,item.id}
  490. count = select(2, bpFindItem(stones[1]))
  491. amount = count * (#stones-1)
  492. else
  493. windower.add_to_chat(5, 'Unable to find that item!')
  494. end
  495.  
  496. end
  497.  
  498. if item and item.id then
  499. local target = windower.ffxi.get_mob_by_id(oboro[1])
  500.  
  501. if bpFindItem(stones[1]) then
  502. local id = select(3, bpFindItem(stones[1]))
  503.  
  504. if bpFindNPC(oboro) then
  505.  
  506. if math.sqrt(target.distance) < 6 then
  507. bpTradeNPC(bpFindNPC(oboro), stones)
  508. windower.add_to_chat(5, "Trading: " .. amount .. " Beitetsu in to: " .. item.name .. ".")
  509.  
  510. elseif math.sqrt(target.distance) > 6 then
  511. windower.add_to_chat(5, 'Target is to far away!')
  512.  
  513. end
  514.  
  515. else
  516. windower.add_to_chat(5, 'Unable to find Player!')
  517.  
  518. end
  519.  
  520. else
  521. windower.add_to_chat(5, 'Unable to find items!')
  522.  
  523. end
  524.  
  525. end
  526.  
  527. end
  528.  
  529. elseif command == 'boulders' then
  530.  
  531. if match then
  532.  
  533. local oboro = {17784988}
  534. local stones = {}
  535. local item
  536.  
  537. if match[1] ~= "max" then
  538.  
  539. name = commands
  540. item = bpCheckInventoryForItem(name)
  541.  
  542. if item then
  543. stones = {4061,4061,4061,4061,4061,4061,4061,item.id}
  544. count = select(2, bpFindItem(stones[1]))
  545. amount = count * (#stones-1)
  546. else
  547. windower.add_to_chat(5, 'Unable to find that item!')
  548. end
  549.  
  550. else
  551.  
  552. item = bpCheckInventoryForItem(commands:sub(#match[1]+2))
  553.  
  554. if item then
  555. stones = {4061,4061,4061,4061,4061,4061,4061,4061,item.id}
  556. count = select(2, bpFindItem(stones[1]))
  557. amount = count * (#stones-1)
  558. else
  559. windower.add_to_chat(5, 'Unable to find that item!')
  560. end
  561.  
  562. end
  563.  
  564. if item and item.id then
  565. local target = windower.ffxi.get_mob_by_id(oboro[1])
  566.  
  567. if bpFindItem(stones[1]) then
  568. local id = select(3, bpFindItem(stones[1]))
  569.  
  570. if bpFindNPC(oboro) then
  571.  
  572. if math.sqrt(target.distance) < 6 then
  573. bpTradeNPC(bpFindNPC(oboro), stones)
  574. windower.add_to_chat(5, "Trading: " .. amount .. " Riftborn Boulders in to: " .. item.name .. ".")
  575.  
  576. elseif math.sqrt(target.distance) > 6 then
  577. windower.add_to_chat(5, 'Target is to far away!')
  578.  
  579. end
  580.  
  581. else
  582. windower.add_to_chat(5, 'Unable to find Player!')
  583.  
  584. end
  585.  
  586. else
  587. windower.add_to_chat(5, 'Unable to find items!')
  588.  
  589. end
  590.  
  591. end
  592.  
  593. end
  594.  
  595. elseif command == 'metal' then
  596.  
  597. if match then
  598.  
  599. local gorpa = {17797273}
  600. local metal = {}
  601. local item
  602.  
  603. if match[1] ~= "max" then
  604.  
  605. name = commands
  606. item = bpCheckInventoryForItem(name)
  607.  
  608. if item then
  609. metal = {9270,9270,9270,9270,9270,9270,9270,item.id}
  610. count = select(2, bpFindItem(metal[1]))
  611. amount = count * (#metal-1)
  612. else
  613. windower.add_to_chat(5, 'Unable to find that item!')
  614. end
  615.  
  616. else
  617.  
  618. item = bpCheckInventoryForItem(commands:sub(#match[1]+2))
  619.  
  620. if item then
  621. metal = {9270,9270,9270,9270,9270,9270,9270,9270,item.id}
  622. count = select(2, bpFindItem(metal[1]))
  623. amount = count * (#metal-1)
  624. else
  625. windower.add_to_chat(5, 'Unable to find that item!')
  626. end
  627.  
  628. end
  629.  
  630. if item and item.id and bpFindNPC(gorpa) then
  631. local target = windower.ffxi.get_mob_by_id(gorpa[1])
  632.  
  633. if bpFindItem(metal[1]) then
  634. local id = select(3, bpFindItem(metal[1]))
  635.  
  636. if bpFindNPC({target.id}) then
  637.  
  638. if math.sqrt(target.distance) < 6 then
  639. bpTradeNPC(bpFindNPC(gorpa), metal)
  640. windower.add_to_chat(5, "Trading: " .. amount .. " Abd. Metals in to: " .. item.name .. ".")
  641.  
  642. elseif math.sqrt(target.distance) > 6 then
  643. windower.add_to_chat(5, 'Target is to far away!')
  644.  
  645. end
  646.  
  647. else
  648. windower.add_to_chat(5, 'Unable to find Player!')
  649.  
  650. end
  651.  
  652. else
  653. windower.add_to_chat(5, 'Unable to find items!')
  654.  
  655. end
  656.  
  657. end
  658.  
  659. end
  660.  
  661. elseif command == 'fiber' then
  662.  
  663. if match then
  664.  
  665. local gorpa = {17797273}
  666. local fiber = {}
  667. local item
  668.  
  669. if match[1] ~= "max" then
  670.  
  671. name = commands
  672. item = bpCheckInventoryForItem(name)
  673.  
  674. if item then
  675. fiber = {9271,9271,9271,9271,9271,9271,9271,item.id}
  676. count = select(2, bpFindItem(fiber[1]))
  677. amount = count * (#fiber-1)
  678. else
  679. windower.add_to_chat(5, 'Unable to find that item!')
  680. end
  681.  
  682. else
  683.  
  684. item = bpCheckInventoryForItem(commands:sub(#match[1]+2))
  685.  
  686. if item then
  687. fiber = {9271,9271,9271,9271,9271,9271,9271,9271,item.id}
  688. count = select(2, bpFindItem(fiber[1]))
  689. amount = count * (#fiber-1)
  690. else
  691. windower.add_to_chat(5, 'Unable to find that item!')
  692. end
  693.  
  694. end
  695.  
  696. if item and item.id and bpFindNPC(gorpa) then
  697. local target = windower.ffxi.get_mob_by_id(gorpa[1])
  698.  
  699. if bpFindItem(fiber[1]) then
  700. local id = select(3, bpFindItem(fiber[1]))
  701.  
  702. if bpFindNPC({target.id}) then
  703.  
  704. if math.sqrt(target.distance) < 6 then
  705. bpTradeNPC(bpFindNPC(gorpa), fiber)
  706. windower.add_to_chat(5, "Trading: " .. amount .. " Abd. Fibers in to: " .. item.name .. ".")
  707.  
  708. elseif math.sqrt(target.distance) > 6 then
  709. windower.add_to_chat(5, 'Target is to far away!')
  710.  
  711. end
  712.  
  713. else
  714. windower.add_to_chat(5, 'Unable to find Player!')
  715.  
  716. end
  717.  
  718. else
  719. windower.add_to_chat(5, 'Unable to find items!')
  720.  
  721. end
  722.  
  723. end
  724.  
  725. end
  726.  
  727. elseif command == 'cape' then
  728.  
  729. if match then
  730.  
  731. local gorpa = {17797273}
  732. local materials = {}
  733. local cape
  734.  
  735. if match[1] ~= "max" then
  736.  
  737. cape = bpCheckInventoryForItem(match[1])
  738. mats = bpCheckInventoryForItem(commands:sub(#match[1]+2))
  739.  
  740. if cape and mats then
  741. materials = {mats.id,mats.id,mats.id,mats.id,mats.id,mats.id,mats.id,cape.id}
  742. count = select(2, bpFindItem(materials[1]))
  743. amount = count * (#materials-1)
  744. else
  745. windower.add_to_chat(5, 'Unable to find that item!')
  746. end
  747.  
  748. else
  749.  
  750. cape = bpCheckInventoryForItem(match[2])
  751. mats = bpCheckInventoryForItem(commands:sub(#match[1]+1+#match[2]+2))
  752.  
  753. if cape and mats then
  754. materials = {mats.id,mats.id,mats.id,mats.id,mats.id,mats.id,mats.id,mats.id,cape.id}
  755. count = select(2, bpFindItem(materials[1]))
  756. amount = count * (#materials-1)
  757. else
  758. windower.add_to_chat(5, 'Unable to find that item!')
  759. end
  760.  
  761. end
  762.  
  763. if cape and mats and cape.id and mats.id and bpFindNPC(gorpa) then
  764. local target = windower.ffxi.get_mob_by_id(gorpa[1])
  765.  
  766. if bpFindItem(materials[1]) then
  767. local id = select(3, bpFindItem(materials[1]))
  768.  
  769. if player and bpFindNPC({player.id}) then
  770.  
  771. if math.sqrt(target.distance) < 6 then
  772. bpTradeNPC(bpFindNPC(gorpa), materials)
  773. windower.add_to_chat(5, "Trading: " .. amount .. " of " .. mats.name .. " in to cape: " .. cape.name .. ".")
  774.  
  775. elseif math.sqrt(target.distance) > 6 then
  776. windower.add_to_chat(5, 'Target is to far away!')
  777.  
  778. end
  779.  
  780. else
  781. windower.add_to_chat(5, 'Unable to find Player!')
  782.  
  783. end
  784.  
  785. else
  786. windower.add_to_chat(5, 'Unable to find items!')
  787.  
  788. end
  789.  
  790. end
  791.  
  792. end
  793.  
  794. elseif command == 'unity' then
  795.  
  796. if match then
  797.  
  798. local unity_npc = windower.ffxi.get_mob_by_target('t')
  799. local materials = {}
  800. local item
  801.  
  802. if match[1] ~= "max" then
  803.  
  804. item = bpCheckInventoryForItem(match[1])
  805. mats = bpCheckInventoryForItem(commands:sub(#match[1]+2))
  806.  
  807. if item and mats then
  808. materials = {mats.id,mats.id,mats.id,mats.id,mats.id,mats.id,mats.id,item.id}
  809. count = select(2, bpFindItem(materials[1]))
  810. amount = count * (#materials-1)
  811. else
  812. windower.add_to_chat(5, 'Unable to find that item!')
  813. end
  814.  
  815. else
  816.  
  817. item = bpCheckInventoryForItem(match[2])
  818. mats = bpCheckInventoryForItem(commands:sub(#match[1]+1+#match[2]+2))
  819.  
  820. if item and mats then
  821. materials = {mats.id,mats.id,mats.id,mats.id,mats.id,mats.id,mats.id,mats.id,item.id}
  822. count = select(2, bpFindItem(materials[1]))
  823. amount = count * (#materials-1)
  824. else
  825. windower.add_to_chat(5, 'Unable to find that item!')
  826. end
  827.  
  828. end
  829.  
  830. if item and mats and item.id and mats.id and bpFindNPC({unity_npc.id}) then
  831.  
  832. if bpFindItem(materials[1]) then
  833. local id = select(3, bpFindItem(materials[1]))
  834.  
  835. if player and bpFindNPC({player.id}) then
  836.  
  837. if math.sqrt(unity_npc.distance) < 6 then
  838. bpTradeNPC(bpFindNPC({unity_npc.id}), materials)
  839. windower.add_to_chat(5, "Trading: " .. amount .. " of " .. mats.name .. " in to: " .. item.name .. ".")
  840.  
  841. elseif math.sqrt(unity_npc.distance) > 6 then
  842. windower.add_to_chat(5, 'Target is to far away!')
  843.  
  844. end
  845.  
  846. else
  847. windower.add_to_chat(5, 'Unable to find Player!')
  848.  
  849. end
  850.  
  851. else
  852. windower.add_to_chat(5, 'Unable to find items!')
  853.  
  854. end
  855.  
  856. end
  857.  
  858. end
  859.  
  860. elseif command == 'weapon' then
  861.  
  862. if match then
  863.  
  864. local gorpa = {17797273}
  865. local materials = {}
  866. local weapon
  867.  
  868. if match[1] ~= "max" then
  869.  
  870. weapon = bpCheckInventoryForItem(match[1])
  871. mats = bpCheckInventoryForItem(commands:sub(#match[1]+2))
  872.  
  873. if weapon and mats then
  874. materials = {mats.id,mats.id,mats.id,mats.id,mats.id,mats.id,mats.id,weapon.id}
  875. count = select(2, bpFindItem(materials[1]))
  876. amount = count * (#materials-1)
  877. else
  878. windower.add_to_chat(5, 'Unable to find that item!')
  879. end
  880.  
  881. else
  882.  
  883. weapon = bpCheckInventoryForItem(match[2])
  884. mats = bpCheckInventoryForItem(commands:sub(#match[1]+1+#match[2]+2))
  885.  
  886. if weapon and mats then
  887. materials = {mats.id,mats.id,mats.id,mats.id,mats.id,mats.id,mats.id,mats.id,weapon.id}
  888. count = select(2, bpFindItem(materials[1]))
  889. amount = count * (#materials-1)
  890. else
  891. windower.add_to_chat(5, 'Unable to find that item!')
  892. end
  893.  
  894. end
  895.  
  896. if weapon and mats and weapon.id and mats.id and bpFindNPC(gorpa) then
  897. local target = windower.ffxi.get_mob_by_id(gorpa[1])
  898.  
  899. if bpFindItem(materials[1]) then
  900. local id = select(3, bpFindItem(materials[1]))
  901.  
  902. if player and bpFindNPC({player.id}) then
  903.  
  904. if math.sqrt(target.distance) < 6 then
  905. bpTradeNPC(bpFindNPC(gorpa), materials)
  906. windower.add_to_chat(5, "Trading: " .. amount .. " of " .. mats.name .. " in to weapon: " .. weapon.name .. ".")
  907.  
  908. elseif math.sqrt(target.distance) > 6 then
  909. windower.add_to_chat(5, 'Target is to far away!')
  910.  
  911. end
  912.  
  913. else
  914. windower.add_to_chat(5, 'Unable to find Player!')
  915.  
  916. end
  917.  
  918. else
  919. windower.add_to_chat(5, 'Unable to find items!')
  920.  
  921. end
  922.  
  923. end
  924.  
  925. end
  926.  
  927. elseif command == 'glow' then
  928.  
  929. if match then
  930.  
  931. local gorpa = {17797273}
  932. local materials = {}
  933. local weapon
  934. local glow
  935.  
  936. if match[1] ~= "max" then
  937.  
  938. weapon = bpCheckInventoryForItem(match[1])
  939. glow = bpCheckInventoryForItem(match[2])
  940. mats = bpCheckInventoryForItem(commands:sub(#match[1]+1+#match[2]+2))
  941.  
  942. if weapon and glow and mats then
  943. materials = {mats.id,mats.id,mats.id,mats.id,mats.id,mats.id,glow.id,weapon.id}
  944. count = select(2, bpFindItem(materials[1]))
  945. amount = count * (#materials-2)
  946. else
  947. windower.add_to_chat(5, 'Unable to find that item!')
  948. end
  949.  
  950. else
  951.  
  952. weapon = bpCheckInventoryForItem(match[2])
  953. glow = bpCheckInventoryForItem(match[3])
  954. mats = bpCheckInventoryForItem(commands:sub(#match[2]+1+#match[3]+2))
  955.  
  956. if weapon and glow and mats then
  957. materials = {mats.id,mats.id,mats.id,mats.id,mats.id,mats.id,mats.id,glow.id,weapon.id}
  958. count = select(2, bpFindItem(materials[1]))
  959. amount = count * (#materials-2)
  960. else
  961. windower.add_to_chat(5, 'Unable to find that item!')
  962. end
  963.  
  964. end
  965.  
  966. if weapon and glow and mats and weapon.id and glow.id and mats.id and bpFindNPC(gorpa) then
  967. local target = windower.ffxi.get_mob_by_id(gorpa[1])
  968.  
  969. if bpFindItem(materials[1]) then
  970. local id = select(3, bpFindItem(materials[1]))
  971.  
  972. if player and bpFindNPC({player.id}) then
  973.  
  974. if math.sqrt(target.distance) < 6 then
  975. bpTradeNPC(bpFindNPC(gorpa), materials)
  976. windower.add_to_chat(5, "Trading: " .. amount .. " of " .. mats.name .. " with glow weapon, " .. glow.name .. " in to weapon: " .. weapon.name .. ".")
  977.  
  978. elseif math.sqrt(target.distance) > 6 then
  979. windower.add_to_chat(5, 'Target is to far away!')
  980.  
  981. end
  982.  
  983. else
  984. windower.add_to_chat(5, 'Unable to find Player!')
  985.  
  986. end
  987.  
  988. else
  989. windower.add_to_chat(5, 'Unable to find items!')
  990.  
  991. end
  992.  
  993. end
  994.  
  995. end
  996.  
  997. elseif command == 'reload' or command == 'r' or command == 'rl' then
  998. windower.send_command('lua reload itemdyr')
  999.  
  1000. end
  1001.  
  1002. end)
  1003.  
  1004. function bpFindItem(itemId)
  1005.  
  1006. local items = windower.ffxi.get_items(0)
  1007.  
  1008. for index, item in ipairs(items) do
  1009.  
  1010. if item and item.id == itemId and item.status == 0 then
  1011. return index, item.count, item.id
  1012.  
  1013. end
  1014.  
  1015. end
  1016.  
  1017. return false
  1018.  
  1019. end
  1020.  
  1021. function bpFindNPC(npcs)
  1022.  
  1023. for i, v in ipairs(npcs) do
  1024.  
  1025. if windower.ffxi.get_mob_by_id(v) then
  1026. return windower.ffxi.get_mob_by_id(v)
  1027.  
  1028. end
  1029.  
  1030. end
  1031.  
  1032. return false
  1033.  
  1034. end
  1035.  
  1036. function bpCheckInventoryForItem(item_name)
  1037.  
  1038. local items = windower.ffxi.get_items(0)
  1039.  
  1040. for index, item in ipairs(items) do
  1041.  
  1042. if item and index and item.id and item.status == 0 then
  1043.  
  1044. local found_item = res.items[item.id]
  1045.  
  1046. if found_item and found_item.name then
  1047.  
  1048. local name = found_item.name
  1049.  
  1050. if name:sub(1, #item_name):lower() == item_name:lower() then
  1051. return found_item
  1052. end
  1053.  
  1054. end
  1055.  
  1056. end
  1057.  
  1058. end
  1059. return false
  1060.  
  1061. end
  1062.  
  1063. function bpGetIndexesByName(item_name)
  1064.  
  1065. local items = windower.ffxi.get_items(0)
  1066. local found_items = {}
  1067.  
  1068. for index, item in ipairs(items) do
  1069.  
  1070. if item and index and item.id and item.status == 0 then
  1071.  
  1072. local found_item = res.items[item.id]
  1073.  
  1074. if found_item and found_item.name then
  1075.  
  1076. local name = found_item.name
  1077.  
  1078. if name:sub(1, #item_name):lower() == item_name:lower() then
  1079. table.insert(found_items, index)
  1080.  
  1081. end
  1082.  
  1083. end
  1084.  
  1085. end
  1086.  
  1087. end
  1088. return found_items
  1089.  
  1090. end
  1091.  
  1092. function bpTradeNPC(npc, items)
  1093.  
  1094. if npc and items then
  1095.  
  1096. local _L = {}
  1097.  
  1098. _L.itemcount1 = 0
  1099. _L.itemcount2 = 0
  1100. _L.itemcount3 = 0
  1101. _L.itemcount4 = 0
  1102. _L.itemcount5 = 0
  1103. _L.itemcount6 = 0
  1104. _L.itemcount7 = 0
  1105. _L.itemcount8 = 0
  1106. _L.itemcount9 = 0
  1107. _L.itemindex1 = 0
  1108. _L.itemindex2 = 0
  1109. _L.itemindex3 = 0
  1110. _L.itemindex4 = 0
  1111. _L.itemindex5 = 0
  1112. _L.itemindex6 = 0
  1113. _L.itemindex7 = 0
  1114. _L.itemindex8 = 0
  1115. _L.itemindex9 = 0
  1116. _L.quantity = 0
  1117.  
  1118. for i, v in ipairs(items) do
  1119.  
  1120. if v ~= 0 then
  1121.  
  1122. local index, count, itemid = bpFindItem(v)
  1123.  
  1124. if index and count then
  1125.  
  1126. _L['quantity'] = _L['quantity'] + 1
  1127.  
  1128. local q = tostring(_L.quantity)
  1129.  
  1130. _L['itemcount' .. q] = count
  1131. _L['itemindex' .. q] = index
  1132.  
  1133. end
  1134.  
  1135. end
  1136.  
  1137. end
  1138.  
  1139. local p = packets.new('outgoing', 0x036, {
  1140. ['Target'] = npc.id,
  1141. ['Item Count 1'] = _L.itemcount1,
  1142. ['Item Count 2'] = _L.itemcount2,
  1143. ['Item Count 3'] = _L.itemcount3,
  1144. ['Item Count 4'] = _L.itemcount4,
  1145. ['Item Count 5'] = _L.itemcount5,
  1146. ['Item Count 6'] = _L.itemcount6,
  1147. ['Item Count 7'] = _L.itemcount7,
  1148. ['Item Count 8'] = _L.itemcount8,
  1149. ['Item Count 9'] = _L.itemcount9,
  1150. ['Item Index 1'] = _L.itemindex1,
  1151. ['Item Index 2'] = _L.itemindex2,
  1152. ['Item Index 3'] = _L.itemindex3,
  1153. ['Item Index 4'] = _L.itemindex4,
  1154. ['Item Index 5'] = _L.itemindex5,
  1155. ['Item Index 6'] = _L.itemindex6,
  1156. ['Item Index 7'] = _L.itemindex7,
  1157. ['Item Index 8'] = _L.itemindex8,
  1158. ['Item Index 9'] = _L.itemindex9,
  1159. ['Target Index'] = npc.index,
  1160. ['Number of Items'] = _L.quantity,
  1161. })
  1162.  
  1163. packets.inject(p)
  1164.  
  1165. end
  1166.  
  1167. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement