16:15:01 21 June 2012 |
|
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:40:05 21 June 2012 |
|
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:37:53 22 June 2012 |
|
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 |
|
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?
IMPORTANT! Fetching error logs! - http://sdk.stalker-game.com/en/index.php?title=Crash-log
My first STALKER story: The Job (Updated 11/6/11)
https://www.gsc-game.com/index.php?t=community&s=forums&s_game_type=xr&thm_page=1&thm_id=19109&sec_id=5
|
13:22:55 22 June 2012 |
|
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. |
17:23:04 22 June 2012 |
|
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 |
|
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
|
|