ProjectsWhat's NewDownloadsCommunitySupportCompany
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
smal script question

1 2 3 | Next 10 events »| All Messages
Posted by/on
Question/AnswerMake Newest Up Sort by Descending
  16:15:01  21 June 2012
profilee-mailreply Message URLTo the Top
olaf1
Senior Resident
 

 
On forum: 01/17/2012
 

Message edited by:
olaf1
06/22/2012 20:50:20
Messages: 240
smal script question

I have a question about this script



local npc_table = {
"mar_clear_sky_respawn_1_1_kamper",
"mar_clear_sky_respawn_1_2_kamper",
"mar_clear_sky_respawn_1_3_kamper",
"mar_clear_sky_respawn_2_1_kamper",
"mar_clear_sky_respawn_2_2_kamper",
"mar_clear_sky_respawn_2_3_kamper",
"mar_clear_sky_respawn_3_1_kamper",
"mar_clear_sky_respawn_3_2_kamper",
"mar_clear_sky_respawn_3_3_kamper"
}

local npc_data_table = {
mar_clear_sky_respawn_1_1_kamper = {
timer1		= 3,
timer2 		= 6,
sections	= "mar_clear_sky_respawn_1_1_kamper",
position = {x = 15.05495262146,y = 2.565721988678,z = -265.27029418945,game_vertex_id = 146152,level_vertex_id = 3423},
count		= 1,
id 			= {},
respwanen = true},

mar_clear_sky_respawn_1_2_kamper = {
timer1		= 3,
timer2 		= 6,
sections	= "mar_clear_sky_respawn_1_2_kamper",
position = {x = 15.05495262146,y = 2.565721988678,z = -265.27029418945,game_vertex_id = 146152,level_vertex_id = 3423},
count		= 1,
id 			= {},
respwanen = true},

mar_clear_sky_respawn_1_3_kamper = {
timer1		= 3,
timer2 		= 6,
sections	= "mar_clear_sky_respawn_1_3_kamper",
position = {x = 15.05495262146,y = 2.565721988678,z = -265.27029418945,game_vertex_id = 146152,level_vertex_id = 3423},
count		= 1,
id 			= {},
respwanen = true},

mar_clear_sky_respawn_2_1_kamper = {
timer1		= 3,
timer2 		= 6,
sections	= "mar_clear_sky_respawn_2_1_kamper",
position = {x = 26.493240356445,y = 3.2842679023743,z = -264.8073425293,game_vertex_id = 152405,level_vertex_id = 3436},
count		= 1,
id 			= {},
respwanen = true},

mar_clear_sky_respawn_2_2_kamper = {
timer1		= 3,
timer2 		= 6,
sections	= "mar_clear_sky_respawn_2_2_kamper",
position = {x = 26.493240356445,y = 3.2842679023743,z = -264.8073425293,game_vertex_id = 152405,level_vertex_id = 3436},
count		= 1,
id 			= {},
respwanen = true},




mar_clear_sky_respawn_2_3_kamper = {
timer1		= 3,
timer2 		= 6,
sections	= "mar_clear_sky_respawn_2_3_kamper",
position = {x = 26.493240356445,y = 3.2842679023743,z = -264.8073425293,game_vertex_id = 152405,level_vertex_id = 3436},
count		= 1,
id 			= {},
respwanen = true},

mar_clear_sky_respawn_3_1_kamper = {
timer1		= 3,
timer2 		= 6,
sections	= "mar_clear_sky_respawn_3_1_kamper",
position = {x =35.865989685059,y = 3.1588425636292,z = -259.74450683594,game_vertex_id = 157685,level_vertex_id = 3436},
count		= 1,
id 			= {},
respwanen = true},

mar_clear_sky_respawn_3_2_kamper = {
timer1		= 3,
timer2 		= 6,
sections	= "mar_clear_sky_respawn_3_2_kamper",
position = {x = 35.865989685059,y = 3.1588425636292,z = -259.74450683594,game_vertex_id = 157685,level_vertex_id = 3436},
count		= 1,
id 			= {},
respwanen = true},

mar_clear_sky_respawn_3_3_kamper = {
timer1		= 3,
timer2 		= 6,
sections	= "mar_clear_sky_respawn_3_3_kamper",
position = {x = 35.865989685059,y = 3.1588425636292,z = -259.74450683594,game_vertex_id = 157685,level_vertex_id = 3436},
count		= 1,
id 			= {},
respwanen = true}
}







function read()	
local npc = npc_table[math.random(1, 9)]
	if npc_data_table[npc] and npc_data_table[npc].respwanen == true then
	npc_name = npc_data_table[npc].sections	
	pos = npc_data_table[npc].position
	npc_number = npc_data_table[npc].count
	timer1 = npc_data_table[npc].timer1
	timer2 = npc_data_table[npc].timer2
	spawn_timer(timer1,timer2)
	spawnen(npc_name,pos,npc_number)
	end
end	


local spawn_start = false
local timer = nil


function spawn_timer(timer1,timer2)
if db.actor:alive() == false then return end
local level_name = level.name()
	if spawn_start == false then
			if timer == nil then
			timer = level.get_time_hours() + math.random(timer1, timer2)
			if timer > 23 then timer = timer - 24 end
			end
		if level.get_time_hours() > timer then
		timer = nil
		spawn_start = true
		end
	end
end
                            


function spawnen(npc,pos,count)
if spawn_start == true then
	if npc and pos and count then
		for i = 1,count do
		npc_data_table[npc].id[alife():create(npc,vector():set(pos.x, pos.y ,pos.z) ,pos.game_vertex_id ,pos.level_vertex_id)] = true
		npc_data_table[npc].respwanen = false
		end
		spawn_start = false	
		end
	else spawn_start = false		
	end	
end



function npc_dead()
local npc = npc_table[math.random(1, 9)]
	if npc_data_table[npc] then
		if npc_data_table[npc].respwanen == false then	
			local tbl_count,obj = 0,nil
			for k,v in pairs(npc_data_table[npc].id) do
			obj = db.storage[k] and db.storage[k].object
			if obj and obj:alive() == false and v == true then
				v = false
				npc_data_table[npc].id = {}
				npc_data_table[npc].respwanen = true
			else
				tbl_count = tbl_count + 1
			end
		end
	end
end
end
		 	


function save(packet)
	save_table(packet,npc_data_table.mar_clear_sky_respawn_1_1_kamper)
	save_table(packet,npc_data_table.mar_clear_sky_respawn_1_2_kamper)
	save_table(packet,npc_data_table.mar_clear_sky_respawn_1_3_kamper)
	save_table(packet,npc_data_table.mar_clear_sky_respawn_2_1_kamper)
	save_table(packet,npc_data_table.mar_clear_sky_respawn_2_2_kamper)
	save_table(packet,npc_data_table.mar_clear_sky_respawn_2_3_kamper)
	save_table(packet,npc_data_table.mar_clear_sky_respawn_3_1_kamper)
	save_table(packet,npc_data_table.mar_clear_sky_respawn_3_2_kamper)
	save_table(packet,npc_data_table.mar_clear_sky_respawn_3_3_kamper)
end

function load(reader)
	load_table(reader,npc_data_table.mar_clear_sky_respawn_1_1_kamper)
	load_table(reader,npc_data_table.mar_clear_sky_respawn_1_2_kamper)
	load_table(reader,npc_data_table.mar_clear_sky_respawn_1_3_kamper)
	load_table(reader,npc_data_table.mar_clear_sky_respawn_2_1_kamper)
	load_table(reader,npc_data_table.mar_clear_sky_respawn_2_2_kamper)
	load_table(reader,npc_data_table.mar_clear_sky_respawn_2_3_kamper)
	load_table(reader,npc_data_table.mar_clear_sky_respawn_3_1_kamper)
	load_table(reader,npc_data_table.mar_clear_sky_respawn_3_2_kamper)
	load_table(reader,npc_data_table.mar_clear_sky_respawn_3_3_kamper)
end

function load_table(reader, obj)
	local ctr = reader:r_u32()
	local tn = 0
	local varname = ""
	local xobj = nil
	for i = 1, ctr do
		varname = reader:r_stringZ()
		tn = reader:r_u8()
		if tn == 0 then
			obj[varname] = reader:r_float()
		elseif tn == 1 then
			obj[varname] = reader:r_stringZ()
		elseif tn == 2 then
			obj[varname] = reader:r_bool()
		elseif tn == 3 then
			obj[varname] = {}
			xobj = obj[varname]
			load_table(reader, xobj)
		end
	end
end

function save_table(packet, obj)
	local ctr = 0
	local tv = nil
	local xobj = nil
	for k,v in pairs(obj) do
		ctr = ctr + 1
	end
	packet:w_u32(ctr)
	for k,v in pairs(obj) do
 		packet:w_stringZ(k)
		tv = type(v)
		if tv == "number" then
			packet:w_u8(0)
	 		packet:w_float(v)
	 	elseif tv == "string" then
			packet:w_u8(1)
	 		packet:w_stringZ(v)
		elseif tv == "boolean" then
			packet:w_u8(2)
			packet:w_bool(v)
		elseif tv == "table" then
			packet:w_u8(3)
			xobj = obj[k]
			save_table(packet, xobj)
		end
	end	
end






i Think the problem is the save and load table can anyone help me away.
  17:12:13  21 June 2012
profilee-mailreply Message URLTo the Top
MrSeyker
Senior Resident
 

 
On forum: 03/21/2010
Messages: 438
Might be because all the Ids are nil.
  17:40:05  21 June 2012
profilee-mailreply Message URLTo the Top
olaf1
Senior Resident
 

 
On forum: 01/17/2012
Messages: 240

---QUOTATION---
Might be because all the Ids are nil.
---END QUOTATION---


how i can change this???
  09:16:25  22 June 2012
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
 

Message edited by:
ThunderFreak
06/22/2012 9:17:09
Messages: 685
Change this line
if time_global() > timer then

to
if level.get_time_hours() > timer then


Because you set the time by hours 3 lines above and not by MS (milli seconds).
  09:37:53  22 June 2012
profilee-mailreply Message URLTo the Top
olaf1
Senior Resident
 

 
On forum: 01/17/2012
Messages: 240

---QUOTATION---
Change this line
if time_global() > timer then

to
if level.get_time_hours() > timer then


Because you set the time by hours 3 lines above and not by MS (milli seconds).
---END QUOTATION---



Thank you but this is not my problem can you help me pleas by my other problem
  11:07:50  22 June 2012
profilee-mailreply Message URLTo the Top
SetaKat
Ex modder, Zones only ferret and will someday release a game
(Resident)

 

 
On forum: 02/20/2010
Messages: 6342
The problem is the sections property in each entry of npc_data_table needs to be the same as the entry name, eg, so if the entry is called "mar_clear_sky_respawn_1_1_kamper", then the sections property of it needs to be set to "mar_clear_sky_respawn_1_1_kamper", not "mar_clear_sky_respawn_1_kamper".
The crash is caused by the game looking for "mar_clear_sky_respawn_1_kamper" in npc_data_table, and as it doesn't exist, it crashes.
Easy to spot, once I indented the code so it is readable, and traced the execution line backwards from the error. Glaringly obvious, once the code is read.

@ThunderFreak
As another scripter, how did you not spot this before me?
  13:22:55  22 June 2012
profilee-mailreply Message URLTo the Top
olaf1
Senior Resident
 

 
On forum: 01/17/2012
 

Message edited by:
olaf1
06/22/2012 14:49:49
Messages: 240

---QUOTATION---
The problem is the sections property in each entry of npc_data_table needs to be the same as the entry name, eg, so if the entry is called "mar_clear_sky_respawn_1_1_kamper", then the sections property of it needs to be set to "mar_clear_sky_respawn_1_1_kamper", not "mar_clear_sky_respawn_1_kamper".
The crash is caused by the game looking for "mar_clear_sky_respawn_1_kamper" in npc_data_table, and as it doesn't exist, it crashes.
Easy to spot, once I indented the code so it is readable, and traced the execution line backwards from the error. Glaringly obvious, once the code is read.

@ThunderFreak
As another scripter, how did you not spot this before me?
---END QUOTATION---


fluffy i have change this and it work very perfectly but the NPC´s spawn and spawn although he is alive.
Can you or an othe say me why???

I think that has to do with save table and load table.
I hope you can help me away.
  14:40:17  22 June 2012
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
Messages: 685

---QUOTATION---
@ThunderFreak
As another scripter, how did you not spot this before me?
---END QUOTATION---


I'm at work, so couldn't take a closer look. Anyway, he emailed me the problem too.
  17:23:04  22 June 2012
profilee-mailreply Message URLTo the Top
olaf1
Senior Resident
 

 
On forum: 01/17/2012
Messages: 240
I think i know the problem but i don´t know how i can remedy the problem.
The problem is the save and load table. When i load not after i save then only 9 NPC´s sawn after i load the savegame there 18 NPC´s after the timer.

can anyone help me by my problem???
  14:24:11  24 June 2012
profilee-mailreply Message URLTo the Top
olaf1
Senior Resident
 

 
On forum: 01/17/2012
Messages: 240
I have a problem. Every i kill a NPC and load the game after i have save this the game a crashed and in the erro log are nothing.

can you help me away ,please???

Thank you


local npc_table = {
"mar_clear_sky_respawn_1_1_kamper",
"mar_clear_sky_respawn_1_2_kamper",
"mar_clear_sky_respawn_1_3_kamper",
"mar_clear_sky_respawn_2_1_kamper",
"mar_clear_sky_respawn_2_2_kamper",
"mar_clear_sky_respawn_2_3_kamper",
"mar_clear_sky_respawn_3_1_kamper",
"mar_clear_sky_respawn_3_2_kamper",
"mar_clear_sky_respawn_3_3_kamper"
}

local npc_data_table = {
mar_clear_sky_respawn_1_1_kamper = {
timer1		= 3,
timer2 		= 6,
sections	= "mar_clear_sky_respawn_1_1_kamper",
position = {x = 15.05495262146,y = 2.565721988678,z = -265.27029418945,game_vertex_id = 146152,level_vertex_id = 3423},
count		= 1,
id 			= {},
respwanen = true},

mar_clear_sky_respawn_1_2_kamper = {
timer1		= 3,
timer2 		= 6,
sections	= "mar_clear_sky_respawn_1_2_kamper",
position = {x = 15.05495262146,y = 2.565721988678,z = -265.27029418945,game_vertex_id = 146152,level_vertex_id = 3423},
count		= 1,
id 			= {},
respwanen = true},

mar_clear_sky_respawn_1_3_kamper = {
timer1		= 3,
timer2 		= 6,
sections	= "mar_clear_sky_respawn_1_3_kamper",
position = {x = 15.05495262146,y = 2.565721988678,z = -265.27029418945,game_vertex_id = 146152,level_vertex_id = 3423},
count		= 1,
id 			= {},
respwanen = true},

mar_clear_sky_respawn_2_1_kamper = {
timer1		= 3,
timer2 		= 6,
sections	= "mar_clear_sky_respawn_2_1_kamper",
position = {x = 26.493240356445,y = 3.2842679023743,z = -264.8073425293,game_vertex_id = 152405,level_vertex_id = 3436},
count		= 1,
id 			= {},
respwanen = true},


mar_clear_sky_respawn_2_2_kamper = {
timer1		= 3,
timer2 		= 6,
sections	= "mar_clear_sky_respawn_2_2_kamper",
position = {x = 26.493240356445,y = 3.2842679023743,z = -264.8073425293,game_vertex_id = 152405,level_vertex_id = 3436},
count		= 1,
id 			= {},
respwanen = true},

mar_clear_sky_respawn_2_3_kamper = {
timer1		= 3,
timer2 		= 6,
sections	= "mar_clear_sky_respawn_2_3_kamper",
position = {x = 26.493240356445,y = 3.2842679023743,z = -264.8073425293,game_vertex_id = 152405,level_vertex_id = 3436},
count		= 1,
id 			= {},
respwanen = true},

mar_clear_sky_respawn_3_1_kamper = {
timer1		= 3,
timer2 		= 6,
sections	= "mar_clear_sky_respawn_3_1_kamper",
position = {x =35.865989685059,y = 3.1588425636292,z = -259.74450683594,game_vertex_id = 157685,level_vertex_id = 3436},
count		= 1,
id 			= {},
respwanen = true},

mar_clear_sky_respawn_3_2_kamper = {
timer1		= 3,
timer2 		= 6,
sections	= "mar_clear_sky_respawn_3_2_kamper",
position = {x = 35.865989685059,y = 3.1588425636292,z = -259.74450683594,game_vertex_id = 157685,level_vertex_id = 3436},
count		= 1,
id 			= {},
respwanen = true},

mar_clear_sky_respawn_3_3_kamper = {
timer1		= 3,
timer2 		= 6,
sections	= "mar_clear_sky_respawn_3_3_kamper",
position = {x = 35.865989685059,y = 3.1588425636292,z = -259.74450683594,game_vertex_id = 157685,level_vertex_id = 3436},
count		= 1,
id 			= {},
respwanen = true}
}





function read()	
local npc = npc_table[math.random(1, 9)]
	if npc_data_table[npc] and npc_data_table[npc].respwanen == true then
	npc_name = npc_data_table[npc].sections	
	pos = npc_data_table[npc].position
	npc_number = npc_data_table[npc].count
	timer1 = npc_data_table[npc].timer1
	timer2 = npc_data_table[npc].timer2
	spawn_timer(timer1,timer2)
	spawnen(npc_name,pos,npc_number)
	end
end	


local spawn_start = false
local timer = nil


function spawn_timer(timer1,timer2)
if db.actor:alive() == false then return end
local level_name = level.name()
	if spawn_start == false then
			if timer == nil then
			timer = level.get_time_hours() + math.random(timer1, timer2)
			if timer > 23 then timer = timer - 24 end
			end
		if level.get_time_hours() > timer then
		timer = nil
		spawn_start = true
		end
	end
end
                            


function spawnen(npc,pos,count)
if spawn_start == true then
	if npc and pos and count then
		for i = 1,count do
		npc_data_table[npc].id[alife():create(npc,vector():set(pos.x, pos.y ,pos.z) ,pos.game_vertex_id ,pos.level_vertex_id)] = true
		npc_data_table[npc].respwanen = false
		sim_statistic.register_respawn(npc)
		end
		spawn_start = false
		end
	else spawn_start = false		
	end	
end


function npc_dead()
local npc = npc_table[math.random(1, 9)]
	if npc_data_table[npc] then
		if npc_data_table[npc].respwanen == false then	
			local tbl_count,obj = 0,nil
			for k,v in pairs(npc_data_table[npc].id) do
			obj = db.storage[k] and db.storage[k].object
			if obj and obj:alive() == false and v == true then
				v = false
				npc_data_table[npc].id = {}
				npc_data_table[npc].respwanen = true
			else
				tbl_count = tbl_count + 1
			end
		end
	end
end
end
	

	



function save(packet)
	save_table(packet,npc_data_table)
end

function load(reader)
	load_table(reader,npc_data_table)

end




function load_table(reader, obj)
	local ctr = reader:r_u32()
	local tn = 0
	local varname = ""
	local xobj = nil
	for i = 1, ctr do
		varname = reader:r_stringZ()
		tn = reader:r_u8()
		if tn == 0 then
			obj[varname] = reader:r_float()
		elseif tn == 1 then
			obj[varname] = reader:r_stringZ()
		elseif tn == 2 then
			obj[varname] = reader:r_bool()
		elseif tn == 3 then
			obj[varname] = {}
			xobj = obj[varname]
			load_table(reader, xobj)
		end
	end
end

function save_table(packet, obj)
	local ctr = 0
	local tv = nil
	local xobj = nil
	if obj ~= nil then
	for k,v in pairs(obj) do
		ctr = ctr + 1
	end
	end
	packet:w_u32(ctr)
	for k,v in pairs(obj) do
 		packet:w_stringZ(k)
		tv = type(v)
		if tv == "number" then
			packet:w_u8(0)
	 		packet:w_float(v)
	 	elseif tv == "string" then
			packet:w_u8(1)
	 		packet:w_stringZ(v)
		elseif tv == "boolean" then
			packet:w_u8(2)
			packet:w_bool(v)
		elseif tv == "table" then
			packet:w_u8(3)
			xobj = obj[k]
			save_table(packet, xobj)
		end
	end	
end




 
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.