Scripted timers / waiting

Discussions on Modding of S.T.A.L.K.E.R. SoC & Clear Sky

Scripted timers / waiting

Postby electricfood on 28 Feb 2011 23:12

I've been trying to make a script to spawn waves of zombies for me to mow down, but I've hit a brick wall. Spawning zombies on a button press is pretty easy, but I can't figure out a way to have the script wait and spawn another wave later.

I've tried the following code, but it causes the game to hang.

Code: Select all
local next_spawn = 0
while true do
        if next_spawn < time_global() then
              -- spawn stuff
              next_spawn = time_global() + 30000
        end
end


I found a timer tutorial here, but I can't figure it out. I don't know how to make the update method get called by stalker's scripting engine. Is there a script that gets called regularly by the engine that I should edit?
electricfood
New Member
 
Posts: 3
Joined: 28 Feb 2011 22:18

Re: Scripted timers / waiting

Postby electricfood on 01 Mar 2011 14:51

I did some more searching around and found the file "bind_stalker.script". If anyone else is interested, add a call to your scripts own update function into the function actor_binder:update to make stalker call it regularly.
electricfood
New Member
 
Posts: 3
Joined: 28 Feb 2011 22:18

Re: Scripted timers / waiting

Postby Nightwatch on 01 Mar 2011 22:46

It must have been a case of bad luck on your part, electricfood in respect of this timer work, as you say that you've been able to activate the discarded zombies and spawn them with a button hit (I take that you mean "binding the function to a keyboard key" -or, was it authoring a pop-up box with a radio button? But this is not that important) so you must be able to write a timer rather easily, and I'm sure that you will do that in no time (even if you haven't already done so) when you've read the article that you refer to on S.T.A.L.K.E.R. MOD portal just once again, as that article is a brilliant work -and very detailed- to describe the function that you're asking and I could put it only that much.
Answer is over there, in detail. Just read it carefully, you must've missed something possibly.

Also, just from a technical point of view, the script piece that you quote, which you forgot to mention where you put it and from whom you've got it -as the author's instructions still remains embedded- would not work like that. As you would know " -- " is a commenting out order and after it, the author of the script tells you to "spawn stuff" there, at that section. By "stuff" he of course means that anything that you want to spawn which is spawnable. I painted RED the commented out instruction part in your quote, in which you are asked to spawn things.


electricfood wrote:I've been trying to make a script to spawn waves of zombies for me to mow down, but I've hit a brick wall. Spawning zombies on a button press is pretty easy, but I can't figure out a way to have the script wait and spawn another wave later.

I've tried the following code, but it causes the game to hang.

==========================================================
local next_spawn = 0
while true do
if next_spawn < time_global() then
-- spawn stuff !_HERE you are asked to spawn the things that you want_! And then remove the comment out, of course.
next_spawn = time_global() + 30000
end
end
==========================================================
I found a timer tutorial here, but I can't figure it out. I don't know how to make the update method get called by stalker's scripting engine. Is there a script that gets called regularly by the engine that I should edit?


In that part, you must put your spawning script. I mention this just for a general point. You need to follow the article, it's a best written answer. I know the guy who wrote it, and you should take his word. :mozilla_smile:
NEWSA.SIMBION_TWEAK 3.0
Mod Website= Features, Video, Tips & Download Link: NEWSA.SIMBION_Tweak

Watch the Trailer: http://www.youtube.com/watch?v=1Ajw_f8K ... re=channel
Please Do Not download and install any files from links other than those on the Mod's Website
User avatar
Nightwatch
Site Admin
 
Posts: 2676
Joined: 13 Apr 2007 05:42
Location: London, United Kingdom

Re: Scripted timers / waiting

Postby electricfood on 02 Mar 2011 00:21

I should clarify; the code I quoted and it's comment are both mine, it's just an illustration of what I had tried so I didn't try to make in complete or give full details. My actual script did have code to spawn monsters where the comment is. However, this is the internet, so I don't see any point in arguing about it :P.

I don't mean to knock the article, having done some further research it makes much more sense now and I've implemented something like the timer they give there to form my script. I see why you rate it so highly, but when I read it first it was not clear to me how to get the timer to actually link in with other scripts. What I did in the end was add a line to bind_stalker.script to call my timer's update function, which I assume is what the author intended, but this in not mentioned anywhere in the article. Pointing the reader toward the bind_*.script files would be beneficial to the article, in my opinion.

That wiki has a lot of potential, it's the only decent source of stalker scripting advice I've been able to find. Its a shame that a game that has been so popular for modders still has such a lack of good reference material.
electricfood
New Member
 
Posts: 3
Joined: 28 Feb 2011 22:18

Re: Scripted timers / waiting

Postby VINTAR on 03 Mar 2011 14:37

Just to give you an alternative to the hugely confusion timer class :
Code: Select all
-- gamedata\scripts\timer.script

local spawn_time_factor = 30000
local last_spawned = nil

function update()
  if db.actor then
   if last_spawned == nil then
      last_spawned = get_current_time()
   end
   if get_current_time() >= (last_spawn + spawn_time_factor) then
      --spawn my stuff
             last_spawned = get_current_time()
   end
  end
end
   
function get_current_time()
   return (level.get_time_days() * 86400 + level.get_time_hours() * 3600 + level.get_time_minutes() * 60)
end

function save(packet)
   packet:w_float(last_spawned_time)
end

function load(reader)
   last_spawned = reader:r_float()
end

-----------------------------------------------------------------------------------
-- gamedata\scripts\bind_stalker.script

--in function actor_binder:update(delta)

timer.update()

--in function actor_binder:save(packet)

timer.save(packet)

--in function actor_binder:load(reader)

timer.load(reader)

--------------------------------------------------------------------------------------
Core2Quad Q8300 2.5 @ 3.6ghz
Cooler Master Hyper TX 2 CPU cooler
Gigabyte EP45 UD3R mobo
Nvidia GTS450
2 GIGS Transcend DDR2 800 pc6400 @ 960
Thermaltake Tough Power 650w PSU
Samsung Syncmaster P2350
-----------------------------------
Apartheid veteran
User avatar
VINTAR
Senior Resident
 
Posts: 441
Joined: 18 Sep 2008 15:07
Location: Durban, South Africa


Return to Modding Techniques

Who is online

Users browsing this forum: No registered users and 18 guests

cron