ProjectsWhat's NewDownloadsCommunitySupportCompany
Forum Index » S.T.A.L.K.E.R.: Shadow of Chernobyl Forum » Mod discussion
spawning through a script help

1 2 3
Posted by/on
Question/AnswerMake Newest Up Sort by Descending
  16:51:33  20 February 2013
profilee-mailreply Message URLTo the Top
Rattertat
(Novice)
 
On forum: 02/20/2013
Messages: 4
spawning through a script help

Hello stalkers,

I have been checking the forums for some time, but now need a little help with scripting. I have been using the spawning through a script wiki and have been able to spawn using this example script with a function I added matched to a action from selecting a text in the xml during sids first conversation:

Question, it does not say in the Wiki, but what do these #'s mean a,13193,8,65535 ? in this line ("bar_dolg_respawn_3",a,13193,8,65535)

local a = vector() -- Set variable type
a.x = -243.61 -- X coordinate
a.y = -19.52 -- height Y
a.z = -127.17 -- Z coordinate

local obj = alife():create("bar_dolg_respawn_3",a,13193,8,65535)
alife():create_ammo("ammo_9x18_fmj",
obj osition(),
obj:level_vertex_id(),
obj:game_vertex_id(),
obj:id(),
20) -- number of bullets

I have been playing with spawning different NPC’s and so on and it is really cool!

I know want to move onto this script and try to spawn lots of zombies. I do not understand what actually needs to go into the script though there is a lot of info here and the example files go to a dead link.

I want to spawn right outside sids bunker just to see if It works, the coordinates are -240.57, -18.06, -128.62. Will use a function again from a selection text.

Would someone be able to write out for me what the end script should look like from the example? I am confused how it should look in the end and have been trying many combinations, but nuthing works.

Thank you to anyone who can help with questions and explaining.

It says to do this first

local zombie_types = {"zombie_weak", "zombie_normal", "zombie_strong", "zombie_immortal", "zombie_ghost"}

Then this

function spawn_zombies( position, total )
local zombie_index -- zombie type from zombie_types array
local new_pos, x_offset, z_offset -- declare variables
for zombie_index=1, total do -- spin the loop the number of times given by the variable "total"
x_offset = math.random(5) -- random x between 1 and 5
z_offset = math.random(5) -- random z between 1 and 5
new_pos = position -- transfer the coordinates to a function
new_pos.x = new_pos.x + x_offset -- add the random x to the x coordinate
new_pos.z = new_pos.z + z_offset -- add the random z to the z coordinate
-- below we call the function of random zombie spawn itself for zombie_types[math.random(5)] tied to our coordinates
alife():create(zombie_types[math.random(5)], new_pos, db.actor:level_vertex_id(), db.actor:game_vertex_id())
end
end

This is last

function zomby_story_1( actor, npc )
-- ten zombies at the plant
local spawn_point = vector():set( 115, -6, -16 ) -- here we specify the coordinates we got while "flying"
spawn_zombies( spawn_point, 10 ) -- here is the call of the previous function itself, giving it the coordinates and the number of objects
end
  19:53:49  20 February 2013
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
 

Message edited by:
ThunderFreak
02/20/2013 19:54:56
Messages: 685
Check this out. It works.

local zombie_types = {"zombie_weak", "zombie_normal", "zombie_strong", "zombie_immortal", "zombie_ghost"}
local zombie_IDs = {}
function spawn_zombies()
	local zombie_nr = #zombie_IDs or 0		-- Check if some zombies still "alive"
	if zombie_nr > 0 then
		local z_obj
		for i=1,zombie_nr do
			obj = level.object_by_id(zombie_IDs[i])	-- Check which zombies are relally dead :-D
			if obj == nil then
				zombie_IDs[i] = nil		-- Delete array entry
			end
		end
		return							-- Return as long as zombies alive
	end
	
	-- Spawn new zombies if all other zombies are gone
	local new_pos = vector():set(-240.57, -18.06, -128.62)
	local lvid = db.actor:level_vertex_id()
	local gvid = db.actor:game_vertex_id()
	local spid
	for i=1,10 do
		new_pos.x = new_pos.x + math.random(5)
		new_pos.z = new_pos.z + math.random(5)
		spid = alife():create(zombie_types[math.random(4)], new_pos, lvid, gvid)
		zombie_IDs[i] = spid.id
	end
end


Zombies are spawned in front of sidos bunker. I extended your script a little bit. Checking if zombies are alive and if not spawn again.

Keep the rookies busy.
  21:31:21  20 February 2013
profilee-mailreply Message URLTo the Top
Rattertat
(Novice)
 
On forum: 02/20/2013
 

Message edited by:
Rattertat
02/21/2013 6:14:30
Messages: 4
Wow! Thank you so much, it works!! Very awesome!!

A couple questions if you dont mind Thunderfreak.

Can I use this as a template to spawn other monsters using different coordintaes and function command linked to an action in XML?

1 other thing, I have added back monster parts and set prob. to .4 for zombie hand, but all zombies that are spawned have in their inventory, do you know why that is?

Thank you so much again
  13:46:25  21 February 2013
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
Messages: 685
I have a better idea. Check out my skydrive, there is a mini mod called Ueberfaelle. You can use this one, if you like.

https://skydrive.live.com/#cid=839FA75832089767&id=839FA75832089767!268

This mini mod starts military raids in the zone. There are 2 spawn points in each level. You can replace the soldiers with what you like i.e. bandits, monsters and so on or a combination of all.
  20:40:06  21 February 2013
profilee-mailreply Message URLTo the Top
insanelazarez
Yeah, Good Luck With That...
(Resident)

 

 
On forum: 01/31/2009
Messages: 1070

---QUOTATION---
Ueberfaelle
---END QUOTATION---



Ok, ThunferFreak... about your 'Ueberfaelle', you have a spawn section with the name 'pri_respawn_military'. This section has 'custom_logic' for pripyat. Spawning them in other maps... the game will break. It's a matter of time.


You should replace them... by other soldiers.

Just saying...
  20:43:34  21 February 2013
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
 

Message edited by:
ThunderFreak
02/21/2013 21:43:01
Messages: 685
Thanks, Insanelazarez. I'll take a look.

EDIT: You're right. Kick them out.
  05:27:14  25 February 2013
profilee-mailreply Message URLTo the Top
Rattertat
(Novice)
 
On forum: 02/20/2013
Messages: 4
Hi Thunder, thank you very much for writting the script out again. I have been testing it alot and am not sure if a bug. I sometimes get 1 zombie or maybe 10, sometimes I also get 0. It is very random, how do I set an exact number, like 10 or 5, etc... I have tried changing some variables in
the script, but either nothing happens or I crash...

Thank you for the link to your other scripts/mods, but I need to take baby steps and want to learn from the one you posted before I start going crazy
  17:12:07  25 February 2013
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
Messages: 685
Did you change something on the script example I posted?

The number of spawns cannot be random. The spawn amount is set to 10.

for i=1,10 do

Add a "debug" line after the line
zombie_IDs[i] = spid.id

to see how many zombies are really spawned.
The debug line is
dbglog("ID %s is spawn number %s",tostring(zombie_IDs[i]),tostring(i))


When you finish the game then you will see in the game log file how many zombies has been spawned on each spawn action.
Hope that helps.
  20:09:28  25 February 2013
profilee-mailreply Message URLTo the Top
insanelazarez
Yeah, Good Luck With That...
(Resident)

 

 
On forum: 01/31/2009
 

Message edited by:
insanelazarez
02/25/2013 20:10:47
Messages: 1070

---QUOTATION---
Did you change something on the script example I posted?

The number of spawns cannot be random. The spawn amount is set to 10.

for i=1,10 do

Add a "debug" line after the line
zombie_IDs[i] = spid.id

to see how many zombies are really spawned.
The debug line is
dbglog("ID %s is spawn number %s",tostring(zombie_IDs[i]),tostring(i))


When you finish the game then you will see in the game log file how many zombies has been spawned on each spawn action.
Hope that helps.
---END QUOTATION---



Well, he is creating items by script... so he might see 7 zombies only... and in the next test... kazaam 9 zombies. And this without considering how fast or slow his system is. It's important see... cause the script never produces the spawn in the same place. Sometimes you want a zombie to spawn 100 metters from you, but... no, he is spawning 3 metters from you. That is 97 metters from the position you want him to spawn. That's one of the reasons why i only add creatures by all.spawn. But i use new functions too, of course i do. In special new functions to allow npcs to create... some item close of their position... but the spawn of the creature itself... must be added by all.spawn. It's the only accurate way to spawn a creature... in position x,y,z. The position will always be the same.
  22:09:09  25 February 2013
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
Messages: 685
Almost all my spawns I do with script spawn. Never had the problem you described. The items, monsters, zombies and so on always appeared at the spawn coordinates.
And in his script the difference to the spawn point is max. 5 meters.
  05:49:52  26 February 2013
profilee-mailreply Message URLTo the Top
Alundaio
Sad Clown
(Resident)

 

 
On forum: 04/05/2010
Messages: 2230
There is not much difference between spawning by script or from the all.spawn. There is no magical thing that makes spawns random or randomly in different locations unless the script itself does it. The only issue I see where an NPC wouldn't spawn at a given position is if it's an invalid vertex id. If the spawn count is doubling after reloads that means you need to store the ids of the created objects to persist through saves.

It's entirely safe and healthy to spawn by script. In Call of Pripyat, for example, that's the only way NPCs are spawned.
  17:25:31  26 February 2013
profilee-mailreply Message URLTo the Top
insanelazarez
Yeah, Good Luck With That...
(Resident)

 

 
On forum: 01/31/2009
Messages: 1070

---QUOTATION---
There is not much difference between spawning by script or from the all.spawn. There is no magical thing that makes spawns random or randomly in different locations unless the script itself does it. The only issue I see where an NPC wouldn't spawn at a given position is if it's an invalid vertex id. If the spawn count is doubling after reloads that means you need to store the ids of the created objects to persist through saves.

It's entirely safe and healthy to spawn by script. In Call of Pripyat, for example, that's the only way NPCs are spawned.
---END QUOTATION---



Well, if the spawn script has an issue that is a problem. But consider this...

On purpose lets create a npc via all.spawn but on a invalid location... result the game will crash. And why... because the spawn location is invalid. Test it again... and again will crash. And so on.

Now keep the coordenates and delete the all.spawn. Now create a 'Magic script' to produce the same npc... in the same coordenates.

Start a new game... and remember the location is still invalid... but now in 50% of the tests... the game wont crash at all. Why? Does this mean the 'Magic Script' is better than all.spawn? For some modders, maybe. For me it just means one thing, the 'Magic Script' is not creating the npc where it should... at all. For some reason the game doesn't crash. This is easy to understand.

I know in cop the spawns are generated by script. And result is one hell of a mess.

Cop game files here... actor in zaton:

;zat_a1_logic.ltx


---QUOTATION---


[logic]
active = sr_idle@game_start

[sr_idle@game_start]
on_info = {=actor_on_level(zaton)} sr_idle@game_start_2 %=damage_actor_items_on_start%

[sr_idle@game_start_2]
on_info = sr_idle@timer %+zat_a1_game_start%

[sr_idle@timer]
on_game_timer = 3000 | sr_idle@free %+zat_a1_simulation_start%
on_info = {+about_skadovsk_dialog_done -zat_a2_reach_base} %+zat_a2_reach_base =give_task(zat_a2_reach_base)%
on_info2 = {-zat_a2_reach_base =actor_in_zone(zat_a2_sr_noweap)} %+about_skadovsk_dialog_done +zat_a2_reach_base%
on_info3 = {-zat_a2_reached_skadovsk =actor_in_zone(zat_a2_sr_noweap)} %+zat_a2_reached_skadovsk =scenario_autosave(st_save_zat_a2_reached_skadovsk)%


---END QUOTATION---



Remember the lag when the game starts? Take a good guess... '+zat_a1_simulation_start'... the info is checked by 'zat_sim_29.ltx'


---QUOTATION---

[spawn_stalker@novice]
spawn_squads = stalker_sim_squad_novice
spawn_num = {+zat_a1_simulation_start -zat_b28_heli_3_searched -zat_b100_heli_2_searched -zat_b101_heli_5_searched} 4, 0

[spawn_stalker@advanced]
spawn_squads = stalker_sim_squad_novice, stalker_sim_squad_advanced
spawn_num = {+jup_b218_pripyat_group_gathering} 0, {+zat_a1_simulation_start +zat_b28_heli_3_searched} 4, {+zat_a1_simulation_start +zat_b100_heli_2_searched} 4, {+zat_a1_simulation_start +zat_b101_heli_5_searched} 4, 0

[spawn_stalker@master]
spawn_squads = stalker_sim_squad_advanced, stalker_sim_squad_advanced, stalker_sim_squad_veteran
spawn_num = {+zat_a1_simulation_start +jup_b218_pripyat_group_gathering} 4, 0


---END QUOTATION---



So in 3 seconds the game, is creating npcs assigned to smart terrains (the smart terrains... you know... the worst feature of the stalker games... duh!!!).

And this doesn't include the 'auto save' feature enabled. How many times the game crashes when you load an auto save? It's like 70% ctds, maybe more.

I like to create things by script too... like this:


---QUOTATION---


[sr_idle@game_start_2]
on_info = sr_idle@timer %=spawn_npc_in_zone(scientific_outfit:zat_a2_sr_noweap) +zat_a1_game_start%


---END QUOTATION---




See? We have a nice suit in that location now... but a suit is just a suit. Unless you have a smart terrain for it ahahaha...

People don't like all.spawn because it is time consuming... and it's easier to use a 'Magic script'... to create squads... for smart terrains (and other things).

And btw, you can create npcs by all.spawn too... but the 'spawn condition function' (if present) was changed by gsc. And it becomes obsolete, the item will spawn always from the start. Some 'Magic Scripter' decided that the function 'to spawn an npc if a condition is present'... is not good, WOW!!!

To compensate us... gsc gave us a nice autosave feature, for 3 seconds later to recreate some very nice... smart terrains, ahahah.

My post reflects an opinion, in this case... my opinion.

Well, i just added a coop npc to my 'Stalker survival' game mode.

Here...

[link]

http://www.youtube.com/watch?v=43zqU-qC4_I

[/link]

But believe, or not the hostile waves are created by script... and i have an autosave feature too (betwen waves of course). Do you see any lag?

Well, that's it...
  17:56:41  26 February 2013
profilee-mailreply Message URLTo the Top
Alundaio
Sad Clown
(Resident)

 

 
On forum: 04/05/2010
Messages: 2230
The long load times in Call of Pripyat isn't due to script spawning it's because the levels are much larger and that the gulag is generated from scratch.
  18:19:18  26 February 2013
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
 

Message edited by:
ThunderFreak
02/26/2013 18:19:55
Messages: 685
There are reasons to use the all.spawn but there are also reasons to use a 'Magic Script'. Specially when it comes to dynamic features, then you are forced to use Magic Scripts. (I like that name - Magic Script. Sounds cool. I am serious. )
In my ShoC mod project 'Project Invasion' i have dynamic anomalies which means after every blowout the anomalies disappear from their current position and appear again on a totally different position. This can be done only by a Magic Script. If you like I can give you much more examples when it's better to use a spawn script or when you can't use the all.spawn.
  20:45:32  26 February 2013
profilee-mailreply Message URLTo the Top
insanelazarez
Yeah, Good Luck With That...
(Resident)

 

 
On forum: 01/31/2009
Messages: 1070

---QUOTATION---
The long load times in Call of Pripyat isn't due to script spawning it's because the levels are much larger and that the gulag is generated from scratch.
---END QUOTATION---




I never said anything about loading times, mate.
  21:21:57  26 February 2013
profilee-mailreply Message URLTo the Top
insanelazarez
Yeah, Good Luck With That...
(Resident)

 

 
On forum: 01/31/2009
Messages: 1070

---QUOTATION---


I like that name - Magic Script. Sounds cool. I am serious...


---END QUOTATION---



You are welcome... and i am serious too...

But i also think all.spawn, deserves a new name:

All.spawn definition:

'Non Dynamic Crappy File - Should be Deleted by Magician after update'

In fact why not create a mod where you move the all.spawn... to the recycle bin? I mean... nobody is using it, right?

Imagine the Magic we can do if we delete the 'Non Dynamic Crappy File'. See? We already have HDDs with 5TB... but 4.5 Mb more is always a good idea. We can always call it... Magic.

Duh...

Guys, i am messing around... but like i said in the my previous post... it was just an opinion.

Btw, you can't move anomalies via all.spawn... only because the script support for that doesn't exist. We just need to create it. I mean, to open a locked door you need a key. It doesn't mean the door (or the key) are bad. Both things are required.

If you guys, don't agree with me... well... you can always blame that guy from youtube...

[link]http://www.youtube.com/watch?v=A-H_AJPrhL8[/link]

Disclaimer:

No 'Magic Script' or 'Non Dynamic Crappy File' were used to upload the previous video. Only 'Firefox'...

You're Welcome...
  12:18:30  27 February 2013
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
Messages: 685
Now he got it wrongly. What I tried to say is not every thing can be done with the all.spawn. For dynamic stuff you need a script. That's all what I tried to say.
  12:45:35  27 February 2013
profilee-mailreply Message URLTo the Top
Alundaio
Sad Clown
(Resident)

 

 
On forum: 04/05/2010
Messages: 2230
It's fine you want to use the all.spawn, nothing wrong with that. But you were making silly claims about spawning by script being random and laggy.
  16:53:33  27 February 2013
profilee-mailreply Message URLTo the Top
Rattertat
(Novice)
 
On forum: 02/20/2013
Messages: 4
Hi ThunderFreak, ok I have found the issue I think. I had a script for making bolts limited and I think for what ever reason that was messing up the spawn scripts. I removed that from my game and now the spawn scripts work great. I loaded and reloaded many many many time to test. The zombies spawn in the same place each time with the correct number . I have now used that script as a template to spawn chimeras too!!! I tested that many many time and it works great.

One more thing I would like to know if possible. Rather then making the script from a function (like when I select a text when talking to a NPC) is it possibloe to spawn a monster when entering a level? Is that more complicated to write out?

Thank you very much
  17:05:46  27 February 2013
profilee-mailreply Message URLTo the Top
insanelazarez
Yeah, Good Luck With That...
(Resident)

 

 
On forum: 01/31/2009
Messages: 1070

---QUOTATION---
It's fine you want to use the all.spawn, nothing wrong with that. But you were making silly claims about spawning by script being random and laggy.
---END QUOTATION---



Sorry, but it's a fact the things get messy by script. For some reason i use the all.spawn. Consider this... create a medkit by script somewhere. Make sure you memorize the position and repeat the spawn after say 15 seconds... is the second medkit in the same spot? And the coordenates are the same... so... why?

Btw, you guys are actually modding the all.spawn? I mean you guys actually tried to mod it? The point is, if a modder uses both techniques all.spawn and scripts... it should be pretty obvious the things with script are faster and easier. But everything gets messy. But if spawning by script is the only process you use... there's no comparison possible.

Lets face it, if we don't change all.spawn... how can we confirm someone's theory about using it? Jesus Christ...
  19:04:36  27 February 2013
profilee-mailreply Message URLTo the Top
Alundaio
Sad Clown
(Resident)

 

 
On forum: 04/05/2010
 

Message edited by:
Alundaio
02/27/2013 19:06:01
Messages: 2230
I love how you are freaking out for absolutely no reason. Calm down.
  20:08:09  27 February 2013
profilee-mailreply Message URLTo the Top
ThunderFreak
Senior Resident
 

 
On forum: 08/07/2009
Messages: 685

---QUOTATION---
... One more thing I would like to know if possible. Rather then making the script from a function (like when I select a text when talking to a NPC) is it possibloe to spawn a monster when entering a level? Is that more complicated to write out?

Thank you very much
---END QUOTATION---


It's more or less the same like to spawn something in front of Sido's bunker.
The only thing you to do before the spawn is to check if the actor is the particular level.
  22:14:24  27 February 2013
profilee-mailreply Message URLTo the Top
insanelazarez
Yeah, Good Luck With That...
(Resident)

 

 
On forum: 01/31/2009
Messages: 1070

---QUOTATION---
I love how you are freaking out for absolutely no reason. Calm down.
---END QUOTATION---



Aha... wow. I don't think anyone is freaking out at all. It's just a matter of opinion.
  22:20:50  27 February 2013
profilee-mailreply Message URLTo the Top
gannebamm
has abondened XRay and uses Unity3D now
(Resident)

 

 
On forum: 05/02/2007
Messages: 1077
hey insanelazarez, whats up? You seem to be quite touched by those scripters here, he?
Try to do not get them wrong here, they did not want to attack you in any way.
As said, both ways could do the trick. All.spawn is sometimes easier to implement, scripting could be more dynamic and powerful. For standart tasks it is more a matter of taste than a matter of functionality. If you are familiar with the all.spawn, than you really should use that. If you know LUA and are familier with the XRay LUA (kind of) API, than it could be better to use that.

---QUOTATION---
it should be pretty obvious the things with script are faster and easier. But everything gets messy.
---END QUOTATION---


You know me, i wouldn´t lie to you. This is just not true. If you know what you do in LUA nothing gets messy. In fact even if you do not know what you do (but are a good copy and paster) it not has to get messy - just take a look at aliVe´s spawn scripts they are messy as hell but the spawns done with them work fine.


(for those good scripters out there, if you want to look at really shitty code you should dl aliVe and take a look at the scripts)
  15:54:47  28 February 2013
profilee-mailreply Message URLTo the Top
Meltac
messing with code
(Resident)

 

 
On forum: 01/21/2010
Messages: 1519

---QUOTATION---
(for those good scripters out there, if you want to look at really shitty code you should dl aliVe and take a look at the scripts)

---END QUOTATION---



TBH it's already sufficient to look into the vanilla scripts concerning this matter
  18:17:37  28 February 2013
profilee-mailreply Message URLTo the Top
insanelazarez
Yeah, Good Luck With That...
(Resident)

 

 
On forum: 01/31/2009
Messages: 1070

---QUOTATION---
hey insanelazarez, whats up? You seem to be quite touched by those scripters here, he?
Try to do not get them wrong here, they did not want to attack you in any way.
As said, both ways could do the trick. All.spawn is sometimes easier to implement, scripting could be more dynamic and powerful. For standart tasks it is more a matter of taste than a matter of functionality. If you are familiar with the all.spawn, than you really should use that. If you know LUA and are familier with the XRay LUA (kind of) API, than it could be better to use that.
it should be pretty obvious the things with script are faster and easier. But everything gets messy.
You know me, i wouldn´t lie to you. This is just not true. If you know what you do in LUA nothing gets messy. In fact even if you do not know what you do (but are a good copy and paster) it not has to get messy - just take a look at aliVe´s spawn scripts they are messy as hell but the spawns done with them work fine.


(for those good scripters out there, if you want to look at really shitty code you should dl aliVe and take a look at the scripts)

---END QUOTATION---



Hello gannebamm, everything ok? Well, i am not 'touched by those scripters' at all. You know i use new functions, and you (among others) helped me several times with some of those functions. But for creating items in game on a final mod release, the stability is better by all.spawn, that didn't change. But the game needs scripts, like it needs textures, models, etc.

That's it... hey... Gannebamm, check this out:

[link]

http://www.youtube.com/watch?v=QZ7zgeAsyc0

[/link]

I like to play with bandits, but i must tweak the 'Ara' Group... cause once in combat they are way too bad. Poor bastards. Lol.
 
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.