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.)
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.
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.
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

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.

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.