Hello guys and girls. As you have noticed, I'm gonna show you how to make a script which enables you to fire a weapon in bursts. Burst fire as most of you know is a firing mode that enables you to shoot a predetermined number bullets with each pull of trigger for example 3 as seen in most firearms in videogames. Let me be honest with you from the beginning. It has a few bugs but anyway gets the job done.
Here's the code I used to make my AR15 type rifle shoot in bursts of 3.
:LABEL_2 wait 0 if 02D8: actor $PLAYER_ACTOR current_weapon == 31 jf @LABEL_2 if 02E0: actor $PLAYER_ACTOR firing_weapon jf @LABEL_2 wait 130 0881: set_player $PLAYER_CHAR able_to_shoot_weapons 0 wait 300 0881: set_player $PLAYER_CHAR able_to_shoot_weapons 1 jump @LABEL_1
02D8 is there to check which weapon are you holding (in this case the "M4")
02E0 is simply used to check if the player is firing
wait 130 and the first 0881 is used to check whether enough cartridges have been fired (or better to say "how much time was the weapon being fired) or not and then stop the playa from shootin'
and wait 300 and the last 0881 is used to enable the player to fire another burst of bullets. The wait 300 is essentially the delay between the bursts. Set to lower or higher offsets if you wish.
NOTE: The wait 130 I used is to check how much time the weapon has been fired not to check how many cartridges have been fired. Since my modified weapon.dat int animLoop start, end, fire is set to 6 8.5 7 (which gives the weapon a higher rate of fire than the normal offsets), I struggled with the number to set the script execute the code within 0.130 sec, when approximately but not essentially accurately it had fired 3 bullets. I haven't tested the normal 6 10 7 offsets which makes the weapon fire slower than my own modified one.
There are a few known bugs:
1. It's not much realistic. If you start firing the weapon and quickly stop firing, not firing enough bullets to full a single burst (firing 1 or 2 bullets instead of for example 3 bursts), the script is not applied to the following bullet(s) of that "burst" as opposed to some real life designs where if you fire e.g. a M16 in a way that only 1 or 2 bullets are fired, the other 1 or 2 bullets from that burst must be fired to set the next burst. Although such mechanism does not apply to all burst fire weapons.
2. When not aiming and simply shooting without pressing the aim button it causes a small animation bug where after firing a burst, the player will start the animation of drawing one's weapon. This problem is not caused if you aim and shoot.
3. Not actually a bug. Like I said the script simply checks how much time the weapon has been fired not how many bullets. Thus, the script doesn't accurately examine the number of bullets fired. However it wasn't much of a problem to me after struggling with the numbers.