--[[ ==========   Спавн-функции для квестов   ===========
     Использована функция erlik'a для универсального спавна всего и вся.
--]]


-------------------------------------------------------------
local count = 0 
function SpawnToNpcOrToLocation(tab_items,tab_where)
local pos, lvid, gvid, id, obj
   local function Compare(id)
     obj = alife():object(id)
      if obj==nil then return false end 
      if obj.profile_name then
           if  obj:profile_name() == tab_where then
   return true
   else 
                          return false 
   end
                else 
             return false
      end
end

    for k, v in pairs(tab_items) do
        if type(tab_where)=='table' then
            for k, v in pairs (tab_items[k]) do 
            count = k
                for i=1, count do
                 alife():create(v,vector():set(tab_where['x'],
                  tab_where['y'],tab_where['z']),
                   tab_where['lv'],tab_where['gv'])
                end
            end
        elseif type(tab_where)=='string' then
    if tab_where =="actor" then 
        obj = alife():actor()
        else
        for i=1, 65534 do
            local predicate = Compare(i)
            if predicate then
            break
        end 
  end 
    end
            if obj == nil then return end
for k, v in pairs (tab_items[k]) do 
            count = k
                 for i=1, count do
                 alife():create(v, obj.position, obj.m_level_vertex_id, obj.m_game_vertex_id, obj.id)
  end
            end
        elseif type(tab_where)=='number' then 
        obj = level_object_by_sid(tab_where)
            if obj ~= nil then
             id = obj:id()
              pos = obj:position()
               lvid = obj:level_vertex_id()
                 gvid = obj:game_vertex_id()
            elseif obj == nil then
             obj = alife():story_object(tab_where)
             id = obj.id
              pos = obj.position
               lvid = obj.m_level_vertex_id
                gvid = obj.m_game_vertex_id
                for k, v in pairs (tab_items[k]) do 
                    count = k
                   for i=1, count do
                   alife():create(v, pos, lvid, gvid, id)
                   end
               end
            end
        end
    end
end
-------------------------------------------------------------
--/Спавн 4 документов для Ирбиса
function spawn_doc_7_doc_8()
	amk.spawn_item("doc_7",vector():set(16.5073776245117,1.17426681518555,-11.5088882446289), 7044, 3216)
end

--/Спавн 4 документов для Ирбиса_2
function spawn_doc_5_doc_6()
	amk.spawn_item("doc_5",vector():set(-100.613,22.58,-25.442), 503, 1529)
end

--/Спавн рюкзака новичка
function spawn_rukz_novichka()
  local tab_items ={{[1]="inv_ruck"}}
  local tab_where ={x = -126.6884765625,y = -29.4200000762939,z = -388.704040527344,lv = 594270,gv = 0}
     this.SpawnToNpcOrToLocation(tab_items,tab_where)
end

--/Спавн doc_9
function spawn_doc_9()
  local tab_items ={{[1]="doc_9"}}
  local tab_where ={x = 313.68,y = 35.62,z = -234.70,lv = 594270,gv = 0}
     this.SpawnToNpcOrToLocation(tab_items,tab_where)
end


function spawn_bro ()
alife():create("upi_bro", vector():set(-395.10,12.32,10.688),51661,3708)
end

--/Спан флешки в Бандоса
function spawn_docs_in_gar_lid()
  local tab_items ={
  {[1]="fleshcard"}
  }
  local tab_where = "gar_lid"     -- имя из профиля 
     this.SpawnToNpcOrToLocation(tab_items,tab_where)
end




function spawn_bandits ()
    alife():create("gar_general_default3_1", vector():set(36.10,0.48,-305.688),209876,253)
	alife():create("gar_general_default3_2", vector():set(36.10,0.48,-305.688),209876,253)
	alife():create("gar_general_default3_3", vector():set(36.10,0.48,-305.688),209876,253)
	alife():create("gar_general_default3_4", vector():set(36.10,0.48,-305.688),209876,253)
	alife():create("gar_general_default3_5", vector():set(36.10,0.48,-305.688),209876,253)
	alife():create("gar_general_default3_6", vector():set(36.10,0.48,-305.688),209876,253)
	alife():create("gar_lid", vector():set(36.10,0.48,-305.688),209876,253)
end
