ProjectsWhat's NewDownloadsCommunitySupportCompany
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
why the respwan npc´s are spwan when the actor is only in the near of his spwan point

Posted by/on
Question/AnswerMake Newest Up Sort by Descending
  19:03:11  6 April 2012
profilee-mailreply Message URLTo the Top
olaf1
Senior Resident
 

 
On forum: 01/17/2012
Messages: 240
why the respwan npc´s are spwan when the actor is only in the near of his spwan point

I have a question?

why the respwan npc´s are spwan when the actor is only in the near of his spwan point

i hope that any one can help me away i have make a new script and it wokrs for ever.
  19:23:34  6 April 2012
profilee-mailreply Message URLTo the Top
ket
Senior Resident
 

 
On forum: 01/13/2006
Messages: 1432
Its a paramater you can adjust in all.spawn, the paramater defines how far away the actor should be before spawning. Increasing or decreasing the value obviously increases or decreases the range in which the actor needs to be before the spawn will occur.
  19:36:02  6 April 2012
profilee-mailreply Message URLTo the Top
olaf1
Senior Resident
 

 
On forum: 01/17/2012
 

Message edited by:
olaf1
04/06/2012 19:40:00
Messages: 240

---QUOTATION---
Its a paramater you can adjust in all.spawn, the paramater defines how far away the actor should be before spawning. Increasing or decreasing the value obviously increases or decreases the range in which the actor needs to be before the spawn will occur.
---END QUOTATION---



but i have not in the all.spwan any entries.

hier is the script


local tIdlePreset = {
	["seldom"]	= 900,
	["medium"]	= 700,
	["often"] 	= 300
}

local i,k,v = 0,0,0

local tRespawners 	    = {}
local tRespawnersParent = {}



class "se_respawn" (cse_alife_smart_zone)
function se_respawn:__init(section) super(section)
	self.tSpawnObject 	= {}	
	self.tSpawnProp 	= {}
	self.oRespawnTime = game.CTime()
end


function se_respawn:STATE_Write( packet )
	cse_alife_smart_zone.STATE_Write( self, packet )
	utils.w_CTime(packet, self.oRespawnTime)
	
	local iTableSize = table.getn(self.tSpawnObject)
	packet:w_u8(iTableSize)	
	for i = 1, iTableSize do
		packet:w_u16(self.tSpawnObject[i])
	end
end



function se_respawn:STATE_Read( packet, size )
	cse_alife_smart_zone.STATE_Read( self, packet, size )	
	if editor() then
		return
	end
	
	self.oRespawnTime = utils.r_CTime(packet)
	local iTableSize = packet:r_u8()
	for i = 1, iTableSize do
		table.insert(self.tSpawnObject, packet:r_u16())
	end	
end

function se_respawn:on_register()
	cse_alife_smart_zone.on_register(self)
	RegisterInit(self)
end


function se_respawn:update()
	cse_alife_smart_zone.update(self)
	self:execute()
end





function se_respawn:execute()
	if self.iIdleSpawn == -1 then 
		return 
	end	

	if self.oRespawnTime > game.get_game_time() then
		return
	end
	
	local oIdleTime = game.CTime()
	oIdleTime:setHMSms(0,0,0, self.iIdleSpawn * math.random(1, 2) * 600)
	self.oRespawnTime = game.get_game_time() + oIdleTime		
	self:UpdateObject()

	local sProbability = xr_logic.pick_section_from_condlist(db.actor_proxy, self, self.aConditions)
	if not sProbability or tonumber(sProbability) == 0 then 
		sim_statistic.respawn_enabled(self, false)
		return 
	end
	sim_statistic.respawn_enabled(self, true)

	if table.getn(self.tSpawnObject) < self.iMinCount then		
		while table.getn(self.tSpawnObject) < self.iMinCount do
			if self:CreateObject(100) == false then
				return
			end
		end	
		return
	end
		

	for i = 1, self.iMaxSpawn do		
		if self.iMaxCount ~= -1 and self.iMaxCount < #self.tSpawnObject then 
			return 
		end
		if self.tCount then
			for iKey, tRespawn in pairs(self.tSectionsToRespawn) do
				local iCount = self.tCount[iKey] or 1
				printf("Ðåñïàâí: "..tostring(self.sName)..": "..tRespawn.section.." - "..iCount)
				
				for i = 1, iCount do
					self:CreateObject(sProbability, tRespawn.section)
				end
			end	
		else
			if self:CreateObject(sProbability) == false then 
				return 
			end
		end
	end	
end


function se_respawn:UpdateObject()
	for k,v in pairs(self.tSpawnObject) do
		local obj = level.object_by_id(v)	
		if obj == nil then obj = alife():object(v) end	

		if obj == nil or ((IsStalker(obj) or IsMonster(obj)) and (obj:alive()~=true)) then
			table.remove(self.tSpawnObject, k)
		end
	end
end




function se_respawn:CreateObject(sProbability, sSpawnSection)
	if math.random(100) > tonumber(sProbability) then
		return
	end	
		
	local iSum = 0

	if not sSpawnSection then	
		for k,v in pairs(self.tSectionsToRespawn) do
			iSum = iSum + v.probability
		end
		
		iSum = math.random(0, iSum)
		for k,v in pairs(self.tSectionsToRespawn) do
			iSum = iSum - v.probability			
			if iSum <= 0 then
				sSpawnSection = v.section
				break
			end
		end
	end
	
	if sSpawnSection == nil then return false end		
	
	if self.iParent then
		local oParent = alife():story_object(self.iParent)
		if oParent == nil then
			abort("SPAWNING [%s], cant find parent with SID [%s]", self:name(), self.iParent)
			return
		end

		if oParent.id and self.bItemSpawn then
			local oItem = alife():create(sSpawnSection,	
				self.position,
				self.m_level_vertex_id,	
				self.m_game_vertex_id,
				oParent.id)						
			table.insert(self.tSpawnObject, oItem.id)
			return true
		end
	else
		local oCreature = alife():create(sSpawnSection,	
			self.position,
			self.m_level_vertex_id,	
			self.m_game_vertex_id)	
		
		if self.sName==nil then
			if self.tSpawnProp[sSpawnSection].isCheck == true then
				oCreature:brain():update()
				local iSmartTerrainID = oCreature:smart_terrain_id()			
				if iSmartTerrainID ~= 65535 then		
					table.insert(self.tSpawnObject, oCreature.id)
					return true
				else
					alife():release(oCreature, true)
					return false
				end
			end						
			table.insert(self.tSpawnObject, oCreature.id)
			return true
		else	
			if self.sLogic ~= "nil" then
				if IsMonster(oCreature) then
					local tData = net_packet_read.GetMonster(oCreature)					
					tData.sCustomData = "[logic]\ncfg = scripts\\"..self.sLogic..".ltx" 
					net_packet_write.SetMonster(tData, oCreature)
				elseif IsStalker(oCreature) then	
					local tData = net_packet_read.GetStalker(oCreature)
					tData.sCustomData = "[logic]\ncfg = scripts\\"..self.sLogic..".ltx" 
					net_packet_write.SetStalker(tData, oCreature)
				end
			end
			table.insert(self.tSpawnObject, oCreature.id)
			return true
		end
	end
end



function RegisterInit(oRespawn)
	local ini = oRespawn:spawn_ini()
	if not ini:section_exist("respawn") then return	end

	oRespawn.tSectionsToRespawn  = readSpawns(ini, "respawn", "respawn_section", oRespawn.tSpawnProp)	
	if oRespawn.tSectionsToRespawn == nil then
		abort("RESPAWN: [%s] field 'respawn_section' doesn't exist.", tostring(oRespawn:name()))
	end	

	oRespawn.sLogic = ReadLine(ini, "String", "respawn", "logic")	
	oRespawn.sName = ReadLine(ini, "String", "respawn", "name")
	oRespawn.iMinCount =  ReadLine(ini, "Number", "respawn", "min_count",  0)
	oRespawn.iMaxCount =  ReadLine(ini, "Number", "respawn", "max_count", -1)
	oRespawn.iMaxSpawn =  ReadLine(ini, "Number", "respawn", "max_spawn",  1)
	oRespawn.iIdleSpawn = ReadLine(ini, "String", "respawn", "idle_spawn", "medium")
	oRespawn.sCond = ReadLine(ini, "String", "respawn", "conditions", 100)
	oRespawn.aConditions = xr_logic.parse_condlist(oRespawn, "respawn", "conditions", oRespawn.sCond)
	oRespawn.iParent =  ReadLine(ini, "Number", "respawn", "parent", nil)
	oRespawn.bItemSpawn = ReadLine(ini, "Boolean", "respawn", "item_spawn", false)

	local sCount = ReadLine(ini, "String", "respawn", "count", "nil")
	if sCount ~= "nil" then
		oRespawn.tCount = SplitString(sCount, 1, ",")
	end
	
	if oRespawn.iMinCount > oRespawn.iMaxCount and oRespawn.iMaxCount ~= -1 then
		abort("RESPAWN: [%s] min_count > max_count", oRespawn:name())
	end
	if tIdlePreset[oRespawn.iIdleSpawn] ~= nil then
		oRespawn.iIdleSpawn = tIdlePreset[oRespawn.iIdleSpawn]
	else
		oRespawn.iIdleSpawn = tonumber(oRespawn.iIdleSpawn)
		if oRespawn.iIdleSpawn == nil then
			abort("RESPAWN: [%s] 'idle_spawn' doesn't exist.", oRespawn:name())
		end
	end
	
	tRespawners[oRespawn:name()] = oRespawn
	if oRespawn.iParent ~= nil then
		tRespawnersParent[oRespawn.iParent] = oRespawn
	end

	sim_statistic.register_respawn(oRespawn)
end





function spawnAction(name)
	local myRespawn = tRespawners[name]
	if myRespawn == nil then
		return
	end
		
	local sProbability = xr_logic.pick_section_from_condlist(db.actor_proxy, myRespawn, myRespawn.aConditions)
	for i = 1, myRespawn.iMaxSpawn do		
		if myRespawn.iMaxCount ~= -1 and table.getn(myRespawn.tSpawnObject) >= myRespawn.iMaxCount then
			return
		end
		if myRespawn.tCount then
			for iKey, tRespawn in pairs(myRespawn.tSectionsToRespawn) do
				local iCount = myRespawn.tCount[iKey] or 1
				printf(tostring(myRespawn.sName)..": "..tRespawn.section.." - "..iCount)
				
				for i = 1, iCount do
					myRespawn:CreateObject(sProbability, tRespawn.section)
				end
			end				
			StartTime(myRespawn)
			
			return
		end
		
		if myRespawn:CreateObject(sProbability) == false then
			return
		else
			StartTime(myRespawn)
		end
	end	
end

function StartTime(myRespawn)
	local oIdleTime = game.CTime()
	oIdleTime:setHMSms(0,0,0, myRespawn.iIdleSpawn * math.random(1, 3) * 600)
	myRespawn.oRespawnTime = game.get_game_time() + oIdleTime
end

function parse_names(s)
    local t = {}
    for sName in string.gfind(s, "([%w_%-.\\]+)%p*") do
        table.insert(t, sName)
    end
    return t
end





function readSpawns(spawn_ini, section, line, tSpawnProp)
	if spawn_ini:line_exist(section, line) then			
		local tRetTable = {}
		local aTableSpawn = parse_names(spawn_ini:r_string(section, line))	
		local iCount = table.getn(aTableSpawn)			
		local k = 1		
		while k <= iCount do			
			local tSpawn = {}
			tSpawn.section = aTableSpawn[k]

			if aTableSpawn[k+1] ~= nil then
				local p = tonumber(aTableSpawn[k+1])
				if p then
					tSpawn.probability = p
					k = k + 2
				else
					tSpawn.probability = 1
					k = k + 1
				end
			else
				tSpawn.probability = 1
				k = k + 1
			end
			table.insert(tRetTable, tSpawn)	
			if tSpawnProp[tSpawn.section] == nil then		
				local respawn_ini = system_ini()
				local sCommunity 	= ReadLine(respawn_ini, "String", tSpawn.section, "community", "nil")
				local sRank 		= ReadLine(respawn_ini, "String", tSpawn.section, "spec_rank", "nil")
				local isCheck 		= true
				local sCustomData 	= ReadLine(respawn_ini, "String", tSpawn.section, "custom_data")		
				if sCustomData ~= nil then
					local iniCustomData = ini_file(sCustomData)			
					if iniCustomData:section_exist("smart_terrains") then					
						if iniCustomData:line_exist("smart_terrains", "none") then
							if ReadLine(iniCustomData, "String", "smart_terrains", "none") == "true" then
								isCheck = false
							end	
						end					
                        if iniCustomData:line_exist("smart_terrains", "respawn_check") then
                            if ReadLine(iniCustomData, "String", "smart_terrains", "respawn_check") == "false" then
                                isCheck = false
                            end
                        end 			
					end
				end				
				tSpawnProp[tSpawn.section] = { sCommunity = sCommunity, sRank = sRank, isCheck = isCheck }
			end					
		end	
		return tRetTable
	end	
	return nil
end


function create_ammo(section, position, lvi, gvi, pid, num)
	local ini = system_ini()
	local num_in_box = ini:r_u32(section, "box_size")
	while num > num_in_box do
		alife():create_ammo(section, position, lvi,	gvi, pid, num_in_box)
		num = num - num_in_box
	end
	return alife():create_ammo(section, position, lvi,	gvi, pid, num)
end





function spawn(name)
	local spawner = respawners[name]
	if spawner == nil then
		return
	end
	
	for i=1,spawner.max_spawn do
		if spawner.max_count ~= -1 and table.getn(spawner.spawned_obj) >= spawner.max_count then
--			printf("SPAWNING [%s], CANT SPAWN. MAX COUNT REACHED!!!", tostring(spawner:name()))
			return
		end		
		if spawner:create(xr_logic.pick_section_from_condlist(db.actor_proxy, spawner, spawner.conditions)) == false then
			return
		end
	end		
end

  19:38:39  6 April 2012
profilee-mailreply Message URLTo the Top
cOldSnake
modeler
(Resident)

 

 
On forum: 07/11/2011
Messages: 197

---QUOTATION---
Its a paramater you can adjust in all.spawn, the paramater defines how far away the actor should be before spawning. Increasing or decreasing the value obviously increases or decreases the range in which the actor needs to be before the spawn will occur.
---END QUOTATION---



Can you paste a section in all.spawn for that?I know when you spawn an npc in level editor it has an option "can switch online" and "can switch offline".When "can switch offline" is unchecked npc dosent dessaper 150-300 meters from actor
  19:41:12  6 April 2012
profilee-mailreply Message URLTo the Top
olaf1
Senior Resident
 

 
On forum: 01/17/2012
 

Message edited by:
olaf1
04/06/2012 19:46:32
Messages: 240
can i chage it?
when i spwan NPC´s per script?

when yes where?

thank you
  20:31:38  6 April 2012
profilee-mailreply Message URLTo the Top
cOldSnake
modeler
(Resident)

 

 
On forum: 07/11/2011
Messages: 197

---QUOTATION---
can i chage it?
when i spwan NPC´s per script?

when yes where?

thank you
---END QUOTATION---


I dont know about script,but in all spawn for NPC online/offline switch is probably an object flag.And i dont think(or know) it will work with NPC spawned with respawn
  20:33:26  6 April 2012
profilee-mailreply Message URLTo the Top
olaf1
Senior Resident
 

 
On forum: 01/17/2012
 

Message edited by:
olaf1
04/06/2012 21:00:44
Messages: 240

---QUOTATION---
can i chage it?
when i spwan NPC´s per script?

when yes where?

thank you
I dont know about script,but in all spawn for NPC online/offline switch is probably an object flag.And i dont think(or know) it will work with NPC spawned with respawn
---END QUOTATION---




witch flag?

edit:
have anyone an idea?
  16:06:51  7 April 2012
profilee-mailreply Message URLTo the Top
cOldSnake
modeler
(Resident)

 

 
On forum: 07/11/2011
Messages: 197

---QUOTATION---
can i chage it?
when i spwan NPC´s per script?

when yes where?

thank you
I dont know about script,but in all spawn for NPC online/offline switch is probably an object flag.And i dont think(or know) it will work with NPC spawned with respawn


witch flag?

edit:
have anyone an idea?
---END QUOTATION---



Change a value in gamedata/config/alife.ltx,under alife section

switch_distance = 1500

default is 150
  16:07:58  7 April 2012
profilee-mailreply Message URLTo the Top
olaf1
Senior Resident
 

 
On forum: 01/17/2012
 

Message edited by:
olaf1
04/07/2012 16:12:30
Messages: 240
thank you i will test it


edit

thank for ever it works very good
 
Each word should be at least 3 characters long.
Search:    
Search conditions:    - spaces as AND    - spaces as OR   
 
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
 

All short dates are in Month-Day-Year format.


 

Copyright © 1995-2021 GSC Game World. All rights reserved.
This site is best viewed in Internet Explorer 4.xx and up and Javascript enabled. Webmaster.
Opera Software products are not supported.
If any problem concerning the site functioning under Opera Software appears apply
to Opera Software technical support service.