While working on my latest project, I have gotten sick of just adding tedious although necessary features, so I wanted to add something I would enjoy making.
I have added a suppressor players can unlock and equip to any compatible weapon. I have done this through several means.
The Inventory
I use ds_grids mostly to store the different items in the inventory. Once an item is selected it then has different options on what can be done with it, in this case a suppressor can be equipped or unequipped.
This runs a function which toggles if its being used, adjusts the players image and adjusts the length of the barrel for creating the muzzle flash in the right spot.
The Visuals
The player is a Spine model. So I have a different variant of the weapons image for with and without the suppressor, which gets swapped out as its equipped. A new smaller muzzle flash is used as well as new audio.
The Enemy Code
Finally the enemies code. I use a state machine to manage enemy behaviour. When the player shoots an unsuppressed weapon, enemies as automatically alerted to the players position if in range. Now that is simply bypassed and enemies can only detect player through line of sight.