Changing ammo cost per attack with sfall hook script

Discussion in 'Fallout General Modding' started by NovaRain, Apr 14, 2013.

  1. NovaRain

    NovaRain Casual Modder Modder

    Mar 10, 2007
    I was trying to emulate the hardcoded 2 ammo per attack attribute of Mega Power Fist & Super Cattle Prod on other weapons, and extend its ability if possible. I know there are set/get_weapon_ammo_count sfall functions, but don't know how to get it done at first. After some help from Ardent and Timeslip, I manage to get it work by taking off extra ammo from weapons after each attack.

    Here's a sample code to modify XL70E3 to have a "hyper-burst" ability, for both single shot and burst:
    (Special thanks to Ardent and Timeslip.)
    // hs_afterhitroll.ssl
    procedure start;
    #include "sfall.h"
    #include "DEFINE.H"
    procedure start begin
      variable hit, attacker, ammo;
      if not init_hook then begin
        if (obj_pid(critter_inven_obj(attacker, INVEN_TYPE_RIGHT_HAND)) == PID_INDEPENDENT) then begin
          ammo:=get_weapon_ammo_count(critter_inven_obj(attacker, INVEN_TYPE_RIGHT_HAND));
          if (get_attack_type == ATKTYPE_RWEP1) then begin
            set_weapon_ammo_count(critter_inven_obj(attacker, INVEN_TYPE_RIGHT_HAND), ammo-1);
          end else if (get_attack_type == ATKTYPE_RWEP2) then begin
            set_weapon_ammo_count(critter_inven_obj(attacker, INVEN_TYPE_RIGHT_HAND), ammo-5);
        end else if (obj_pid(critter_inven_obj(attacker, INVEN_TYPE_LEFT_HAND)) == PID_INDEPENDENT) then begin
          ammo:=get_weapon_ammo_count(critter_inven_obj(attacker, INVEN_TYPE_LEFT_HAND));
          if (get_attack_type == ATKTYPE_LWEP1) then begin
            set_weapon_ammo_count(critter_inven_obj(attacker, INVEN_TYPE_LEFT_HAND), ammo-1);
          end else if (get_attack_type == ATKTYPE_LWEP2) then begin
            set_weapon_ammo_count(critter_inven_obj(attacker, INVEN_TYPE_LEFT_HAND), ammo-5);
    And the proto also need to be edited a bit:

    Now XL70E3 will cost 2 ammo per single shot and 10 ammo in a 5-round burst. Of course you can change the ammo cost per attack or limit it to apply on only one of attack modes. The problem is it won't stop the player from firing the weapon when there's only one ammo left. Timeslip suggests me to add a check forcing any single shot with insufficient ammo into a critical miss. :P
    Actually the same problem also happens on Mega Power Fist, since its ammo capacity is 25 not an even number. You can still punch people with only one cell left. I guess the devs didn't think of that at the time.
  2. Ardent

    Ardent A Smooth-Skin

    Jul 24, 2009
    Thanks for taking the time to make it work, Novarain! We'll actually be using that script in MR :)
  3. phobos2077

    phobos2077 Mildly Dipped

    Apr 24, 2010
    I've managed to add "hs_ammocost" hook script, which does exactly the same. But also I've added optional (INI) check if there is enough ammo to use the weapon or display "Out of ammo".
    It will probably be in Sfall 3.4.

    Edit: works for bursts as well now
    Last edited: Sep 7, 2014
  4. Ghoul [BB]

    Ghoul [BB] First time out of the vault

    Aug 3, 2014
    Great! It will be wery usefull in some kinds of weapons: for example, for powerfull weapons to make game balance.