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
  00:27:42  20 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
 

Message edited by:
SacriPan
04/20/2014 0:30:47
Messages: 319
But even if I go with xr_effect and info_portions and all, I still have to dynamically change his logic (which will be random, of course ), so what else than packet can I use?

I don't get it
  01:20:37  20 April 2014
profilee-mailreply Message URLTo the Top
Alundaio
Sad Clown
(Resident)

 

 
On forum: 04/05/2010
 

Message edited by:
Alundaio
04/20/2014 1:44:57
Messages: 2230
You are looking at something more sophisticated. I didn't test this but in theory you need to unregister the npc from his current smart/gulag and register him to the new smart. If you want it random you could maybe do a random roll every hour. If the roll passes he switches the job.


-- xr_conditions.script
-- 50% chance to return true every 3600 in-game seconds
local last_check_time
function can_switch_job(actor,npc,p)
	if (last_check_time == nil or game.get_game_time():diffSec(last_check_time) >= 3600) then
		last_check_time = game.get_game_time()
		if (math.random() < 50) then 
			return true 
		end 	
	end
	return false
end


local switch_job_table = { 
							["default"] = "smart_name_1",
							["smart_name_1"] = "smart_name_2",
							["smart_name_2"] = "smart_name_1"
						}
						
local cfg_by_smart = 	{
						["smart_name_1"] = "[logic]\n cfg = scripts\\my_custom_logic1.ltx",
						["smart_name_2"] = "[logic]\n cfg = scripts\\my_custom_logic2.ltx"
						}
						
-- Switch job based on his current smart
function switch_gulag_and_job(actor,npc,p)

	local sim = alife()
	
	-- get server object (Maybe replace with sim:story_object and use SID)
	local se_obj = p[1] and sim:object(p[1])
	if not (se_obj) then 
		return 
	end 
	
	-- If has current smart then unregister
	local smart
	local smart_id = se_obj:smart_terrain_id()
	if (smart_id and smart_id ~= 65535) then 

		-- get smart by id
		smart = sim:object(smart_id)
		if (smart) then 
			-- unregister npc from smart
			smart:unregister_npc(se_obj)
		end
	end
	
	-- get new target gulag based on old gulag or if no current gulag use default
	local new_gulag_name = smart and switch_job_table[smart:name()] or switch_job_table["default"]
	local new_gulag = new_gulag_name and xr_gulag.get_gulag_by_name(new_gulag_name)
	if not (new_gulag) then 
		return 
	end
	
	-- grab new smart
	local new_smart = new_gulag.smrttrn
	if not (new_smart) then 
		return 
	end
	
	-- register npc to new smart 
	new_smart:register_npc(se_obj)
	
	-- switch/ensure offline
	if (se_obj.online) then 
		sim:set_switch_online(se_obj.id,false)
		sim:set_switch_offline(se_obj.id,true)
	end	
	
	-- get new custom_data
	local custom_data = cfg_by_smart[new_smart:name()]
	if not (custom_data) then 
		return 
	end
	
	-- set packet data
	local data = packet_utils.get_object_data(se_obj)
	data.custom_data = custom_data
end 

on_info = {=can_switch_job} %=switch_gulag_and_job(npc_by_name)%




You may need to use the [smart_terrains] section or whatever for it. But you get the idea. You can probably try to test switch_gulag_and_job by using your menu keys.

EDIT:

edited
  02:00:14  20 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
 

Message edited by:
SacriPan
04/20/2014 2:03:27
Messages: 319
Ah.... I kinda abandoned the idea of Smart Terrain for this, and I think the main advantage of a ST is the respawn, which I don't want.


What you suggest is too complex for what I wanna do and I just made it work via logic only. I used what you told me about info_portions and these are what my script will randomly fire:

I will only use logic and it will look like this (this works, I just tested it, the NPC switches jobs smoothly)


[smart_terrains]
 none			= true

[logic]
 active			= walker@job1

;-- binocular
[walker@job1]
 path_walk		= pan_rookie_kamp
 path_look		= pan_rookie_binocular
 def_state_moving	= patrol
 meet			= meet
 on_info 		= {+pan_npc_01_go_to_job2} walker@job2 %-pan_npc_01_go_to_job1%
 on_info2 		= {+pan_npc_01_go_to_job3} kamp@job3 %-pan_npc_01_go_to_job1%
 
;-- guard
[walker@job2]
 path_walk		= pan_rookie_kamp
 path_look		= pan_rookie_guard
 def_state_moving	= patrol
 meet			= meet
 on_info 		= {+pan_npc_01_go_to_job1} walker@job1 %-pan_npc_01_go_to_job2%
 on_info2 		= {+pan_npc_01_go_to_job3} kamp@job3 %-pan_npc_01_go_to_job2%

;-- kampfire
[kamp@job3]
 path_walk		= <path_camp_name>_task
 center_point		= pan_rookie_kamp
 radius			= 2
 def_state_moving	= patrol
 meet			= meet
 on_info 		= {+pan_npc_01_go_to_job1} walker@job1 %-pan_npc_01_go_to_job3%
 on_info2 		= {+pan_npc_01_go_to_job2} walker@job2 %-pan_npc_01_go_to_job3%
 
;-- meet
[meet]
 use			= true
 use_wpn		= true
 meet_talk_enabled	= true
 meet_state		= ward
 use_medkit		= true




For what I wanna do, I will have to define a lot more "on_info" lines (maybe 5 or 6) but it's just config, it's quite easy compared to messing with Smart terrain and packets.

Nonetheless, thanks for you efforts (both TKGP and Alundaio), I did learn things in this thread, and I'm sure I wasn't the only one
  02:12:50  20 April 2014
profilee-mailreply Message URLTo the Top
Alundaio
Sad Clown
(Resident)

 

 
On forum: 04/05/2010
 

Message edited by:
Alundaio
04/20/2014 2:21:21
Messages: 2230
I was under the impression you wanted a npc to take jobs at two different gulags. What you did is perfect for what you want.
  02:24:27  20 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
 

Message edited by:
SacriPan
04/20/2014 2:24:37
Messages: 319
Well, technically, that's what I want and I thought I'd use Smart terrains for that.
You know, have NPCs take jobs at a ST, deactivate this ST at a given time and in the meantime, activate an other ST, so NPCs would travel across the map (that part is important) and occupy other job on the newly activated ST.

But like we said, logic is far less complicated and allow the same level of control over NPCs taking jobs, at least for what I wanna do.
  21:05:32  20 April 2014
profilee-mailreply Message URLTo the Top
Vintar
a bit of this and a lot of that
(Resident)

 

 
On forum: 08/08/2008
Messages: 6349

---QUOTATION---
Well, technically, that's what I want and I thought I'd use Smart terrains for that.
You know, have NPCs take jobs at a ST, deactivate this ST at a given time and in the meantime, activate an other ST, so NPCs would travel across the map (that part is important) and occupy other job on the newly activated ST.

But like we said, logic is far less complicated and allow the same level of control over NPCs taking jobs, at least for what I wanna do.
---END QUOTATION---



Sounds like all you are wanting is an actual working version of general lager. I`ve fixed it for LA and it works like a charm.
  13:05:21  21 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
Messages: 319
Well, I did some test yesterday with mutants.

I want to spawn a pack of dogs, and have them settle in a camp (like my NPCs). When I give the proper info_portion, they will follow the new Logic and will travel to their new camp.

I did this with Logic only and it works like a charm

Though, configurating Logic will be quite long (to say the least...) because the number of possible camps will increase the number of info_portions, as well as the "on_info lines" for each behavior in the Logic files. But in the end, it will be a matter of copy and paste.


@Vintar
I wouldn't know about general_lager. What's it about exactly? Why doesn't it work in vanilla?
  21:38:59  21 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
 

Message edited by:
SacriPan
04/21/2014 21:43:27
Messages: 319
I have a problem with 1 NPC's Logic.

He's supposed to go to sleep at night.

The thing is, he goes to the coordinates, but adopts a "camp" attitude, though, he snores...

I use this:

[logic@pan_st_test_kamp01_job02_night]
 active		= sleeper@pan_st_test_kamp01_job02_night

[sleeper@pan_st_test_kamp01_job02_night]
 path_main	= kamp01_job02_sleep
 wakeable	= true
 meet		= meet@pan

Strangely, when I use "walker" instead of "sleeper", he does sleep, but he doesn't make any sound. Also, the "weakable" tag has no effect at all.
[logic@pan_st_test_kamp01_job02_night]
 active		= walker@pan_st_test_kamp01_job02_night

[walker@pan_st_test_kamp01_job02_night]
 path_walk	= kamp01_job02_sleep
 wakeable	= true
 meet		= meet@pan


The waypoint is defined as follows in "way_escape.ltx":

[pan_st_test_kamp01_job02_sleep]
points = p0
p0:name = name00|a=sleep
p0:flags = 0x1
p0:position = -69.7271, -4.0084, -87.9482
p0:game_vertex_id = 76
p0:level_vertex_id = 202911




Any clue on this strange behavior?
  21:42:47  21 April 2014
profilee-mailreply Message URLTo the Top
Vintar
a bit of this and a lot of that
(Resident)

 

 
On forum: 08/08/2008
Messages: 6349
I've been working with LA scripts and SDK for so long now I actually don't know what is supported by the vanilla files anymore. In LA (and possibly SOC) it's quite simple to change smart terrains with an infoportion :
[smart_terrains]
esc_kamp1 = {-info2 +info1}
esc_kamp2 = {-info3 +info2}
esc_kamp3 = {-info4 +info3}



etcetera.
  21:46:38  21 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
 

Message edited by:
SacriPan
04/21/2014 22:18:45
Messages: 319
@vintar

I tried that this afternoon:


[smart_terrains]
esc_kamp1 = {-info_kamp2}
esc_kamp2 = {+info_kamp2}



NPCs go effectively from kamp1 to kamp2 when the info_portion is given, but when I disable it, they just wander around...
I believe they are suppose to go back to kamp1, as the info_portion is disabled, therefore kamp2 is not available anymore and kamp is now available.
Is there a subtility I didn't catch here?
 
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.