Advertisement
ppgab

Untitled

Jul 16th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.42 KB | None | 0 0
  1. local Manual = false -- True if you will config the file manually;
  2. local Mode = "vertical" -- 'horizontal' will output plain function, 'vertical' will make a new line for each item and add a comment with the item name
  3. local fileName = "fileName.xbst" -- Name of file to gather loot list from;
  4. local itemsToIgnore = {} -- Put here the id of the items to ignore separated by;
  5. local stackableIndex = 0 -- Index of deposit bp to put stackables;
  6. local nonStackableIndex = 1 -- Same but for non stackables.
  7. local outputName = "fileName.lua"
  8. local talkstate = "fileName"
  9.  
  10. function Receive(log, msg)
  11.     log:SendYellowMessage(Self.Name().." ["..Self.Level().."] ", msg)
  12.     if talkstate == "fileName" then
  13.         if msg:find(".xbst") then
  14.             fileName = msg
  15.             talkstate = "lua"
  16.             log:SendOrangeMessage("Xenobot ", "Type the name you want for the lua file")
  17.         else
  18.             log:SendOrangeMessage('Xenobot ', "That's not a valid file format, example : FileName.xbst")
  19.         end
  20.     elseif talkstate == 'lua' then
  21.         if msg:find('.lua') then
  22.             outputName = msg
  23.             talkstate = 'stackable'
  24.             log:SendOrangeMessage("Xenobot ", "Type the Depot BP Index number for stackable items")
  25.         else
  26.             log:SendOrangeMessage('Xenobot ', "That's not a valid file format, example : FileName.lua")
  27.         end
  28.     elseif talkstate == 'stackable' then
  29.         if tonumber(msg) then
  30.             stackableIndex = msg
  31.             talkstate = 'non'
  32.             log:SendOrangeMessage("Xenobot ", "Type the Depot BP Index number for non-stackable items")
  33.         else
  34.             log:SendOrangeMessage("Xenobot ", "That's not a number, try again")
  35.         end
  36.     elseif talkstate == 'non' then
  37.         if tonumber(msg) then
  38.             nonStackableIndex = msg
  39.             talkstate = 'final'
  40.             log:SendOrangeMessage("Xenobot ", "List created, copy from below or in '"..outputName.."' on 'Scripts' folder")
  41.             OutPut()
  42.         else
  43.             log:SendOrangeMessage("Xenobot ", "That's not a number, try again")
  44.         end
  45.     end
  46. end
  47.  
  48. function Close()
  49. end
  50.  
  51. Scripter = Channel.New("Setup", Receive, Close)
  52. Scripter:SendOrangeMessage("Xenobot ", "Type the name of the file with .xbst in the end where the Loot list is")
  53.  
  54. function OutPut()
  55.     local GatherIDS
  56.     local GatherLabels
  57.     local foundIDS = {}
  58.     local foundLabels = {}
  59.  
  60.     for lines in io.lines("..//Settings//"..fileName) do
  61.         if lines:find('<control name="LootList"') then
  62.             GatherIDS = true
  63.         elseif lines:find('<control name="WaypointList">') then
  64.             GatherLabels = true
  65.         end
  66.         if GatherIDS then
  67.             if lines:find('</control>') then
  68.                 GatherIDS = false
  69.             else
  70.                 ID = lines:match('<item ID="(%d+)"')
  71.                 if ID then
  72.                     table.insert(foundIDS, ID)
  73.                 end
  74.             end
  75.         elseif GatherLabels then
  76.             if lines:find('</control>') then
  77.                 GatherLabels = false
  78.             else
  79.                 Label = lines:match('<item text="(.+):" tag="255"/>')
  80.                 if Label then
  81.                     table.insert(foundLabels, Label)
  82.                 end
  83.             end
  84.         end
  85.     end
  86.  
  87.     if itemsToIgnore then
  88.         for i = 1, #foundIDS do
  89.             local er = table.fastfind(foundIDS[i], itemsToIgnore)
  90.             if er then
  91.                 table.remove(i, foundIDS)
  92.             end
  93.         end
  94.     end
  95.      
  96.     str = "Self.DepositItems("
  97.  
  98.     local ind
  99.  
  100.     if foundIDS then
  101.         local len = #foundIDS
  102.         for i = 1, len do
  103.             local item = foundIDS[i]
  104.             if Mode == "vertical" then
  105.                 nl = '\n'
  106.                 comment = ' -- '..Item.GetName(item):titlecase()
  107.             else
  108.                 nl = ""
  109.                 comment = ""
  110.             end
  111.             if Item.isStackable(item) then
  112.                 ind = stackableIndex
  113.             else
  114.                 ind = nonStackableIndex
  115.             end
  116.             if i == len then
  117.                 str = str..nl..'{'..item..','..ind..'})'..comment
  118.             else
  119.                 str = str..nl..'{'..item..','..ind..'},'..comment
  120.             end
  121.         end
  122.     end
  123.  
  124.     if foundLabels then
  125.         lstr = '\nfunction onWalkerSelectLabel(label)'
  126.         local len = #foundLabels
  127.         for i = 1, len do
  128.             if i == 1 then
  129.                 lstr = lstr..'\n    if label = "'..foundLabels[i]..'" then \n        --code'
  130.             else
  131.                 lstr = lstr..'\n    elseif label = "'..foundLabels[i]..'" then \n        --code'
  132.             end
  133.         end
  134.         lstr = lstr..'\nend\nregisterEventListener(WALKER_SELECTLABEL, "onWalkerSelectLabel")'
  135.     end
  136.  
  137.     fstr = '--[[\n'..str..'\n]]\n\n'..lstr
  138.  
  139.     Scripter:SendOrangeMessage("Copy", str)
  140.          
  141.     file = io.open("..//Scripts//"..outputName,"w+")
  142.  
  143.     file:write(fstr)
  144.     file:flush()
  145.     file:close()
  146.     wait(1000)
  147.  
  148.     os.execute('start C:'..os.getenv('HOMEPATH')..'\\Documents\\XenoBot\\Scripts\\'..outputName)
  149. end
  150.  
  151. function table.fastfind(value, table)
  152.     local data = table
  153.     for i = 1, #data do
  154.         if value == data[i] then
  155.             return value
  156.         end
  157.     end
  158.     return false
  159. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement