Advertisement
Guest User

inventory.script as mnn requested

a guest
Jan 22nd, 2011
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.02 KB | None | 0 0
  1. belt = {}
  2. belt_id = {}
  3. belt_status = false
  4.  
  5. local need_update = true
  6. local inventory_open = false
  7. local separator_spawned = false
  8. local separator = "separator"
  9.  
  10. local debug = false
  11. local flag
  12.  
  13. function update()
  14.  
  15.     if (need_update == false) then return end
  16.  
  17.     if debug == true and belt_status == true then get_console():execute("belt_status=false") end
  18.     belt_status = false
  19.  
  20.     -- Ñïàâíèì ðàçäåëÿþùèé åëåìåíò
  21.     if (separator_spawned == false) then
  22.         alife():create(separator,
  23.             db.actor:position(),
  24.             db.actor:level_vertex_id(),
  25.             db.actor:game_vertex_id(),
  26.             db.actor:id())
  27.         separator_spawned = true
  28.         if debug == true then get_console():execute("separator_spawned") end
  29.         return
  30.     end
  31.  
  32.     belt = {}
  33.     belt_id = {}
  34.     flag = 0
  35.  
  36.     -- Ñêàíèðóåì èíâåíòàðü
  37.     db.actor:inventory_for_each(scan_inv)
  38.     need_update = false
  39.  
  40.     -- Óäàëÿåì ðàçäåëÿþùèé åëåìåíò
  41.     db.actor:inventory_for_each(del_separator)
  42.     separator_spawned = false
  43.  
  44.     if debug == true and belt_status == false then get_console():execute("belt_status=true") end
  45.     belt_status = true
  46.  
  47.     if debug == true then
  48.         for i,k in pairs(belt) do
  49.             get_console():execute(i.."="..k)
  50.         end
  51.     end
  52. end
  53.  
  54. -- Ïåðåáîð ïðåäìåòîâ èíâåíòàðÿ
  55. function scan_inv(item)
  56.     local section = item:section()
  57.  
  58.     if section == separator then
  59.         flag = 1
  60.         return
  61.     end
  62.  
  63.     if flag == 1 then
  64.         if slot_item(item) ~= nil then
  65.             flag = 2
  66.         else
  67.             insert_to_table(belt, section)
  68.             belt_id[item:id()] = true
  69.         end
  70.     end
  71. end
  72.  
  73. -- Äîáàâëåíèå â òàáëèöó
  74. function insert_to_table(tbl, section)
  75.     if tbl[section] == nil then
  76.         tbl[section] = 1
  77.     else
  78.         tbl[section] = tbl[section] + 1
  79.     end
  80. end
  81.  
  82. -- Óäàëåíèå ðàçäåëÿþùåãî ïðåäìåòà
  83. function del_separator(item)
  84.     if item:section() == separator then
  85.         local sobj = alife():object(item:id())
  86.         if sobj then
  87.             alife():release(sobj, true)
  88.         end
  89.         if debug == true then get_console():execute("separator_removed") end
  90.     end
  91. end
  92.  
  93. -- Îïðåäåëåíèå íàëå÷èÿ ïðåäìåòà â îäíîì èç ñëîòîâ
  94. function slot_item(item)
  95.     for i=0,12 do
  96.         local obj = db.actor:item_in_slot(i)
  97.         if obj and item:id() == obj:id() then
  98.             return i
  99.         end
  100.     end
  101.  
  102.     return nil
  103. end
  104.  
  105. -- Ïîäíÿòèå ïðåäìåòà
  106. function on_item_take(item)
  107.     if item:section() == separator then return end
  108.  
  109.     if (inventory_open == false) then
  110.         if (separator_spawned == true) then
  111.             db.actor:inventory_for_each(del_separator)
  112.             separator_spawned = false
  113.         end
  114.  
  115.         need_update = true
  116.         if debug == true then get_console():execute("item_take") end
  117.     end
  118. end
  119.  
  120. -- Âûáðîñ ïðåäìåòà
  121. function on_item_drop(item)
  122.     if item:section() == separator then return end
  123.  
  124.     if (inventory_open == false) then
  125.         if (separator_spawned == true) then
  126.             db.actor:inventory_for_each(del_separator)
  127.             separator_spawned = false
  128.         end
  129.  
  130.         need_update = true
  131.         if debug == true then get_console():execute("item_drop") end
  132.     end
  133. end
  134.  
  135. -- Îòêðûòèå/çàêðûòèå èíâåíòàðÿ
  136. function on_inventory_info(info_id)
  137.     if info_id == "ui_inventory" then
  138.         inventory_open = true
  139.         if debug == true then get_console():execute("inventory_open") end
  140.  
  141.     elseif info_id == "ui_inventory_hide" then
  142.         inventory_open = false
  143.         need_update = true
  144.         if debug == true then get_console():execute("inventory_close") end
  145.     end
  146. end
  147.  
  148. function check_blood()
  149. --   if belt_status == true then
  150.       if belt["af_blood"]~=nil and belt["af_blood"]>0 then -- òî åñòü êîãäà ïàðàìåòð ïîÿñà[af_blood] ðàâåí 1, 2, 3.. Ñêîëüêî íàâåñèøü Êàìíåé.
  151.              amk.send_tip("Êðîâü Êàìíÿ íà ïîÿñå")
  152.           end
  153. --   end
  154. end
  155.  
  156. function check_backpack()
  157.   if belt["backpack"]~=nil and belt["backpack"]>0 then
  158.     return true
  159.   else
  160.     return false
  161.   end
  162. end
  163.  
  164. function check_backpackempty()
  165.   if belt["backpack"]==nil then
  166.     return true
  167.   else
  168.     return false
  169.   end
  170. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement