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
  20:09:03  19 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
 

Message edited by:
SacriPan
04/19/2014 20:30:49
Messages: 319
Ok guys,

I managed to change on the fly the logic a NPC uses with a mix of TKGP's and Alundaio's advices:

local npc		= alife():object(npc_01_id)
local se_obj		= packet_utils.get_server_obj(npc)
local data		= packet_utils.get_object_data(se_obj)
data.custom_data	= "[logic]\n cfg = scripts\\my_custom_logic.ltx"
packet_utils.set_object_data( se_obj, data )




The problem for me is that the NPC has to go offline to make the change of logic really effective, so I need to go more than 120 meters away, which is not acceptable.


Is there a way to force a NPC to go switch offline and then come back online?

I would use my script before bringing him back online.
  20:46:55  19 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
 

Message edited by:
SacriPan
04/19/2014 21:08:36
Messages: 319
I found this in lua_help but of course, it doesn't work, or at least not the way I thought it would (I want the NPC to go offline in front of me if I tell him to):

sim:set_switch_online(p_id, false)
sim:set_switch_offline(p_id, true)


and then

sim:set_switch_online(p_id, true)
sim:set_switch_offline(p_id, false)

  21:02:49  19 April 2014
profilee-mailreply Message URLTo the Top
Alundaio
Sad Clown
(Resident)

 

 
On forum: 04/05/2010
 

Message edited by:
Alundaio
04/19/2014 21:10:17
Messages: 2230

---QUOTATION---
local npc = alife() bject(npc_01_id)
local se_obj = packet_utils.get_server_obj(npc)
local data = packet_utils.get_object_data(se_obj)
data.custom_data = "[logic]\n cfg = scripts\\my_custom_logic.ltx"
packet_utils.set_object_data( se_obj, data )
---END QUOTATION---



You could just do this:

local se_obj = alife(): object(npc_01_id)


---QUOTATION---
sim:set_switch_online(p_id, true)
sim:set_switch_offline(p_id, false)
---END QUOTATION---



That should work, normally.


function switch_online(id)
	if id == -1 then return end
	local sim = alife()
	if sim then
		sim:set_switch_online(id,true)
		sim:set_switch_offline(id,false)
	end
end

function switch_offline(id)
	local sim = alife()
	if sim then
		sim:set_switch_online(id,false)
		sim:set_switch_offline(id,true)
	end
end



Those are my functions I use.

What exactly do you need to do? Turn him off just one time in an update? Or are you trying to keep him off permanently until you want to turn him back on? If the latter then you need to set the switch for can_switch_online to false.

ex. se_obj:can_switch_online(false)
  21:35:26  19 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
 

Message edited by:
SacriPan
04/19/2014 22:22:36
Messages: 319
I want to be able to change a NPC's logic on the fly by script. I got that part working, but the NPC has to go offline (150m by default) to apply the new logic.

So, I need to be able to switch him offline manually, apply an other logic, and then switch him back online.


Let's say I want him to travel between 2 camps every day, I just need to change his logic by script and he will travel between camps and do what the 2 different "logic" say he should do.



---QUOTATION---
se_obj:can_switch_online(false)
---END QUOTATION---



I tried this but no joy


Also, I don't use this via an update in bind_stalker for example, but directly in my script, which is called when I press a key in the menu.
One key to spawn the NPC, an other to change his logic.
  21:53:49  19 April 2014
profilee-mailreply Message URLTo the Top
Alundaio
Sad Clown
(Resident)

 

 
On forum: 04/05/2010
 

Message edited by:
Alundaio
04/19/2014 22:01:34
Messages: 2230
Odd. This should definitely work (using function examples in above post):


	switch_offline(se_obj.id)

	local data = packet_utils.get_object_data(se_obj)
	data.custom_data = "[logic]\n cfg = scripts\\my_custom_logic.ltx"
	packet_utils.set_object_data( se_obj, data )

	switch_online(se_obj.id)



Where are you doing this?

EDIT:

Saw your edit. It may be because you are doing it from menu (The alife simulator is paused). Are you just using buttons for testing? Later you may want to do it as a condition and effect. Find any old space restrictor logic and add your on conditions to an existing sr_idle section and trigger it through on_info. Use infoportions to make sure it only happens once.

on_info = {-my_info =is_night} %+my_info =switch_my_npc_logic(name1)%
on_info2 = {+my_info !is_night} %-my_info =switch_my_npc_logic(name2)%
  22:15:25  19 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
Messages: 319
Yeah, I heard lately that a-life simulator is paused but I do it after I call the function to close the menu, and my NPC is spawned OK, and the logic is changed too (it just doesn't take effect till he's offline), so I don't believe it's the problem.


And yes, the menu keys are just for testing this rapidly
  22:19:15  19 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
 

Message edited by:
SacriPan
04/19/2014 22:21:00
Messages: 319
I understand the "+my_info" and "-my_info" part, but what does the rest does?

---QUOTATION---

-my_info =is_night
%+my_info =switch_my_npc_logic(name1)%

---END QUOTATION---

  22:29:04  19 April 2014
profilee-mailreply Message URLTo the Top
Alundaio
Sad Clown
(Resident)

 

 
On forum: 04/05/2010
 

Message edited by:
Alundaio
04/19/2014 22:31:43
Messages: 2230
Just an example if you made your own xr_effect function to trigger the logic change.

Inside brackets are condition statements and inside percents are effects. So if it is night and you do not have my_info it will trigger the logic change once when it turns night. The on_info2 statement does the opposite.
  22:37:30  19 April 2014
profilee-mailreply Message URLTo the Top
SacriPan
Senior Resident
 

 
On forum: 09/20/2009
Messages: 319
Ok thanks, I will try that. But I think I'm gonna end up with the same problem, meaning that the NPC will change logic but I doubt it will apply it right away.

I'm gonna eat and test this after, and I let you know
  22:44:28  19 April 2014
profilee-mailreply Message URLTo the Top
Alundaio
Sad Clown
(Resident)

 

 
On forum: 04/05/2010
 

Message edited by:
Alundaio
04/19/2014 22:45:45
Messages: 2230

---QUOTATION---
Ok thanks, I will try that. But I think I'm gonna end up with the same problem, meaning that the NPC will change logic but I doubt it will apply it right away.

I'm gonna eat and test this after, and I let you know
---END QUOTATION---




Let him turn himself back online. It may need an update. Switching him offline and back online in same frame won't initialize the changes needed by xr_logic.

db.storage[id].active_scheme, db.storage[id].active_section, db.storage[id].ini probably didn't change, so when you change it through the packet, it is still using what is in the storage table.
 
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.