Weapon reducing AC - possible?

Discussion in 'Fallout General Modding' started by burn, Nov 13, 2015.

  1. burn

    burn A Smooth-Skin
    Modder

    626
    Apr 22, 2012
    Some ammo reduces target's AC. I was wondering if the same is possible (or possible to emulate effectively) for the weapon itself.
     
  2. Magnus

    Magnus Water Chip? Been There, Done That
    Modder

    953
    Dec 6, 2007
    To my knowledge, not without scripting. You can give weapons higher hit chance, but not make them lower AC.

    You can however make a hook script that reduces AC whenever a certain weapon is equipped.
     
    • [Like] [Like] x 1
  3. burn

    burn A Smooth-Skin
    Modder

    626
    Apr 22, 2012
    Reduces AC of the target? That would affect all combatants, then?
     
  4. Magnus

    Magnus Water Chip? Been There, Done That
    Modder

    953
    Dec 6, 2007
    Yes, unless you also filter out only certain targets in the script. Likewise, when enemies use that weapon against you, your AC will be reduced for the purpose of calculating their hit chance with that weapon. This is assuming you're editing a hook script that affects all critters, some affect only the player.

    This will break compatibility with other weapon mods, but I have a feeling you know that.
     
    • [Like] [Like] x 1
  5. burn

    burn A Smooth-Skin
    Modder

    626
    Apr 22, 2012
    I'm not sure.. I trying to grasp the system yet.

    I assume that I should modify hs_tohit.int, right? Or, I should create a new script and assign it to weapon's PRO offset 0x001C?

    In sfall's hookscripts.txt is says "Runs after the hit chance is fully calculated normally, including applying the 95% cap". So if I just add target's AC to that and return, will that be fine? Or should I apply the cap myself again?
     
  6. burn

    burn A Smooth-Skin
    Modder

    626
    Apr 22, 2012
    Also, I'm not seeing weapon in args to hs_tohit. How can I determine the current weapon?
    I could check if the weapon is in hands, but as far as I understand, that will provide to hit bonus even when it's in off hand.
     
  7. Magnus

    Magnus Water Chip? Been There, Done That
    Modder

    953
    Dec 6, 2007
    Call the function to get the current weapon of the attacking critter.
     
  8. burn

    burn A Smooth-Skin
    Modder

    626
    Apr 22, 2012
    Yeah... which one is it?
     
  9. burn

    burn A Smooth-Skin
    Modder

    626
    Apr 22, 2012
    So there's no function. Any other ideas?
     
  10. NovaRain

    NovaRain Casual Modder Modder

    Mar 10, 2007
    Have you checked the commands.doc included in the official mapper or killap's script sources?
    Using (obj_pid(critter_inven_obj(critter, INVEN_TYPE_RIGHT/LEFT_HAND)) should do the trick.
     
    Last edited: Nov 18, 2015
  11. burn

    burn A Smooth-Skin
    Modder

    626
    Apr 22, 2012
    Yes, but like I said, this is not what I need.
     
  12. Magnus

    Magnus Water Chip? Been There, Done That
    Modder

    953
    Dec 6, 2007
    Jeez, you're hard to please :D
    All right, how about this: Sfall has a function called active_hand which returns an integer. It has no explanation in the docs, but I'm betting that it returns the currently active item slot for the player (all critters in the game always have their active item in the 2nd slot, the item in their 1st slot is technically a part of their inventory).

    So, first check if the attacking critter is the player. If not, use the INVEN_TYPE_RIGHT_HAND flag in NovaRain's suggestion (although be sure to check if the critter is actually wielding an object in either hand so that it does not crash for unarmed attacks). If it is the player, use active_hand to determine which slot to check for.

    You might wanna write a macro for all this.
     
    • [Like] [Like] x 1
  13. burn

    burn A Smooth-Skin
    Modder

    626
    Apr 22, 2012
    Ah, there it is. I'm pretty sure I searched all the docs for words "current", "active", or "weapon", but somehow I missed it.
    Thank you.
     
  14. NovaRain

    NovaRain Casual Modder Modder

    Mar 10, 2007
    It's easier than I thought. Here's an example code that essentially gives 10mm Pistol and Desert Eagle an AC mod -5:
    Code:
    // hs_tohit.ssl
    
    procedure start;
    #include ".\HEADERS\DEFINE.H"
    #include ".\HEADERS\sfall.h"
    
    #define usewpn(PID) (obj_pid(critter_inven_obj(attacker, INVEN_TYPE_RIGHT_HAND)) == PID) or (obj_pid(critter_inven_obj(attacker, INVEN_TYPE_LEFT_HAND)) == PID)
    
    procedure start begin
        variable tohit;
        variable attacker;
        variable target;
        if not init_hook then begin
            tohit := get_sfall_arg;
            attacker := get_sfall_arg;
            target := get_sfall_arg;
    
            if (usewpn(PID_10MM_PISTOL) or usewpn(PID_DESERT_EAGLE)) then begin
                if (get_critter_stat(target, STAT_ac) < 5) then begin
                    tohit := tohit + get_critter_stat(target, STAT_ac);
                end else begin
                    tohit := tohit + 5;
                end
            end
    
            if (tohit > 95) then begin
                set_sfall_return(95);
            end else begin
                set_sfall_return(tohit);
            end
        end
    end
     
    Last edited: Nov 18, 2015
    • [Like] [Like] x 1
  15. burn

    burn A Smooth-Skin
    Modder

    626
    Apr 22, 2012
    Thanks for the snippet, I'll try to use it.
     
  16. Magnus

    Magnus Water Chip? Been There, Done That
    Modder

    953
    Dec 6, 2007
    What happens if critter_inven_obj returns 0, i.e. the character is unarmed? Won't obj_pid(0x00) cause a crash? Or will it just return false?
     
  17. J_Fred

    J_Fred Long time lurker

    286
    Dec 22, 2013
    ... why not just have the AC reduction inherent in the ammo? I think YAMM does this, right?
     
  18. NovaRain

    NovaRain Casual Modder Modder

    Mar 10, 2007
    It works perfectly normal if you just go punching or kicking someone.
     
  19. Magnus

    Magnus Water Chip? Been There, Done That
    Modder

    953
    Dec 6, 2007
    Could you humor me and see if you get an output if you try printing the results of obj_pid(0)? I'm worried I may have given false advice in another thread, and I don't have my Fallout modding gear installed on this PC.
     
  20. NovaRain

    NovaRain Casual Modder Modder

    Mar 10, 2007
    Sure, I added the line in my script:
    And the result is -1: