How is the chance to jam a lock determined?

Discussion in 'Fallout General Modding' started by PinkEraser44, Jan 18, 2023.

  1. PinkEraser44

    PinkEraser44 First time out of the vault

    19
    Jul 9, 2022
  2. gustarballs1983

    gustarballs1983 Vault Senior Citizen
    Modder

    Oct 28, 2009
    I think you should look in to lock scripts, or door, locker, footlocker scripts with locked locks.. i don't think it's a hardcoded feature, at least in fo2 engine...

    from what i remember when discussing the matter years back, it was indeed a form of crit fail on lockpick skill check with some kind of dice roll. the outcom could have various effects like breaking a set of lockpicks, finger injury ( minor hp loss if lockpicking without lockpicks), jamming the lock was the most severe as i can remember. it had greater chances depending on lock complexity, ( higher skill check), and player lockpick skill %

    so if skill check was waay higher than player's skill it gave greater chances of breaking or jamming the lock, and only 5% to open it via criticall success ( in some cases even crit succes wasn't guaranteed to open the lock).

    perhaps @Lexx knows more on this
     
    Last edited: Jan 18, 2023
  3. PinkEraser44

    PinkEraser44 First time out of the vault

    19
    Jul 9, 2022
    Thank you gustarballs, that was very helpful.

    As you said, the locked container scripts clearly indicate that a jammed lock is caused by a critical failure.

    From an example locked container: https://fallout.fandom.com/wiki/CREDDOOR.INT
    Code:
    procedure use_skill_on_p_proc
    begin
            variable LVar0 := 0;
            if (local_var(0) == 0) then begin
                    if (action_being_used == 9) then begin
                            script_overrides;
                            LVar0 := roll_vs_skill(dude_obj, 9, -60);
                            if (is_success(LVar0)) then begin
                                    set_local_var(0, 1);
                                    display_msg(message_str(63, 100));
                                    display_msg(message_str(766, 103) + "85" + message_str(766, 104));
                                    give_exp_points(85);
                            end
                            else begin
                                    if (is_critical(LVar0)) then begin
                                            jam_lock(self_obj);
                                            display_msg(message_str(63, 110));
                                    end
                                    else begin
                                            display_msg(message_str(63, 103));
                                    end
                            end
                    end
            end
            else begin
                    display_msg(message_str(63, 109));
            end
    end
    

    I think the following engine code determines critical success or critical failure?
    https://github.com/alexbatalov/fall...78dc8720739b2f740a319df99a542/src/game/roll.c

    Code:
    // Rolls d% against [difficulty].
    //
    // 0x4A3000
    int roll_check(int difficulty, int criticalSuccessModifier, int* howMuchPtr)
    {
        int delta = difficulty - roll_random(1, 100);
        int result = roll_check_critical(delta, criticalSuccessModifier);
    
        if (howMuchPtr != NULL) {
            *howMuchPtr = delta;
        }
    
        return result;
    }
    
    // Translates raw d% result into [Roll] constants, possibly upgrading to
    // criticals (starting from day 2).
    //
    // 0x4A3030
    int roll_check_critical(int delta, int criticalSuccessModifier)
    {
        int gameTime = game_time();
    
        int roll;
        if (delta < 0) {
            roll = ROLL_FAILURE;
    
            if ((gameTime / GAME_TIME_TICKS_PER_DAY) >= 1) {
                // 10% to become critical failure.
                if (roll_random(1, 100) <= -delta / 10) {
                    roll = ROLL_CRITICAL_FAILURE;
                }
            }
        } else {
            roll = ROLL_SUCCESS;
    
            if ((gameTime / GAME_TIME_TICKS_PER_DAY) >= 1) {
                // 10% + modifier to become critical success.
                if (roll_random(1, 100) <= delta / 10 + criticalSuccessModifier) {
                    roll = ROLL_CRITICAL_SUCCESS;
                }
            }
        }
    
        return roll;
    
    So as you said, a critical failure is more likely when the delta between your skill and what the computer rolled is very large.

    But I'm not sure I exactly understand the code.

    If lockpick skill is 30, the lockpick difficulty is -20 and the game rolls a 100, I think roll_check() would set delta equal to 90.

    delta=30-100-20=30-120=-90

    And if roll_check_critical() had a delta of -90 and a random number of 50, I think roll_check_critical() would say it would NOT be a critical failure.

    if (roll_random(1, 100) <= -delta / 10)

    if (50 <= -(-90)/10)

    if (50 <= 9)

    Therefore this if conditional is false leads to a regular failure and not a critical failure.

    Am I reading the code correctly?
     
  4. gustarballs1983

    gustarballs1983 Vault Senior Citizen
    Modder

    Oct 28, 2009
    All I told you was from a conversation with @Lexx i had waays back on this matter. Personally I'm not a programer, so I can't tell you anything for certain.

    ask @Lexx He knows more on this stuff.

    though do bare in mind that the game gives the player an ability to modify the hit Jinxed triat is -50 to the roll. havy handed is -25 to crit severity . and better criticals is +20 to crit severity table only.

    so by picking a char with lk1 jinxed and heavy handed you'll have 55% chance to roll a crit failiure and +25 greater chance to roll the worse possible outcome of the crit failure, on the crit severity table.

    by picking a char with sniper and lk10 you never have to worry about critically missing a shot as you'll always roll crit succes.
     
    Last edited: Jan 20, 2023
  5. NovaRain

    NovaRain Casual Modder Modder Moderator

    Mar 10, 2007
    Jinxed only affects the roll result in combat when an attack misses. The same goes for Better Criticals, it only affects the roll result for critical hits in combat. The two don't affect anything outside of the combat, like the lock jamming here.
     
  6. PinkEraser44

    PinkEraser44 First time out of the vault

    19
    Jul 9, 2022
    Thanks all, much appreciated!