ProjectsWhat's NewDownloadsCommunitySupportCompany
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
Assigning a Smart Terrain to a NPC spawned by script

« Previous 10 events | 1 2 3 4 5 | Next 10 events »| All Messages
Posted by/on
Question/AnswerMake Newest Up Sort by Descending
  18:16:44  17 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
Messages: 319
OK

I'll try to set my ST right first, then I'll try to spawn my NPC and see if it does respawn or not.

Thanks
  21:12:53  17 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
Messages: 319

---QUOTATION---
The excellent packet_utils allows you to set custom_data from script (among many other things). For example,

local data = packet_utils.get_object_data( sObj ) --where sObj is a server object reference to your NPC
data.custom_data = "[smart_terrains]\nesc_lager = true"
packet_utils.set_object_data( sObj, data )


---END QUOTATION---




Doesn't work for me:

FATAL ERROR
 
[error]Expression    : fatal error
[error]Function      : CScriptEngine::lua_error
[error]File          : E:\stalker\sources\trunk\xr_3da\xrGame\script_engine.cpp
[error]Line          : 73
[error]Description   : <no expression>
[error]Arguments     : LUA error: ....e.r. - soc\gamedata\scripts\sacripan_testing.script:241: attempt to index local 'data' (a nil value)





This is how I psawn my NPC (works OK) and then add the ST to its logic:

local npc_id	=	nil


--[[------------------------------------------------
	Function to spawn a NPC
--]]------------------------------------------------
function spawn_test_npc()


	local pos		=	vector():set(-58.2559, -3.9862, -68.4168)
	local level_id	=	219612
	local game_id	=	74
	
	local npc		=	alife():create("esc_st_test_npc", pos, level_id, game_id)
	npc_id		=	npc.id
	
end



--[[------------------------------------------------
	Function bind the ST to a NPC
--]]------------------------------------------------
function bind_npc_to_ST_test()


	if (npc_id ~= nil) then
		local npc	=	level.object_by_id(npc_id)
		local data	=	packet_utils.get_object_data( npc )
		
		data.custom_data	=	"[smart_terrains]\nesc_st_test = true"
		packet_utils.set_object_data( npc, data )
	end
	
	
end




I have "packet_utils" 2.0 and run on 1.6 patch. I tried on a 1.4 install but got the same error.


Also, concerning my Smart Terrain, I did have a typo, preventing other ST to be OK. It's fine now. The only problem is, seconds after I enable my own ST, the game freezes...
  22:25:54  17 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
Messages: 319
UPDATE on the error message generated after the freeze.


FATAL ERROR
 
[error]Expression    : fatal error
[error]Function      : CScriptEngine::lua_error
[error]File          : E:\stalker\sources\trunk\xr_3da\xrGame\script_engine.cpp
[error]Line          : 73
[error]Description   : <no expression>
[error]Arguments     : LUA error: ...l.k.e.r. - soc\gamedata\scripts\smart_terrain.script:836: attempt to index a function value




Here is the script file:

function se_smart_terrain:create_gulag()
	self.duration_end = game.CTime()   -- LINE 836...
--	self.duration_end:setHMSms( 0, 0, 0, math.random( self.gparams.duration_min * h2ms, self.gparams.duration_max * h2ms ) )
	self.duration_end:setHMSms( math.random( self.gparams.duration_min, self.gparams.duration_max ), 0, 0, 0 )
	self.duration_end:add( game.get_game_time() )

	self.check_time = CTime_0

	self.gulag:initialize()

	self.gulag_working = true
end

  22:51:39  17 April 2014
profilee-mailreply Message URLTo the Top
TKGP
Senior Resident
 

 
On forum: 01/25/2013
 

Message edited by:
TKGP
04/17/2014 22:53:43
Messages: 454
SacriPan,
level.object_by_id attempts to find a client object (that is to say, something that's online) with the given ID. It does not work to get server objects, which is what you need for packet_utils. Immediately after you spawn something, it is still offline, even if it's within switch distance; I should have mentioned as well that setting object data only works on offline objects, but that's not a problem here. So, leaving the rest the same all you need to do is this:

local npc	=	level.object_by_id(npc_id)
change to...
local npc = alife():object( npc_id )


Note: alife():create returns a server object reference in the first place, so you can use that result directly instead of recording the ID and re-acquiring the reference based on that, if you prefer.
  02:43:58  18 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
 

Message edited by:
SacriPan
04/18/2014 12:16:21
Messages: 319
Ok, so after a lot of trial and errors, I finally got my ST working (Dez ST debug tool says it is, it's active and yellow)

But of course, I got a "new" CTD as soon as I approached the NPC:


[error]Expression    : fatal error
[error]Function      : CScriptEngine::lua_error
[error]File          : E:\stalker\sources\trunk\xr_3da\xrGame\script_engine.cpp
[error]Line          : 73
[error]Description   : <no expression>
[error]Arguments     : LUA error: ....t.a.l.k.e.r. - soc\gamedata\scripts\xr_logic.script:371: attempt to index field '?' (a nil value)




That is the line (vanilla file)
_G[filename].set_scheme(npc, ini, scheme, section, db.storage[npc_id]["gulag_name"])


Also, for now, I spawned my NPC via all.spawn and assigned him its ST there too.
  15:28:32  18 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
 

Message edited by:
SacriPan
04/18/2014 16:58:00
Messages: 319
I put some displays in the log and I found out that "filename" is not set, and that is why the error occurs.


I don't get what I'm doing wrong. I just followed the tutorial.
I have 1 Smart Terrain, 1 job, 1 state (I tried with 2 states), 1 NPC, but the game just can't take it...

Any advice?


EDIT:
If anyone has special powers to make ST work properly, I'll take them too
  17:15:16  18 April 2014
profilee-mailreply Message URLTo the Top
Alundaio
Sad Clown
(Resident)

 

 
On forum: 04/05/2010
 

Message edited by:
Alundaio
04/18/2014 17:26:50
Messages: 2230
There is a probably a typo in the npc's custom data. Or a syntax error in the script of the scheme it is using.


---QUOTATION---
"[smart_terrains]\nesc_st_test = true"
---END QUOTATION---



Is this what you are using? Don't they need a [logic] section?

Here is my example I use in cop to spawn helicopters and edit the packet to set the logic:


data.custom_data = "[logic]\n cfg = scripts\\heli_test.ltx"

  17:51:42  18 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
Messages: 319
Well I'm new to packet_utils. I used TKGP advices and code example.

As far as I understand about logic, I didn't need to set the NPC logic because I set the smart terrain, the Smart terrain providing to my NPC its own logic (via a job).

That how I understand it at least



In all.spawn there can be a [logic] section and a [smart_terrain] section for a NPC.
But logic section points to a custom logic file for the NPC, which I believe is only used if he's not tied to a Smart Terrain.

I'm not really sure about that though
  18:01:45  18 April 2014
profilee-mailreply Message URLTo the Top
Alundaio
Sad Clown
(Resident)

 

 
On forum: 04/05/2010
 

Message edited by:
Alundaio
04/18/2014 18:14:14
Messages: 2230

---QUOTATION---
he's not tied to a Smart Terrain
---END QUOTATION---


It's used for exclusive jobs at smart terrains.

Sorry, assigning a [smart_terrain] section is not something I'm familiar with. I didn't realize that's how SoC uses the dynamic gulag_general. Though I guess it's not that dynamic in SoC, .

Are you spawning him at a smart that has available jobs?
  21:10:59  18 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
 

Message edited by:
SacriPan
04/18/2014 21:17:37
Messages: 319
Yes, I spawn him at the same coordinates than the ST, so I don't have to wait an hour for him to go to work
 
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.