How to make a mod where "x happens after y in-game hours or days"?

Discussion in 'Fallout General Modding' started by banjo_oz, May 4, 2021.

  1. banjo_oz

    banjo_oz First time out of the vault

    42
    Mar 3, 2007
    I've been looking at timer functions but haven't been able to find what I needed.

    If I wanted to script something so that any time while the game is running, after a certain number of hours or days the player is given a specific perk, affected by a specific effect (say, -1 to Endurance) or a GVAR increases/decreases, what function should I use and how?

    What is the best function to use that checks time passed since it last run so I can have it do something? Is it
    Code:
    time_has_passed(old_time, passed_time)
    ? If so, how would I set it to check every so often? Is there a hook (I couldn't find one) that triggers "when time passes" or something similar?
     
  2. NovaRain

    NovaRain Casual Modder Modder

    Mar 10, 2007
    It depends on how often you want to run the check, or is it really necessary to do so (keep running the check constantly in the background).
    Usually the game scripts use critter_p_proc for constant checks because the procedure is executed repeatedly for each object. For global scripts you can use set_global_script_repeat, or sfall's add_g_timer_event to run timed_event_p_proc in global scripts.
    Example of a global script that prints time difference in ticks between each run:
    Code:
    // gl_timediff.ssl
    variable prevTime;
    
    procedure start begin
       if game_loaded then begin
          prevTime := game_time;
          set_global_script_repeat(30); // script runs every 30 frames, for ordinary 60fps it's about 0.5 second, or 5 ticks in game
       end else begin
          variable time;
          time := game_time - prevTime;
          prevTime := game_time;
          display_msg("Ticks diff: " + time); // result value should be about 5~6 ticks
       end
    end
    
     
    Last edited: May 4, 2021
  3. Lexx

    Lexx Testament to the ghoul lifespan
    Moderator Modder

    Apr 24, 2005
    I would probably just throw the code into map_update_p_proc of obj_dude and just check the current time. If current time > old time + x then .... etc.

    If you don't want to edit the obj_dude script for whatever reason, then the map_update_p_proc could also be checked in a global script. Or as NovaRain wrote above, just put the global script on repeat, but I'm not sure how certain the timer is. If you want changes to happen at a specific daytime, it's probably better to not rely on that.

    As usually, there is an example for that in the ettu scripts. I am checking for the Night Person trait via HOOK_GAMEMODECHANGE - simply because the player is often enough checking inventory and pipboy and dialog, etc. for that to be enough.