Changing ammo cost per attack with sfall hook script

NovaRain

Casual Modder
Modder
Moderator
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.)
Code:
// hs_afterhitroll.ssl

procedure start;
#include "sfall.h"
#include "DEFINE.H"

procedure start begin
  variable hit, attacker, ammo;
  if not init_hook then begin
    hit:=get_sfall_arg;
    attacker:=get_sfall_arg;

    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
    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);
      end
    end
  end
end
And the proto also need to be edited a bit:
xl70burst.png


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.
 
Thanks for taking the time to make it work, Novarain! We'll actually be using that script in MR :)
 
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:
Great! It will be wery usefull in some kinds of weapons: for example, for powerfull weapons to make game balance.
 
Back
Top