ProjectsWhat's NewDownloadsCommunitySupportCompany
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
Spawning a NPC by a .script possible?

« Previous 10 events | 1 2 3 4 5 | Next 10 events »| All Messages
Posted by/on
Question/AnswerMake Newest Up Sort by Descending
  23:36:24  12 April 2012
profilee-mailreply Message URLTo the Top
olaf1
Senior Resident
 

 
On forum: 01/17/2012
Messages: 240
use this


local dolg_respawn_timer = 0



function spawn_dolg()
	local levels = [{1] = "l01_escape", [2] = "l02_garbage", [3] = "l03_agroprom", [4] = "l04_darkvalley", [5] = "l05_bar", [6] = "l06_rostok", [7] = "l07_military", [8] = "l08_yantar"}
	local KoordinateA = [{1] = {x = -250.32, y = -18.05, z = -127.13]
	local KoordinateB = [{1] = {x = -250.32, y = -18.05, z = -127.13]
    	local dolg = {"bar_dolg_respawn_3"}
	local level_name = level.name()
	local actor_rank = ranks.get_obj_rank_name(db.actor)
    	local Koordinate ={}
	local which_spawn = math.random(1, 2)
	local dolg_spawn = dolg[math.random(1,1)]
    	local hmnpc	= 4
if db.actor:character_community() == "military" then
    if actor_rank == "experienced" then
       hmnpc	= 4
    elseif actor_rank == "veteran" then
       hmnpc 	= 6
    elseif actor_rank == "master" then
        hmnpc	= 8
    end
	if dolg_respawn_timer == 0 then dolg_respawn_timer = level.get_time_hours() + math.random(3,4) end
	if db.actor:alive() then
        if level.get_time_hours() > dolg_respawn_timer then
            dolg_respawn_timer = 0
			for indx, lvl in pairs(levels) do
				if level_name == lvl then
				if level_name == "l01_escape" then
					for hm = 1, hmnpc do	
							if which_spawn == 1 then 
							alife():create(dolg_spawn, vector():set(KoordinateA[indx].x, KoordinateA[indx].y, KoordinateA[indx].z), db.actor:level_vertex_id(), db.actor:game_vertex_id())
								else
							alife():create(dolg_spawn, vector():set(KoordinateB[indx].x, KoordinateB[indx].y, KoordinateB[indx].z), db.actor:level_vertex_id(), db.actor:game_vertex_id())
								end
							end
					end
				end
			end
        	end
	end
end
end

  23:54:54  12 April 2012
profilee-mailreply Message URLTo the Top
insanelazarez
Yeah, Good Luck With That...
(Resident)

 

 
On forum: 01/31/2009
Messages: 1070

---QUOTATION---
Spawning a NPC by a .script possible?

Hi, I've been trying to spawn a duty member directly outside of Sid's "bunker" in Cordon.
I'm quite new to making advanced scripts so please excuse its "noobishness"

http://pastebin.com/mFPYMjr8 < This is the code which is supposed to spawn a duty member in front of Sid's bunker.

Would anyone know why it doesn't work?

I didn't edit the .spawn at all.
I thought it will be possible to spawn a duty member if a player joins a specific faction such as the military via .script only?

Here are the tutorials I used:
http://forums.filefront.com/s-t-l-k-e-r-soc-modding-mapping-editing/372535-spawning-through-script.html

http://sdk.stalker-game.com/en/index.php?title=Spawning_through_script

Thanks.

Are you interested in an alternative?

Let's pretend that is the case.

Unpacked files required:

config\scripts\esc_tutorial.ltx
xr_effects.script

1 - Open 'esc_tutorial.ltx' and change it this way:



[sr_idle@tutorial]
on_info = {+esc_tutorial_start} nil %=create_this_item_on_actor(gar_dolg_respawn_1)%



2 - Add this to 'xr_effects':



function create_this_item_on_actor(actor, npc, p)
local stuff = p[1]
local npc = db.actor

alife():create(stuff,
npc osition(),
npc:level_vertex_id(),
npc:game_vertex_id())
end



You can change the name of the item for anything you want. Weapons, spawn sections, explosive barrels, etc.

Have fun.[/quote]

Thanks for replying. I would prefer to learn how to spawn npcs via script as that way I will remember how to do it instead of copying and pasting. Ok... I made the changes to both of the files and... *NOOB MOMENT* I ran the game... Without editing your example in any way. LOL. Needless to say... It crashed. I'm confused on how its supposed to be structured. I then got my old script and pasted some bits in and I got a crash. Here's the log:

"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: ...shadow of chernobyl\gamedata\scripts\xr_logic.script:603: attempt to index global 'xr_effects' (a nil value)"

Basically it means I messed up on scripting

Here is my updated "script":

function create_this_item_on_actor(actor, npc, p)
local stuff = p[1]
local npc = db.actor
alife():create("bar_dolg_respawn_3",a.x = -250.32, a.y = -19.52, a.z = -127.17)
npc:level_vertex_id(), 1
npc:game_vertex_id(),
end

Am I doing it all wrong? :S
---END QUOTATION---



Please copy and paste my 2 codes... and make sure you also remove the smile in xr_effects. The code has to work.

The code creates a duty npc, in your position when you leave the bunker.
  23:56:29  12 April 2012
profilee-mailreply Message URLTo the Top
DutyStalker666
Senior Resident
 

 
On forum: 10/25/2011
Messages: 169

---QUOTATION---
use this


local dolg_respawn_timer = 0



function spawn_dolg()
	local levels = [{1] = "l01_escape", [2] = "l02_garbage", [3] = "l03_agroprom", [4] = "l04_darkvalley", [5] = "l05_bar", [6] = "l06_rostok", [7] = "l07_military", [8] = "l08_yantar"}
	local KoordinateA = [{1] = {x = -250.32, y = -18.05, z = -127.13]
	local KoordinateB = [{1] = {x = -250.32, y = -18.05, z = -127.13]
    	local dolg = {"bar_dolg_respawn_3"}
	local level_name = level.name()
	local actor_rank = ranks.get_obj_rank_name(db.actor)
    	local Koordinate ={}
	local which_spawn = math.random(1, 2)
	local dolg_spawn = dolg[math.random(1,1)]
    	local hmnpc	= 4
if db.actor:character_community() == "military" then
    if actor_rank == "experienced" then
       hmnpc	= 4
    elseif actor_rank == "veteran" then
       hmnpc 	= 6
    elseif actor_rank == "master" then
        hmnpc	= 8
    end
	if dolg_respawn_timer == 0 then dolg_respawn_timer = level.get_time_hours() + math.random(3,4) end
	if db.actor:alive() then
        if level.get_time_hours() > dolg_respawn_timer then
            dolg_respawn_timer = 0
			for indx, lvl in pairs(levels) do
				if level_name == lvl then
				if level_name == "l01_escape" then
					for hm = 1, hmnpc do	
							if which_spawn == 1 then 
							alife():create(dolg_spawn, vector():set(KoordinateA[indx].x, KoordinateA[indx].y, KoordinateA[indx].z), db.actor:level_vertex_id(), db.actor:game_vertex_id())
								else
							alife():create(dolg_spawn, vector():set(KoordinateB[indx].x, KoordinateB[indx].y, KoordinateB[indx].z), db.actor:level_vertex_id(), db.actor:game_vertex_id())
								end
							end
					end
				end
			end
        	end
	end
end
end


---END QUOTATION---



Doesnt work Also, I do not need re-spawning stalkers, only for a single duty stalker to spawn outside sid's bunker when I choose to join the military faction... I'm gonna try again
  00:06:27  13 April 2012
profilee-mailreply Message URLTo the Top
insanelazarez
Yeah, Good Luck With That...
(Resident)

 

 
On forum: 01/31/2009
Messages: 1070
DutyStalker666, my trick has several advantages.

1 - The space restrictor calling the tutorial is already there. So no external sources are required.

2 - You can spawn 75 stalker at the same time. Or say 3, this way:


---QUOTATION---


[sr_idle@tutorial]
on_info = {+esc_tutorial_start} nil %=create_this_item_on_actor(gar_dolg_respawn_1) =create_this_item_on_actor(gar_dolg_respawn_1) =create_this_item_on_actor(gar_dolg_respawn_1)%


---END QUOTATION---



See? The fuction now is called 3 times. And creates 3 npcs.

Just make sure you don't have any smilies in the xr_effects function.
  00:19:52  13 April 2012
profilee-mailreply Message URLTo the Top
DutyStalker666
Senior Resident
 

 
On forum: 10/25/2011
 

Message edited by:
DutyStalker666
04/13/2012 0:27:17
Messages: 169

---QUOTATION---
DutyStalker666, my trick has several advantages.

1 - The space restrictor calling the tutorial is already there. So no external sources are required.

2 - You can spawn 75 stalker at the same time. Or say 3, this way:



[sr_idle@tutorial]
on_info = {+esc_tutorial_start} nil %=create_this_item_on_actor(gar_dolg_respawn_1) =create_this_item_on_actor(gar_dolg_respawn_1) =create_this_item_on_actor(gar_dolg_respawn_1)%



See? The fuction now is called 3 times. And creates 3 npcs.

Just make sure you don't have any smilies in the xr_effects function.
---END QUOTATION---



I done what you said and I got a ctd
"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: ...shadow of chernobyl\gamedata\scripts\xr_logic.script:608: attempt to call field '?' (a nil value)

stack trace:"

I feel like I'm cursed I gotta be doing something wrong...
I crashed as soon as I got out of the bunker.
  00:51:34  13 April 2012
profilee-mailreply Message URLTo the Top
insanelazarez
Yeah, Good Luck With That...
(Resident)

 

 
On forum: 01/31/2009
Messages: 1070
DutyStalker666,

The proof:

[link]

http://www.uploadscreenshot.com/image/902530/827701

[/link]
  00:54:13  13 April 2012
profilee-mailreply Message URLTo the Top
insanelazarez
Yeah, Good Luck With That...
(Resident)

 

 
On forum: 01/31/2009
Messages: 1070
It's a copy/paste issue for sure. Unless your game version is different. But even if that is the case, it should work (in theory). I use patch 1.0004.

I can upload the minimod if you want.

Please respond.
  05:16:21  13 April 2012
profilee-mailreply Message URLTo the Top
DutyStalker666
Senior Resident
 

 
On forum: 10/25/2011
Messages: 169

---QUOTATION---
It's a copy/paste issue for sure. Unless your game version is different. But even if that is the case, it should work (in theory). I use patch 1.0004.

I can upload the minimod if you want.

Please respond.
---END QUOTATION---



I have version 1.5, perhaps this has something to do with it as single player did have some bugs fixed I would appreciate finished code so I can see what I'm doing wrong. If worst comes to worst, I will "cheat" by using the atlas spawn menu.

Thanks.
  06:33:13  13 April 2012
profilee-mailreply Message URLTo the Top
insanelazarez
Yeah, Good Luck With That...
(Resident)

 

 
On forum: 01/31/2009
Messages: 1070

---QUOTATION---
It's a copy/paste issue for sure. Unless your game version is different. But even if that is the case, it should work (in theory). I use patch 1.0004.

I can upload the minimod if you want.

Please respond.

I have version 1.5, perhaps this has something to do with it as single player did have some bugs fixed I would appreciate finished code so I can see what I'm doing wrong. If worst comes to worst, I will "cheat" by using the atlas spawn menu.

Thanks.
---END QUOTATION---




The code i used to take the screenshot of my previous post is right here:

[link]http://www.4shared.com/rar/gcJnD-vt/3_npc_for_DutyStalker666.html
[/link]

Have fun...
  06:56:43  13 April 2012
profilee-mailreply Message URLTo the Top
DutyStalker666
Senior Resident
 

 
On forum: 10/25/2011
Messages: 169

---QUOTATION---
It's a copy/paste issue for sure. Unless your game version is different. But even if that is the case, it should work (in theory). I use patch 1.0004.

I can upload the minimod if you want.

Please respond.

I have version 1.5, perhaps this has something to do with it as single player did have some bugs fixed I would appreciate finished code so I can see what I'm doing wrong. If worst comes to worst, I will "cheat" by using the atlas spawn menu.

Thanks.


The code i used to take the screenshot of my previous post is right here:

[link]http://www.4shared.com/rar/gcJnD-vt/3_npc_for_DutyStalker666.html
[/link]

Have fun...
---END QUOTATION---



Thank you Tested in game and it worked. Now I'm trying to script it so different faction members spawn (depends what faction you join):

[logic]
active = sr_idle@tutorial

if db.actor:character_community() == "military" then

[sr_idle@tutorial]
on_info = {+esc_tutorial_start} nil %=create_this_item_on_actor(gar_dolg_respawn_1) =create_this_item_on_actor(gar_dolg_respawn_1) =create_this_item_on_actor

(gar_dolg_respawn_1)%

else
if db.actor:character_community() == "zombie" then

[sr_idle@tutorial]
on_info = {+esc_tutorial_start} nil %=create_this_item_on_actor(gar_dolg_respawn_1)

end
end

I got a CTD I can't set if statements in the tutorial?
 
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-2022 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.