Перейти к содержанию

Рекомендуемые сообщения

 
 

vader_33 10 разных


76561198152189716.png

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

Как то так для 10 одинаковых

for i=1, 10 do
if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
end

 


Дополнено 3 минуты спустя

Если для разных  то в цикл надо ещё добавить

local sobj = alife():object( rnd ) 


Дополнено 4 минуты спустя

local rnd = tbl[ math.random( table.getn( tbl ) ) ]

Изменено пользователем Alex Kireev

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

Alex Kireev типо вот так?

Спойлер

function remove_random_item()
  local important_objects = {  -- Здесь предметы, которые нельзя удалять
    [ "bolt"       ] = true,
    [ "device_pda" ] = true,
  }
  local tbl = {}
  local cnt = 0
  db.actor:iterate_inventory(
    function( dummy, obj )
      if obj and not important_objects[ obj:section() ] then
        cnt = cnt + 1
        table.insert( tbl, obj:id() )
      end
    end
  )
  if cnt == 0 then return end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
end

 

Если да, то пробовал. И вот так делал:

Спойлер

function remove_random_item()
  local important_objects = {  -- Здесь предметы, которые нельзя удалять
    [ "bolt"       ] = true,
    [ "device_pda" ] = true,
  }
  local tbl = {}
  local cnt = 0
  db.actor:iterate_inventory(
    function( dummy, obj )
      if obj and not important_objects[ obj:section() ] then
        cnt = cnt + 1
        table.insert( tbl, obj:id() )
      end
    end
  )
  if cnt < 10 then return end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
end

 

И, да, это работает, но как-то странно. Почему-то удаляются не по 10 предметов, а скорее по 8-9, а то и по 6... При этом там стоит проверка на аборт функции, если предметов в инвентаре меньше 10, и эта проверка работает и действительно не дает скрипту произойти в случае недобора предметов в инвентаре, но в это же время положи ты 10 предметов в инвентарь и скрипт не заберет их все. Я не знаю, может на один и тот же предмет падает два раза удаление или что-то вроде того.


76561198152189716.png

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

То есть как то так

for i=1, 10 do
local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
end

 

  • Хабар 1

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

Alex Kireev такого еще точно не было. Буду пробовать.


76561198152189716.png

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 
10 минут назад, ian98 сказал:

типо вот так?

Да, только через цикл удобней и быстрее, мой последний пример аналогичен этому

function remove_random_item()
  local important_objects = {  -- Здесь предметы, которые нельзя удалять
    [ "bolt"       ] = true,
    [ "device_pda" ] = true,
  }
  local tbl = {}
  local cnt = 0
  db.actor:iterate_inventory(
    function( dummy, obj )
      if obj and not important_objects[ obj:section() ] then
        cnt = cnt + 1
        table.insert( tbl, obj:id() )
      end
    end
  )
  if cnt < 10 then return end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
end

Скрипту, но только я сделал с использованием цикла, так короче 


Дополнено 3 минуты спустя

И ещё функция рандом может генерировать подряд несколько одинаковых чисел 

То есть 1, 1, 1, 2, 8, 7, 3, 3, 3, 3, 5, 5, 4

6 минут назад, ian98 сказал:

Буду пробовать

Если будет не 10 предметов удаляться, а 9 то в строке 

for i=1, 10 do

 Измени 10 на 11

Изменено пользователем Alex Kireev

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

что-то вообще перестало работать, если так:

Спойлер

function remove_random_common_final(npc, npz)
  local important_objects = {  -- Здесь предметы, которые нельзя удалять
    [ "bolt"       ] = true,
    [ "device_pda" ] = true
  }
  local tbl = {}
  local cnt = 0
  db.actor:iterate_inventory(
    function( dummy, obj )
      if obj and not important_objects[ obj:section() ] then
        cnt = cnt + 1
        table.insert( tbl, obj:id() )
      end
    end
  )
  if cnt < 10 then return end
  for i=1, 10 do
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
end

 

 


76561198152189716.png

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

ian98 как-то так. Наверняка можно сделать проще, но ночью меня на большее не хватило ?


 

Спойлер



function remove_random_item()
  local important_objects = {  -- Здесь предметы, которые нельзя удалять
    [ "bolt"       ] = true,
    [ "device_pda" ] = true,
  }
  local tbl = {}
	  db.actor:iterate_inventory(
		function( dummy, obj )
		  if obj and not important_objects[ obj:section() ] then
			table.insert( tbl, obj:id() )
		  end
		end
	  )
	if table.getn(tbl) >= 10 then
		local rnd_tbl = random_10_items(tbl)
			for i, v in pairs(rnd_tbl) do
				local sobj = alife():object( v )
					if sobj then
						news_manager.relocate_item( db.actor, "out", sobj:section_name() )
						alife():release( sobj, true )
					end
			end
	end
end

function random_10_items(tbl)
	local t = {}
	
	local function rnd()
		local num = math.random(#tbl)
			if t[num] then  
				num = rnd(tbl)
			end
				return num
	end
	
	while table.getn(t) <= 9 do
		local num2 = rnd()
		table.insert(t, tbl[num2] )
	end
		return t
end


 

 

  • Печаль 1

В беге за рассветом приближаешь свой закат

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

ian98 это зачем?

if cnt < 10 then return end


Дополнено 2 минуты спустя
function remove_random_common_final(npc, npz)
  local important_objects = {  -- Здесь предметы, которые нельзя удалять
    [ "bolt"       ] = true,
    [ "device_pda" ] = true
  }
  local tbl = {}
  local cnt = 0
  db.actor:iterate_inventory(
    function( dummy, obj )
      if obj and not important_objects[ obj:section() ] then
        cnt = cnt + 1
        table.insert( tbl, obj:id() )
      end
    end
  )
  if cnt == 0 then return end
  for i=1, 10 do
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
end

 


Дополнено 3 минуты спустя

Вот так попробуй


Дополнено 5 минуты спустя
function remove_random_common_final(npc, npz)
  local important_objects = {  -- Здесь предметы, которые нельзя удалять
    [ "bolt"       ] = true,
    [ "device_pda" ] = true
  }
  local tbl = {}
  local cnt = 0
  db.actor:iterate_inventory(
    function( dummy, obj )
      if obj and not important_objects[ obj:section() ] then
        cnt = cnt + 1
        table.insert( tbl, obj:id() )
      end
    end
  )
  if cnt == 0 then return end
  else
  for i=1, 10 do
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
end
end

Или так

  • Печаль 1

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

vader_33 Работает, но тоже нестабильно, может с багом, как и это:

Спойлер

function remove_random_item()
  local important_objects = {  -- Здесь предметы, которые нельзя удалять
    [ "bolt"       ] = true,
    [ "device_pda" ] = true,
  }
  local tbl = {}
  local cnt = 0
  db.actor:iterate_inventory(
    function( dummy, obj )
      if obj and not important_objects[ obj:section() ] then
        cnt = cnt + 1
        table.insert( tbl, obj:id() )
      end
    end
  )
  if cnt < 10 then return end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
end

 

В общем, 10 предметов не забирает. Тестил раз 5 и максимум потерял 8 предметов, минимум было 5. При этом в инвентаре 10 предметов.


Дополнено 0 минут спустя

Alex Kireev Ничего. Что-то не так(


Дополнено 2 минуты спустя

vader_33 Не, ну вообще круто завернул. Теперь скрипт стал для меня еще непонятнее, чем был)


76561198152189716.png

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

ian98 нужно удалить 10 разных предметов, включая и оружие и боеприпасы?

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

Alex Kireev да, удалить 10 предметов, что в инвентаре и не в таблице важных предметов

Изменено пользователем ian98

76561198152189716.png

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

И этот скрипт работает?

function remove_random_item()
  local important_objects = {  -- Здесь предметы, которые нельзя удалять
    [ "bolt"       ] = true,
    [ "device_pda" ] = true,
  }
  local tbl = {}
  local cnt = 0
  db.actor:iterate_inventory(
    function( dummy, obj )
      if obj and not important_objects[ obj:section() ] then
        cnt = cnt + 1
        table.insert( tbl, obj:id() )
      end
    end
  )
  if cnt == 0 then return end
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
  end
end

 

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

Alex Kireev С виду он удаляет один предмет, но попробую гляну. Да, он удаляет 1 случайный предмет) Это походу оригинал скрипта. Я уже запутался

Изменено пользователем ian98

76561198152189716.png

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 
Спойлер

function remove_random_common_final(npc, npz)
  local important_objects = {  -- Здесь предметы, которые нельзя удалять
    [ "bolt"       ] = true,
    [ "device_pda" ] = true
  }
  local tbl = {}
  local cnt = 0
  db.actor:iterate_inventory(
    function( dummy, obj )
      if obj and not important_objects[ obj:section() ] then
        cnt = cnt + 1
        table.insert( tbl, obj:id() )
      end
    end
  )
  if cnt == 0 then return end
if table.geth(tbl) >= 10 then
  for i=1, 10 do
  local rnd  = tbl[ math.random( table.getn( tbl ) ) ]
  local sobj = alife():object( rnd )
  if sobj then
    news_manager.relocate_item( db.actor, "out", sobj:section_name() )
    alife():release( sobj, true )
end
  end
end

 

Если не заработает, то тогда до завтра, что бы сам мог посмотреть что и как 

  • Печаль 1

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

Alex Kireev Ну что ж, до завтра. Может завтра все случится, а может и нет. Кто его знает... Но я и сам целый день сегодня мудохался, пыхтел и все в одно место. Еще много веселых моментов с death_managerом. Я там оружие удалить при смерти непеся без багов не могу. Никак.


76561198152189716.png

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

ian98 давай, счастливо и ещё , а как скрипт вызываешь? 

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

Alex Kireev в общем, из таблички еще надо удалять, после удаления предмета его ид из нее никуда не девается, и при выпадении его с рандома sobj не будет. Ну точно ночью спать надо, а не тут сидеть)
 

Спойлер



function remove_random_item()
  local important_objects = {  -- Здесь предметы, которые нельзя удалять
    ["bolt"] = true,
    ["device_pda"] = true,
	["device_torch"] = true,
	["wpn_binoc"] = true,
	["detector_simple"] = true
  }
  local tbl = {}
	  db.actor:iterate_inventory(
		function( dummy, obj )
		  if obj and not important_objects[ obj:section() ] then
			table.insert( tbl, obj:id() )
		  end
		end
	  )
	if table.getn(tbl) >= 10 then
		for i=1,10 do
			local rnd = math.random(1,#tbl)
			local sobj = alife():object(tbl[rnd])
				if sobj then
					news_manager.relocate_item( db.actor, "out", sobj:section_name() )
					alife():release( sobj, true )
					table.remove(tbl, rnd)
				end
		end
	end
end


 

 

  • Мастер! 1

В беге за рассветом приближаешь свой закат

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

Alex Kireev через диалоги


Дополнено 3 минуты спустя

vader_33 Неужели оно? РАБОТАЕТ. 2 раза уже протестил. Радости полные штаны. Спасибо!

  • Смех 1

76561198152189716.png

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

vader_33 а, ну я почти правильно сделал

3 часа назад, vader_33 сказал:

Ну точно ночью спать надо, а не тут сидеть

Авха, эт точно

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

Всё-таки не справляюсь. Хочу удалять некоторое оружие у нпс после их смерти. Реализовал через death_manager. Через эту функцию:

Спойлер

--' Функция вызывается для каждого предмета, если вернет false то предмет удалится.
function keep_item(npc, item)
    local section = item:section()

    if section == "bolt" then
       return false
    end

    if always_keep_item[section] == true then
        return true
    end

    if section == "wpn_gauss" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_fn2000" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_rpg7" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_vintorez" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_val" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_svu" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_svd" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_groza" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_g36" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_desert_eagle" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_wincheaster1300" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_usp" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_sig550" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_spas12" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_sig220" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_l85" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_lr300" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_abakan" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_ak74" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_colt1911" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_walther" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_mp5" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_hpsa" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_ak74u" then
       alife():release(alife():object(item:id()), true)
    end

    if section == "wpn_beretta" then
       alife():release(alife():object(item:id()), true)
    end

    local item_id = item:id()
    local item_in_slot = npc:item_in_slot(1)
    if item_in_slot ~= nil and
       item_in_slot:id() == item_id
    then
        item:unload_magazine()
    --' Тут надо уменьшить кондишн оружия
        item:set_condition(math.min((math.random(99)+1)/100,item:condition()))
        return true
    end
    item_in_slot = npc:item_in_slot(2)
    if item_in_slot ~= nil and
       item_in_slot:id() == item_id
    then
        item:unload_magazine()
    --' Тут надо уменьшить кондишн оружия
        item:set_condition(math.min((math.random(99)+1)/100,item:condition()))
        return true
    end
    -- сохранить оружие, возвращаемое из ящика
    if wm_slot_1_id == item_id or wm_slot_2_id == item_id then
        --' Тут надо уменьшить кондишн оружия
        item:set_condition(math.min((math.random(99)+1)/100,item:condition()))
        return true
    end
    -- нельзя удалять активный предмет
    if item_id == active_item_id then
        --' Тут надо уменьшить кондишн оружия
        if npc:active_slot() ~= 3 then    -- кроме гранат
            item:set_condition(math.min((math.random(99)+1)/100,item:condition()))
        end
        return true
    end
    alife():release(alife():object(item:id()), true)
end

И вроде бы работает, но только довольно часто может произойти вылет

Спойлер

Expression    : assertion failed
Function      : xrServer::Process_event_reject
File          : .\xrServer_process_event_reject.cpp
Line          : 12
Description   : e_parent && e_entity

 

после которого оружие не только не удаляется, но в инвентарях нпс появляются предметы, которых быть не должно: пда, гармошки и прочее. Да и без вылета легко может случится тоже самое: непись роняет оружие, которое должно бы было удалится, а в его инвентаре просто тонна предметов, которые актор не должен был бы видеть.  Может я удаляю как-то не так. Пробовал еще удалять абсолютно любое оружие, такой вариант тоже устраивает, таким образом:

If isWeapon(item) then

       alife():release(alife():object(item:id()), true)
    end

Но там вылет сразу. Игра такое не пытается даже скушать.

Кажись это бы так должно бы выглядеть. По крайней мере, это лучший мой результат

 
Дополнено 12 минуты спустя
Спойлер

function keep_item(npc, item)
    local section = item:section()

    if section == "bolt" then
       return false
    end

    if always_keep_item[section] == true then
        return true
    end

    local item_id = item:id()
    local item_in_slot = npc:item_in_slot(1)
    if item_in_slot ~= nil and
       item_in_slot:id() == item_id
    then
        alife():release(alife():object(item:id()), true)
        return true
    end
    item_in_slot = npc:item_in_slot(2)
    if item_in_slot ~= nil and
       item_in_slot:id() == item_id
    then
	alife():release(alife():object(item:id()), true)
        return true
    end

 

но все равно все удаляется через раз, вылетает и все самое худшее... Че так сложно? В ЗП работало на ура.

Не удаляются некоторые стволы, например гроза, видимо они у нпс в каком-то другом слоте находятся.

Изменено пользователем ian98

76561198152189716.png

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
   

Alex Kireev не, надо, чтобы из рук удалялось при смерти нпс, а не падало на землю. И в принципе я сделал, удаляются все пушки. Правда вылеты случаются безобидные, но бесячие. Вот бы их убрать теперь.

Изменено пользователем ian98

76561198152189716.png

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 
4 часа назад, ian98 сказал:

If isWeapon(item) then

       alife():release(alife():object(item:id()), true)
    end

Попробуй так:

If isWeapon(item) then

local s_obj = item and  item:id() and alife():object( item:id() )

if s_obj then

alife():release( s_obj ,  true )

end

 end


Терпение... И все получится.

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты
 

makdm уже разобрался сделал так:

Спойлер

    local item_id = item:id()
    local item_in_slot = npc:item_in_slot(1)
    if item_in_slot ~= nil and
       item_in_slot:id() == item_id
    then
        alife():release(alife():object(item:id()), true)
        return true
    end
    item_in_slot = npc:item_in_slot(2)
    if item_in_slot ~= nil and
       item_in_slot:id() == item_id
    then
	alife():release(alife():object(item:id()), true)
        return true
    end

 

Правда случаются вылеты

Спойлер

Expression : assertion failed Function : xrServer::Process_event_reject File : .\xrServer_process_event_reject.cpp Line : 12 Description : e_parent && e_entity

Если я сделаю, как ты описал, как думаешь, вылеты эти исчезнут? 


Дополнено 18 минуты спустя

makdm вылетаю. И со своим вариантом отлетаю, меня крашит бесконечно. Что за жесть


Дополнено 6 минуты спустя

А можно ли удалять предметы в death_manager через клсиды? Там походу проблема в том, что оружие в руках нпц меняется каждый раз когда я перезагружаю игру и автор скрипта мне говорил что-то о том, что через айди в таком случае предметы не убрать. Видно я поэтому и вылетаю.

Блин, походу через клсиды в случае дропа предмета удалятся все предметы у всех вокруг. Я щас волка убил и его автомат исчез, вместе с автоматами всех остальных новичков в деревне. И они, став мне врагами, разбежались в страхе. Хотя, может сделал чет не так.

Изменено пользователем ian98

76561198152189716.png

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты

Для публикации сообщений создайте учётную запись или авторизуйтесь

Вы должны быть пользователем, чтобы оставить комментарий

Создать учетную запись

Зарегистрируйте новую учётную запись в нашем сообществе. Это очень просто!

Регистрация нового пользователя

Войти

Уже есть аккаунт? Войти в систему.

Войти

  • Последние посетители   0 пользователей онлайн

    Ни одного зарегистрированного пользователя не просматривает данную страницу