Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.55 KB | None | 0 0
  1. -------------- конечное количество болтов -------------
  2. ------------------ реализация Charsi ------------------
  3. -------------- идейный вдохновитель Z.I.R.D.-----------
  4. ------------------ 17/08 - 13/12 2010 -----------------
  5. ----------------- last edit 23/12/2010 ----------------
  6. -- версия 1.01
  7. -- добавлен уборщик бесхозных болтов
  8. -- исправлен баг при загрузке
  9. -- добавлено взятие в слот при подборе с болта земли,если болта не было в слоте
  10. -------------------------------------- можно настроить
  11. local max_cnt_bolt = 10 -- кол-во бесхозных болтов в игре
  12.  
  13. -------------------------------------- не трогать
  14. local bolt_cnt=0    --количество болтов в рюкзаке
  15. local throwed_bolt_id,bolt_in_hands_id,st,box_id
  16. local f=true        -- флаг того, что убрали болт из слота
  17. local show_f=true
  18. local f2=true       -- флаг того,что надо поставить болт в слот
  19.  
  20. new_bolt_id = {}
  21.  
  22. function on_item_take(obj)
  23.     if obj:section()=="fake_bolt" then
  24.        bolt_cnt=bolt_cnt+1
  25.        local bolt=db.actor:object("bolt")
  26.        if bolt~=nil and db.actor:item_in_slot(5)==nil and f2 then
  27.         db.actor:transfer_item(bolt,db.actor) remove_item(obj) f2=false
  28.        end
  29.     end
  30.     if obj:section()=="bolt" and bolt_cnt>0 and f2 then
  31.         db.actor:transfer_item(bolt,db.actor) f2=false
  32.     end
  33. end
  34.  
  35. function on_item_drop(obj)
  36.     if obj:section()=="fake_bolt" then
  37.         bolt_cnt=bolt_cnt-1
  38.     end
  39. end
  40.  
  41. function on_actor_use(obj)
  42.     if obj:section()=="fake_bolt" and has_alife_info("ui_inventory") then
  43.         local bolt=db.actor:item_in_slot(5)
  44.         if bolt then
  45.             spawn_item_in_inv("fake_bolt")
  46.         else
  47.             db.actor:transfer_item(db.actor:object("bolt"),db.actor)
  48.         end
  49.     end
  50. end
  51.  
  52. function update()
  53.  
  54.   if new_bolt_id[1] and f then
  55.     f=false table.remove(new_bolt_id,1) return -- взяли болт в инвентарь
  56.   end
  57.  
  58.   if db.actor:active_slot()==5 then
  59.     if level.main_input_receiver()==nil then show_static() else remove_static() end
  60.     if new_bolt_id[1] then
  61.  
  62.         if bolt_in_hands_id then    -- болт2 висит в инвизе над ГГ
  63.             throwed_bolt_id = bolt_in_hands_id
  64.             bolt_binder.drop_bolt[throwed_bolt_id]=true
  65.             if not remove_item(db.actor:object("fake_bolt")) then bolt_cnt=bolt_cnt-1 del_bolt() end
  66.         end
  67.    
  68.         bolt_in_hands_id=new_bolt_id[1]
  69.         if f then bolt_in_hands_id=nil end
  70.  
  71.         table.remove(new_bolt_id,1)
  72.     end
  73.   else
  74.     remove_static()
  75.   end
  76.  
  77. end
  78.  
  79. function remove_static()
  80.     if st then get_hud():RemoveDialogToRender(st) st=nil end
  81. end
  82.  
  83. function show_static()
  84. if st then
  85.     st:SetText(bolt_cnt)
  86. else
  87.     bolt_cnt=0
  88.     db.actor:iterate_inventory(function(dummy,item) if item:section()=="fake_bolt" then bolt_cnt=bolt_cnt+1 end end,dummy)
  89.     if db.actor:item_in_slot(5) then bolt_cnt=bolt_cnt+1 end
  90.  
  91.     st=CUIStatic()
  92.     st:Init(1024-160,768-65,110,50) -- координаты где рисовать
  93.  
  94.     st:SetFont(GetFontGraffiti32Russian())
  95.     st:SetTextAlign(CGameFont.alRight)
  96.     st:SetTextColor (255,238,155,23)
  97.     st:SetTextY(15) -- выравнивание по вертикали ,-1 по центру
  98.  
  99.     local ini=system_ini() local sect="fake_bolt"
  100.     local x=ini:r_u32(sect, "inv_grid_x")*50
  101.     local y=ini:r_u32(sect, "inv_grid_y")*50
  102.     local width=ini:r_u32(sect, "inv_grid_width")*50
  103.     local height=ini:r_u32(sect, "inv_grid_height")*50
  104.     st:InitTexture("ui\\ui_icon_equipment")
  105.     st:SetOriginalRect(x,y,width,height)
  106.     --st:Show(true)
  107.     get_hud():AddDialogToRender(st)
  108. end
  109. end
  110.  
  111. function on_info(info_id)
  112.     if info_id == "ui_car_body" or info_id == "ui_trade" then
  113.         if db.actor:item_in_slot(5) then
  114.             del_bolt()
  115.             spawn_item_in_inv("fake_bolt")
  116.         end    
  117.     elseif  info_id == "ui_car_body_hide" or info_id == "ui_trade_hide" then
  118.         local obj = db.actor:object("fake_bolt")
  119.         if obj then remove_item(obj) db.actor:transfer_item(db.actor:object("bolt"),db.actor)  end
  120.     end
  121. end
  122.  
  123. function del_bolt()
  124.     -- спавним болт чтоб не было битья сейва
  125.     local npc=db.actor
  126.     alife():create("bolt", npc:position(),npc:level_vertex_id(),npc:game_vertex_id(), 0)
  127.     f=true f2=true
  128.     bolt_in_hands_id=nil
  129.     db.actor:transfer_item(db.actor:item_in_slot(5),level.object_by_id(box_id))
  130. end
  131.  
  132. function net_spawn()
  133.     local sobj local string_sub=string.sub
  134.     local sim=alife()
  135.     local cnt=0
  136.     for i=1,65534 do    -- удаляем лишние бесхозные болты
  137.         sobj=sim:object(i)
  138.         if sobj then
  139.             if string_sub(sobj:name(),1,9)=="fake_bolt" and sobj.parent_id==65535 then
  140.                 if cnt < max_cnt_bolt then cnt=cnt+1 else sim:release(sobj,true) end
  141.             end
  142.         end
  143.     end
  144.     sobj=sim:object("invis_rukzak_bolt")
  145.     if sobj then sim:release(sobj,true) end
  146.     sobj= sim:create("invis_rukzak_bolt",db.actor:position(), db.actor:level_vertex_id(), db.actor:game_vertex_id())
  147.     box_id=sobj.id
  148.     level.client_spawn_manager():add(sobj.id, 0, OnSpawnInvizRukzak,0)
  149. end
  150.  
  151. function net_destroy()
  152.     remove_static()
  153. end
  154.  
  155. function OnSpawnInvizRukzak(arg, iId, gObj)
  156.     alife():set_switch_online  (box_id, true)
  157.     alife():set_switch_offline (box_id, false)
  158.     gObj:set_tip_text("")
  159.     gObj:set_nonscript_usable(false)
  160. end
  161.  
  162. function remove_item(item)
  163. if item then
  164.     local sobj=alife():object(item:id())
  165.     if sobj then alife():release(sobj,true) end
  166.     return true
  167. end
  168. return false
  169. end
  170.  
  171. function spawn_item_in_inv( sect )
  172.     alife():create(sect,db.actor:position(),db.actor:level_vertex_id(),db.actor:game_vertex_id(),0)
  173. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement