how to execute a script only at a new game?

luppolo
Scavenger
Posts: 24
Joined: 04 Nov 2016, 21:58

how to execute a script only at a new game?

Postby luppolo » 18 May 2017, 19:13

i want to spawn some items in the maps, i got the spawning code working but now i want to run it once at the start of a new game (when you pick faction and spawn position) and never again, how can i do this?

User avatar
Alundaio
S.T.A.L.K.E.R.
Posts: 1368
Joined: 26 May 2012, 22:26

Re: how to execute a script only at a new game?

Postby Alundaio » 18 May 2017, 21:50

ui_faction_select.script would be a good place.

Probably anywhere inside the if (faction and faction ~= "") then block.


coc_treasure_manager.script in on_game_load after the caches_count check is another place.


Alternatively, and probably a much cleaner way is to use your own script. Make an on_game_start function in the script and register for on_game_load. Then you can do something like this:

Code: Select all

function on_game_start()
   RegisterScriptCallback("on_game_load",on_game_load)
end

function on_game_load()
   local m_data = alife_storage_manager.get_state()
   if (m_data.custom_spawn_only_once) then
      return
   end
   m_data.custom_spawn_only_once = true
   
   
   -- your code
end


alife_storage_manager.get_state() returns a table that persists through saves.
"I have a dream that one day this community will rise up and live out the true meaning of its creed: "We hold these truths to be self-evident; that all mods are created equal."

luppolo
Scavenger
Posts: 24
Joined: 04 Nov 2016, 21:58

Re: how to execute a script only at a new game?

Postby luppolo » 19 May 2017, 20:32

thanks for the reply, this storage manager thing is very handy


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 3 guests