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
|