Page 1 of 1

Spawn Manager

Posted: 06 Jul 2012, 13:50
by olaf1
Hey Alundaio hier you can answere or other when they have an idea.

I will make in the spawn manager from Alundaio that the NPC´s only spawn when in a spazil space restrictor nothing or NPC´s from the same faktion they can only spawn.

But it don´t work??
Hier is my spawn_manager.script

Code: Select all

-- storage for spawned objects
local Objects = {}

-- Spawner Table and Index
local SpawnerIndex = {}
local Spawner = {}

local ini = ini_file("spawn_manager\\spawn_manager.ltx")
local initialized = false
function init()
   local SpawnerSections = collect_sections(ini,{"sections"})

   for k,v in pairs(SpawnerSections) do
      table.insert(SpawnerIndex,k)
      -- Create a spawn manager for each section
      Spawner[k] = SpawnManager(k)
   end

   initialized = true
end

---------------------------------------------------
-- class SpawnManager
---------------------------------------------------
class "SpawnManager"
function SpawnManager:__init(section)
   self.section = section
   self.loaded = false
end

function SpawnManager:initialize()
   local section = self.section
   -- Inherit data from ini
   self.sections =    str_explode(read_from_ini(   ini,    section, "sections",       "string",    "stalker"), ","      )
   self.respawn =                read_from_ini(   ini,    section, "respawn",       "string",    "true"            )
   self.respawn_delta = str_explode(read_from_ini(   ini,    section, "respawn_delta",   "string",    "60,120"), ","       )
   self.respawn_radius   =         read_from_ini(  ini,   section, "respawn_radius",   "float",    0               )
   self.count =                read_from_ini(   ini,    section, "count",         "float",   0               )
   self.position =      str_explode(read_from_ini(   ini,    section, "position",      "string",   "0,0,0"), ","       )
   self.level_vertex_id =         read_from_ini(   ini,    section, "level_vertex_id",   "float",   0               )
   self.game_vertex_id   =         read_from_ini(   ini,    section, "game_vertex_id",   "float",   0               )


   -- Faction Controlled
   self.respawn_only_if_base_controlled = read_from_ini(ini, section, "respawn_only_if_base_controlled", "bool", false)
   self.faction = read_from_ini(ini, section, "faction", "string", "stalker")
   self.zone_name = read_from_ini(ini, section, "zone_name", "string", "")
   self.faction_in_control = self.faction

   -- set respawn timer
   self.respawn_delta[1] = tonumber(self.respawn_delta[1])
   self.respawn_delta[2] = tonumber(self.respawn_delta[2])

   self.delta = math.random(self.respawn_delta[1],self.respawn_delta[2])

   -- create position vector
   self.position = vector():set( tonumber(self.position[1]) , tonumber(self.position[2]), tonumber(self.position[3]))

   -- create table to hold ids of spawned sections
   self.ids = {}

   self.loaded = true
end

function SpawnManager:finalize()
   self:clear_dead()
end

function SpawnManager:update(game_time)
   -- Check if time to call a respawn

   if (self.last_respawn_update == nil or game_time:diffSec(self.last_respawn_update) > self.delta) then

      -- Clear Dead
      self:clear_dead()

      -- Set last update
      self.last_respawn_update = game_time

      -- check if max population reached
      if (#self.ids == self.count) then
         return
      end

      -- Parse conditions to allow a respawn
      local actor = alife():actor()
      if (xr_logic.pick_section_from_condlist(actor, actor, xr_logic.parse_condlist(actor,"","",self.respawn) ) ~= "true") then
         return
      end


      -- If actor is on same level, then respawn only if actor outside of respawn raidus
            if (self.respawn_radius > 0 and game_graph():vertex(self.game_vertex_id):level_id() == game_graph():vertex(actor.m_game_vertex_id):level_id()) then
               if (actor.position:distance_to_sqr(self.position) < self.respawn_radius) then
                  return
               end
            end

      -- If facton only spawner
      if (self.respawn_only_if_base_controlled == true) then
          on_npc_update()
         end
         if (self.faction_in_control ~= self.faction) then
         return
      end
   

      -- randomize delta
      self.delta = math.random(self.respawn_delta[1],self.respawn_delta[2])

      -- Spawn section for each available slot
      self:spawn()

   end
end

function SpawnManager:spawn()
   local se_obj
   local amt = self.count-#self.ids
   for i=1,amt,1 do
      -- Create sections
      se_obj = alife():create(self.sections[math.random(1, #self.sections)],self.position,self.level_vertex_id,self.game_vertex_id)
      -- Remember spawned objects by id
      table.insert(self.ids, se_obj.id)

      register_object(se_obj.id)

      set_object_info(se_obj,"alive",true)
   end
end

function SpawnManager:clear_dead()
   if (#self.ids < 1) then
      return
   end

   local se_obj

   local _temp = {}
   for i=1,#self.ids,1 do
      se_obj = alife():object(self.ids[i])

      -- Check if alive or deleted
      if (se_obj == nil or get_object_info(se_obj,"alive") == false) then

         -- unregister object
         unregister_object(self.ids[i])

      else
         table.insert(_temp,self.ids[i])
      end
      self.ids[i] = nil
   end

   self.ids = nil
   self.ids = _temp
end

function SpawnManager:save(packet)
   if (self.last_respawn_update) then
      utils.w_CTime(packet, self.last_respawn_update)
   else
      packet:w_u8(0)
   end
   packet:w_u32(#self.ids)
   for i=1,#self.ids,1 do
      packet:w_u32(self.ids[i])
   end
   packet:w_stringZ(self.faction_in_control)
end

function SpawnManager:load(packet)
   self.last_respawn_update = utils.r_CTime(packet)

   local count = packet:r_u32()
   for i=1,count,1 do
      self.ids[i] = packet:r_u32()
   end
   self.faction_in_control = packet:r_stringZ()
end

function set_object_info(se_obj,info,val)
   if (Objects[se_obj.id]) then
      --printf("Set[%s] %s = %s",se_obj.id,info,val)
      Objects[se_obj.id][info] = val
   end
end

function get_object_info(se_obj,info)
   if (Objects[se_obj.id]) then
      --printf("Get[%s] %s = %s",se_obj.id,info,Objects[se_obj.id][info])
      return Objects[se_obj.id][info]
   end
end

function register_object(id)
   --printf("Object registered %s",se_obj.id)
   if not (Objects[id]) then
      Objects[id] = {}
   end
end

function unregister_object(id)
   --printf("Object unregistered %s",se_obj.id)
   Objects[id] = nil
end
---------------------------------------------------
-- Callbacks
---------------------------------------------------

function on_npc_update(npc)
        if npc and npc:alive() then
          local zone
          local community
          for i=1,#SpawnerIndex,1 do

             -- Check if spawner can only spawn when faction controlled
             if (Spawner[SpawnerIndex[i]].respawn_only_if_base_controlled == true) then

                   -- get npc faction
                   community = npc:character_community()
                   -- Check only if my faction isn't already in control
                     if (Spawner[SpawnerIndex[i]].faction ~= community) then

                        -- Get zone
            zone = db.zone_by_name[ Spawner[SpawnerIndex[i]].zone_name ]
                         if (zone:inside(npc:position())) then
               get_console():execute(npc:character_community())
                            Spawner[SpawnerIndex[i]].faction_in_control = npc:character_community()
               end
            end
         end
      end
   end
end

-- Callback actor_binder:net_spawn()
function on_game_load()
   if not (initialized) then
      init()
   end
end

-- Callback actor_binder:update()
function on_actor_update()
   local gt = game.get_game_time()
   for i=1,#SpawnerIndex,1 do
      if not (Spawner[SpawnerIndex[i]].loaded) then
         Spawner[SpawnerIndex[i]]:initialize()
      end
      Spawner[SpawnerIndex[i]]:update(gt)
   end
end

-- Callback actor_binder:save()
function on_actor_save(actor,packet)
   for i=1,#SpawnerIndex,1 do
      Spawner[SpawnerIndex[i]]:finalize()
      Spawner[SpawnerIndex[i]]:save(packet)
   end
end

-- Callback actor_binder:load()
function on_actor_load(actor,reader)
   if not (initialized) then
      init()
   end

   for i=1,#SpawnerIndex,1 do
      Spawner[SpawnerIndex[i]]:initialize()
      Spawner[SpawnerIndex[i]]:load(reader)
   end
   initialized = true
end

-- Callback se_stalker:on_death()       Can be called also in se_monster
function on_npc_death(se_obj,who)

   -- flag object as dead
   if (get_object_info(se_obj,"alive")) then
      set_object_info(se_obj,"alive",false)
   end
end

--------------------------
-- Utils
--------------------------
function collect_sections(ini,sections)
   local r,p = {},{}
   for k,v in ipairs(sections) do
      if ini:section_exist(v) then
         local n = ini:line_count(v)
         if n > 0 then
            for i = 0,n-1 do
               local res,id,val = ini:r_line(v,i,"","")
               if r[id] == nil then
                  r[id] = val
               end
            end
         end
         p[k] = n
      else
         p[k] = 0
      end
   end
   return r,p
end

function read_from_ini(ini,section,line,var_type,default)
   if not (ini) then
      ini = system_ini()
   end

   if (section and line and ini:section_exist(section) and ini:line_exist(section,line)) then
      if (var_type == "bool") then
         return ini:r_bool(section,line)
      elseif (var_type == "string") then
         return ini:r_string(section,line)
      elseif (var_type == "float") then
         return ini:r_float(section,line)
      else
         return ini:r_string_wq(section,line)
      end
   else
      return default
   end
end

function string:split(pat)
  local st, g = 1, self:gmatch("()("..pat..")")
  local function getter(self, segs, seps, sep, cap1, ...)
    st = sep and seps + #sep
    return self:sub(segs, (seps or 0) - 1), cap1 or sep, ...
  end
  local function splitter(self)
    if st then return getter(self, st, g()) end
  end
  return splitter, self
end

function str_explode(str,pattern)
   local t = {}
   if (type(str) ~= "string") then return end
   for word, pat, start in str:split(pattern) do
      t[#t+1] = word
      if (start and pat == pattern) then
          t[#t+1] = str:sub(start)
         break
      end
   end
   return t
end

function printf(txt,...)
   if not (text) then return end
   local i = 0
   local p = {...}
   local function sr(a)
      i = i + 1
      return tostring(p[i])
   end
   local output = string.gsub(text,"%%s",sr)
   get_console():execute("load ~#I#:"..output)
   --get_console():execute("flush")
end


and in the bind_stalker.script

Code: Select all

function init    (obj)
   xr_motivator.AddToMotivator(obj)
end

function actor_init    (npc)
   npc:bind_object(actor_binder(npc))
end

local game_difficulty_by_num = {
   [0] = "gd_novice",
   [1] = "gd_stalker",
   [2] = "gd_veteran",
   [3] = "gd_master"
   }

lasthealth  = 0
lasttime   = 0
post_process = 0
local weapon_hide = false
----------------------------------------------------------------------------------------------------------------------
class "actor_binder" (object_binder)
----------------------------------------------------------------------------------------------------------------------
function actor_binder:__init (obj) super(obj)
   self.bCheckStart = false
   self.weather_manager = level_weathers.WeatherManager()
   self.actor_detector = xr_detector.actor_detector()
end
----------------------------------------------------------------------------------------------------------------------
function actor_binder:net_spawn(data)
   printf("actor net spawn")      

   level.show_indicators()

   self.bCheckStart = true
   self.weapon_hide = false -- ñïðÿòàíî èëè íåò îðóæèå ïðè ðàçãîâîðå.
   weapon_hide = false -- óñòàíàâëèâàåì ãëîáàëüíûé äåôîëòîâûé ôëàã.

   if object_binder.net_spawn(self,data) == false then
      return false
   end

   db.add_actor(self.object)
   
   if self.st.disable_input_time == nil then
      level.enable_input()
   end

   self.weather_manager:reset()
--   game_stats.initialize ()

   if(actor_stats.add_to_ranking~=nil)then
      actor_stats.add_to_ranking(self.object:id())
   end

   --' Çàãðóæàåì íàñòðîéêè äðîïà
   death_manager.init_drop_settings()
   
   
   
   --ADDED BY ATONIUM2027 FOR INVASION.MOD
   if xrs_ai then xrs_ai.actor_net_spawn(self) end
--Rudix AI mod
  if rx_ai then
   rx_ai.actor_net_spawn()
  end
if (spawn_manager) then spawn_manager.on_game_load() end

   return true
end
----------------------------------------------------------------------------------------------------------------------
function actor_binder:net_destroy()
   if(actor_stats.remove_from_ranking~=nil)then
      actor_stats.remove_from_ranking(self.object:id())
   end
--   game_stats.shutdown ()
   db.del_actor(self.object)

    sr_light.clean_up ()

   self.object:set_callback(callback.inventory_info, nil)
   self.object:set_callback(callback.article_info, nil)
   self.object:set_callback(callback.on_item_take, nil)
   self.object:set_callback(callback.on_item_drop, nil)
   --self.object:set_callback(callback.actor_sleep, nil)
   self.object:set_callback(callback.task_state, nil)
   self.object:set_callback(callback.level_border_enter, nil)
   self.object:set_callback(callback.level_border_exit, nil)
   self.object:set_callback(callback.take_item_from_box, nil)

   if sr_psy_antenna.psy_antenna then
      sr_psy_antenna.psy_antenna:destroy()
      sr_psy_antenna.psy_antenna = false
   end

   xr_sound.stop_all_sound_object()

   object_binder.net_destroy(self)
end
----------------------------------------------------------------------------------------------------------------------
function actor_binder:reinit()
   object_binder.reinit(self)
   
   local npc_id = self.object:id()

   db.storage[npc_id] = { }

   self.st = db.storage[npc_id]
   self.st.pstor = nil

   self.next_restrictors_update_time = -10000

   self.object:set_callback(callback.inventory_info, self.info_callback, self)
   self.object:set_callback(callback.article_info, self.article_callback, self)
   self.object:set_callback(callback.on_item_take, self.on_item_take, self)
   self.object:set_callback(callback.on_item_drop, self.on_item_drop, self)
   self.object:set_callback(callback.trade_sell_buy_item, self.on_trade, self) -- for game stats
   --self.object:set_callback(callback.actor_sleep, self.sleep_callback, self)
   self.object:set_callback(callback.task_state, self.task_callback, self)
   --self.object:set_callback(callback.map_location_added, self.map_location_added_callback, self)
   self.object:set_callback(callback.level_border_enter, self.level_border_enter, self)
   self.object:set_callback(callback.level_border_exit, self.level_border_exit, self)
   self.object:set_callback(callback.take_item_from_box, self.take_item_from_box, self)
end
----------------------------------------------------------------------------------------------------------------------
function actor_binder:take_item_from_box(box, item)
   local story_id = box:story_id()
   if story_id == nil then
      return
   end

   treasure_manager.take_item_from_box(box, story_id)
--[[   
   local respawner = se_respawn.get_respawner_by_parent(story_id)
   if respawner == nil then
      return
   end
   
   --' Íåîáõîäèìî óìåíüøèòü ñ÷åò÷èê â ðåñïàâíåðå
   respawner:remove_spawned(item:id())

   local smart_terrain = db.strn_by_respawn[respawner:name()]
   if smart_terrain == nil then
      return
   end

   local npc = smart_terrain.gulag:get_nearest_online_obj(db.actor:position())
    if npc ~= nil then
       xr_sound.set_sound_play(npc, "reac_box")
       xr_gulag.setGulagEnemy(smart_terrain:name() , db.actor)      
    end
]]
end
----------------------------------------------------------------------------------------------------------------------
function actor_binder:level_border_enter(npc, info_id)
   self.actor_detector:actor_enter()
end
----------------------------------------------------------------------------------------------------------------------
function actor_binder:level_border_exit(npc, info_id)
   self.actor_detector:actor_exit()
end
----------------------------------------------------------------------------------------------------------------------
function actor_binder:info_callback(npc, info_id)
   printf("*INFO*: npc='%s' id='%s'", npc:name(), info_id)
   --' Ñþæåò
   level_tasks.proceed(self.object)
   -- Îòìåòêè íà êàðòå
   level_tasks.process_info_portion(info_id)
   
   
   
   
--ADDED BY ATONIUM2027 FOR INVASION.MOD
   inventory.on_inventory_info(info_id)
end
----------------------------------------------------------------------------------------------------------------------
function actor_binder:on_trade (item, sell_bye, money)
    if sell_bye == true then
       game_stats.money_trade_update (money)
    else       
       game_stats.money_trade_update (-money)
    end   

--ADDED BY ATONIUM2027 FOR INVASION.MOD

end
----------------------------------------------------------------------------------------------------------------------
function actor_binder:article_callback(npc, group, name)
   --printf("article_callback [%s][%s]", group, name)
   if device().precache_frame >1 then return end
   
   if group == "Diary" then
      news_manager.send_encyclopedy("diary", group)
   else
      news_manager.send_encyclopedy("encyclopedy", group)
   end
end
----------------------------------------------------------------------------------------------------------------------
function actor_binder:on_item_take (obj)
    level_tasks.proceed(self.object)
   
   
   
   
--ADDED BY ATONIUM2027 FOR INVASION.MOD 
   if xrs_ai then xrs_ai.actor_item_take(obj) end
    inventory.on_item_take(obj)

   --Rudix AI mod
   if rx_ai then
      rx_ai.actor_item_take(obj)
   end



end
----------------------------------------------------------------------------------------------------------------------
function actor_binder:on_item_drop (obj)
    level_tasks.proceed(self.object)
    --game_stats.update_drop_item (obj, self.object)
    inventory.on_item_drop(obj)
         if ps_items then
               ps_items.on_item_drop(obj)
            end

   if obj:section() == "repair_kit" then
      obj_id = obj:id()
   end
       
end
----------------------------------------------------------------------------------------------------------------------

function actor_binder:task_callback(_task, _objective, _state)
   task_manager.task_callback(_task:get_id(), _objective:get_idx(), _state)
   if _objective:get_idx() == 0 then
      if _state == task.fail then
         news_manager.send_task(db.actor, "fail", _task, _objective)
      elseif _state == task.completed then
         task_manager.reward_by_task(_task)
         news_manager.send_task(db.actor, "complete", _task, _objective)
      else
         news_manager.send_task(db.actor, "new", _task, _objective)
      end
   else
      if _task:get_objective(0):get_state() == task.in_progress then
         news_manager.send_task(db.actor, "update", _task, _objective)
      end
   end
end

----------------------------------------------------------------------------------------------------------------------
function actor_binder:map_location_added_callback(spot_type_str, object_id)
   if (false==app_ready()) or (device().precache_frame>1) then return end
   --'news_manager.send_task(db.actor, "new")
end
----------------------------------------------------------------------------------------------------------------------
function actor_binder:update(delta)
   object_binder.update(self, delta)


if (spawn_manager) then spawn_manager.on_actor_update() end

   if obj_id and alife():object(obj_id)==nil then
      repair_kit.repair_ui_menu()
   end


   -- DEBUG slowdown
--   slowdown.update()

   if ps_items then
      ps_items.update()
   end

   local time = time_global()
   
   game_stats.update (delta, self.object)

   -- àïäåéò ïîãîäû
   self.weather_manager:update()
   
   -- àïäåéò ñõåìû äåòåêòîðà
   self.actor_detector:update()

   -- àïäåéò çâóêîâîé ñõåìû àêòåðà
   xr_sound.update_actor()
   
   if actor_need_help and actor_need_help.obj_id_in_team(self.object:id()) then
   actor_need_help.update_level_names()
   local dest=actor_need_help.get_offline_dest()
  end
   
   --' Ïðîâåðêà ïîòåðè æèçíè
--[[
   if self.object.health - lasthealth > 0.001 or
      self.object.health - lasthealth < -0.001 then
      printf("%f | %f", self.object.health, self.object.health - lasthealth, game.time() - lasttime)
      lasthealth = self.object.health
      lasttime = game.time()
   end
]]   
   -- Îáíîâëåíèå îòêëþ÷åíèÿ ââîäà ñ êëàâèàòóðû.
   if self.st.disable_input_time ~= nil and
      game.get_game_time():diffSec(self.st.disable_input_time) >= self.st.disable_input_idle
   then
      level.enable_input()
      self.st.disable_input_time = nil
   end
   -- Îáíîâëåíèå ñíà ñ ïåðåíîñîì ÷óâàêà â óêàçàííóþ ïîçèöèþ
   if self.st.sleep_relocate_time ~= nil and
      game.get_game_time():diffSec(self.st.sleep_relocate_time) >= self.st.sleep_relocate_idle
   then
      self.object:set_actor_position(self.st.sleep_relocate_point)
      local dir = self.st.sleep_relocate_point:sub(self.st.sleep_relocate_look)
      self.object:set_actor_direction(dir:getH())
      self.st.sleep_relocate_time = nil
   end

   -- Àïäåéò ïðÿòàíèå îðóæèÿ èãðîêà âî âðåìÿ äèàëîãà
   if weapon_hide == true or self.object:is_talking() then
      if self.weapon_hide == false then
         self.object:hide_weapon()
         self.weapon_hide = true
      end
   else
      if self.weapon_hide == true then
         self.object:restore_weapon()
         self.weapon_hide = false
      end
   end   

   -- îáíîâëåíèå ðåñòðèêòîðîâ, êîòîðûå ïîä ëîãèêîé, ñðàáàòûâàåò ÷åðåç èíòåðâàëû âðåìåíè
   if self.next_restrictors_update_time < time then
      bind_restrictor.actor_update(delta)

      self.next_restrictors_update_time = time + 200

      task_manager.actor_update()
   end

   -- îáíîâëåíèå ïîñòïðîöåññîâ
   if post_process ~= 0 then
      if post_process:update () == true then
         post_process = 0
      end
   end

   -- îáíîâëåíèå ïñè-àíòåííû
   if sr_psy_antenna.psy_antenna then
      sr_psy_antenna.psy_antenna:update(delta)
   end


   --ADDED BY ATONIUM2027 FOR INVASION.MOD

   inventory.update()
   --' Âûâîä ñîîáùåíèÿ î áîëüøîé ðàäèàöèè
   if self.object.radiation >= 0.7 then
      local hud = get_hud()
      local custom_static = hud:GetCustomStatic("cs_radiation_danger")
      if custom_static == nil then
         hud:AddCustomStatic("cs_radiation_danger", true)
         hud:GetCustomStatic("cs_radiation_danger"):wnd():SetTextST("st_radiation_danger")
      end
   else
      local hud = get_hud()
      local custom_static = hud:GetCustomStatic("cs_radiation_danger")
      if custom_static ~= nil then
         hud:RemoveCustomStatic("cs_radiation_danger")
      end
   end




    if self.bCheckStart then
      printf("SET DEFAULT INFOS")      

      if not has_alife_info("storyline_actor_start") and
         (level.name() == "marsh")
      then
         self.object:give_info_portion("storyline_actor_start")
         _G.g_start_avi = true
         printf("*AVI* RUN START AVI")         
      end


      if not has_alife_info("global_dialogs") then
         self.object:give_info_portion("global_dialogs")
      end

      if not has_alife_info("level_changer_icons") then
         self.object:give_info_portion("level_changer_icons")
      end

      level_tasks.add_lchanger_location()

      self.bCheckStart = false      
   end      
   
   
   --ADDED BY ATONIUM2027 FOR INVASION.MOD
   if biodetector then biodetector.update() end
   if xrs_ai then xrs_ai.actor_update(delta) end
   -- Rudix AI mod
   if rx_ai then rx_ai.actor_update() end



end
----------------------------------------------------------------------------------------------------------------------
function actor_binder:save(packet)
   --Rudix AI mod
   if rx_ai then rx_ai.actor_save(packet) end
   
   local save_treasure_manager = true
   
   printf("actor_binder:save(): self.object:name()='%s'", self.object:name())
   object_binder.save(self, packet)

   --' Ñîõðàíÿåì óðîâåíü ñëîæíîñòè
   if save_treasure_manager == true then
      packet:w_u8(level.get_game_difficulty() + 128)
   else
      packet:w_u8(level.get_game_difficulty())
   end


   --' Ñîõðàíÿåì äàííûå îá îòêëþ÷åííîì ââîäå
   if self.st.disable_input_time == nil then
      packet:w_bool(false)
   else
      packer:w_bool(true)
      utils.w_CTime(packet, self.st.disable_input_time)
   end

   xr_logic.pstor_save_all(self.object, packet)
   self.weather_manager:save(packet)

   sr_psy_antenna.save( packet )
   
   if save_treasure_manager == true then
      treasure_manager.save(packet)     
   end                                 

   task_manager.save(packet)
   self.actor_detector:save(packet)
if (spawn_manager) then spawn_manager.on_actor_save(self.object,packet) end
end
----------------------------------------------------------------------------------------------------------------------
function actor_binder:load(reader)
   printf("actor_binder:load(): self.object:name()='%s'", self.object:name())
   object_binder.load(self, reader)
   printf("actor_binder:object_binder.load(): self.object:name()='%s'", self.object:name())

   --' Çàãðóæàåì óðîâåíü ñëîæíîñòè
   local game_difficulty = reader:r_u8()
   
   local load_treasure_manager = false     
   if game_difficulty >= 128 then           
      game_difficulty = game_difficulty - 128
      load_treasure_manager = true           
   end                                     

   

   if reader:r_eof() then
      abort("SAVE FILE IS CORRUPT")
   end

   local stored_input_time = reader:r_u8()
   if stored_input_time == true then
      self.st.disable_input_time = utils.r_CTime(reader)
   end

   xr_logic.pstor_load_all(self.object, reader)
   self.weather_manager:load(reader)

   sr_psy_antenna.load(reader)
   
   if load_treasure_manager == true then
      treasure_manager.load(reader)     
   end                                 

   
   task_manager.load(reader)
   self.actor_detector:load(reader)
if (spawn_manager) then spawn_manager.on_actor_load(self.object,reader) end      
end
----------------------------------------------------------------------------------------------------------------------

--ñòàðò ïðåôåò÷à çâóêîâ
--if string.find(command_line(), "-noprefetch") == nil then
--   sound_prefetch.prefetch_sounds()
--end


-- Weapon functions
function hide_weapon()
   weapon_hide = true
end
function restore_weapon()
   weapon_hide = false
end

// this is test for section iteration
/**
local function test_section_iteration(file_name, section_name)
   printf         ("file    : %s",file_name)
   printf         ("section : %s",section_name)
   
   local         file = ini_file(file_name)
   local         n = file:line_count(section_name)
   printf         ("lines   : %d",n)
   
   local         id, value = "", "", result
   for i=0,n-1 do
      result, id, value   = file:r_line(section_name,i,"","")
      printf      ("line %d : %s = %s",i,id,value)
   end
end

test_section_iteration("system.ltx","space_restrictor")
/**/





in thexr_motivator.script i have ad this

Code: Select all

function motivator_binder:update(delta)
...................................
if (spawn_manager and spawn_manager.on_npc_update) then
        local npc = self.object or db.storage[self.id] and db.storage[self.id].object
        if (npc) then
            spawn_manager.on_npc_update(npc)
        end
   end


end



and add this

Code: Select all

function se_stalker:on_death(killer)
   cse_alife_human_stalker.on_death(self, killer)
   if (spawn_manager) then spawn_manager.on_npc_death(self,killer) end
   --' Óáðàòü ìàïñïîò ñ ñîáîé
   if sim_statistic.show_stalker_spot == true then
      local community, rank = sim_statistic.getNpcType(self)
      level.map_remove_object_spot(self.id, "alife_presentation_"..community)
   end
end


and in the se_monster.script i have add this

Code: Select all

function se_monster:on_death(killer)
   cse_alife_monster_base.on_death(self, killer)
   if (spawn_manager) then spawn_manager.on_npc_death(self,killer) end
   --' Óáðàòü ìàïñïîò ñ ñîáîé
   if sim_statistic.show_monster_spot == true then
      local community, rank = sim_statistic.getNpcType(self)
      level.map_remove_object_spot(self.id, "alife_presentation_monstr")
   end
end




and hier is my spawn_manager.ltx

Code: Select all

[sections]
mar_clear_sky_1 = true
mar_clear_sky_2 = true
mar_clear_sky_3 = true
mar_clear_sky_4 = true
mar_soldier_regular = true


[mar_clear_sky_1]
sections = mar_clear_sky_regualr_1         ;Random selection on each spawn
respawn = true                                                   ;Can be condlist
respawn_delta = 5400,7400                                                ;seconds idle before trying to respawn
respawn_radius = 10                                                   ;Respawn only if actor outside radius
count = 3                                                      ;Amount to spawn
position = 31.549459457397,3.0783360004425,-235.57046508789
level_vertex_id = 155355
game_vertex_id = 3433
respawn_only_if_base_controlled = true
faction = sky
zone_name = mar_clear_sky_base_restrictor

[mar_clear_sky_2]
sections = mar_clear_sky_regualr_2
respawn = true
respawn_delta = 5400,7400
respawn_radius = 10
count = 3
position = 26.858909606934,2.8843760490417,-215.20172119141
level_vertex_id = 152468
game_vertex_id = 3433
respawn_only_if_base_controlled = true
faction = sky
zone_name = mar_clear_sky_base_restrictor


[mar_clear_sky_3]
sections = mar_clear_sky_regualr_3
respawn = true
respawn_delta = 5400,7400
respawn_radius = 10
count = 3
position = 31.549459457397,3.0783360004425,-235.57046508789
level_vertex_id = 155355
game_vertex_id = 3433
respawn_only_if_base_controlled = true
faction = sky
zone_name = mar_clear_sky_base_restrictor


[mar_clear_sky_4]
sections = mar_clear_sky_regualr_4
respawn = true
respawn_delta = 5400,7400
respawn_radius = 10
count = 3
position = 31.549459457397,3.0783360004425,-235.57046508789
level_vertex_id = 155355
game_vertex_id = 3433
respawn_only_if_base_controlled = true
faction = sky
zone_name = mar_clear_sky_1_restrictor



[mar_soldier_regular]
sections = mar_soldier_regular
respawn = true
respawn_delta = 5400,7400
respawn_radius = 10
count = 3
position = 120.62075805664,0.94821202754974,-152.2998046875
level_vertex_id = 207680
game_vertex_id = 3465
respawn_only_if_base_controlled = true
faction = military
zone_name = mar_clear_sky_1_restrictor




and this is one of my space restrictor

Code: Select all

[18688]
; cse_abstract properties
section_name = space_restrictor
name = mar_clear_sky_base_restrictor
position = 31.549459457397,3.0783360004425,-235.57046508789
direction = 0,0,0

; cse_alife_object properties
game_vertex_id = 3433
distance = 0
level_vertex_id = 155355
object_flags = 0xffffff3e

; cse_shape properties
shapes = shape0
shape0:type = sphere
shape0:offset = 0,0,0
shape0:radius = 45.117057800293

; cse_alife_space_restrictor properties
restrictor_type = 3




When anyone have a question then can ask me

Re: Spawn Manager

Posted: 06 Jul 2012, 16:36
by Alundaio
I would remove on_npc_update in xr_motivator and only keep the one in se_stalker.


Here is the problem. In CoP there is a storage table for offline objects called db.offline_objects. Apparently that doesn't exist in SoCh. I'm not sure if db.storage is also the storage for offline objects. You need to be able to get the level object of se_stalker.

So try this:

Code: Select all

function se_stalker:update()
   cse_alife_human_stalker.update(self)
   if (spawn_manager and spawn_manager.on_npc_update) then
        local npc = self.object or db.storage[self.id] and db.storage[self.id].object or level.object_by_id(self.id)
        if (npc) then
            spawn_manager.on_npc_update(npc)
        end
   end
end

Re: Spawn Manager

Posted: 07 Jul 2012, 07:10
by olaf1
I have use that but the NPC´s spawn every :( no matter in this space restrictor are enemy NPC´s

Re: Spawn Manager

Posted: 08 Jul 2012, 09:28
by olaf1
I have the feeling that the function on_npc_update not alaway are work.

for example i have make a get_console():execute("text") in the SpawnManager:spawn() function i get this test every a npc were spawn but wenn i get this in the on_npc_update function then i get nothing in the console :(

How i can say that this function alawy working??
I hope you can understand this i have test that with te bind_stalker but i get nothing :(

Re: Spawn Manager

Posted: 08 Jul 2012, 10:07
by Alundaio
It should be working every update. Must be a difference between Call of Pripyat and Soch.

Maybe you should think of a different way to spawn. Checking every npc if there in certain zones so something can spawn is kinda inefficient and apparently ineffective. I think in Clear Sky, Smart Terrains already work this way and it's set up for faction wars.