Page 1 of 1

how to execute a script only at a new game?

Posted: 18 May 2017, 19:13
by luppolo
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?

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

Posted: 18 May 2017, 21:50
by Alundaio
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.

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

Posted: 19 May 2017, 20:32
by luppolo
thanks for the reply, this storage manager thing is very handy