I can't figure how to get the shotgun sprite to draw only when firing and only when the ammo is >0
In the script scrUseItem, line 245, you see this:
if (not scrPlayerIsDucking())
{
if (facing == LEFT and firing == 0)
{
instance_create(x-9, y+1, oShotgunBlastLeft);
obj = instance_create(x-9, y-2, oBullet);
obj.xVel = (-1 * rand(6,8)) + xVel;
if (obj.xVel >= -6) obj.xVel = -6;
obj.yVel = 0;
if (state != HANGING and state != CLIMBING)
{
yVel -= 1;
xVel += 1;
}
playSound(global.sndShotgun);
firing = firingPistolMax;
}
Just add another clause to the if statement, like "and global.ammo > 0". I'm assuming you're using a global ammo variable since that's how bombs and ropes are tracked, plus it'll make it easier to add a new UI element (see below).
You'll want to do the same thing to line 260, which is the same code but for when you're facing right.
Specifically, it's when the game creates oShotgunBlastLeft and oShotgunBlastRight that it displays the muzzle flashes. So you could also put an "if (global.ammo > 0) right before the instance_create for those objects as well.
2. is implicit to gameplay, as it stands you will start the game with 7 shells. I have added an item (box of shells) to give 7 more and put it in the shop/box lists. I can't tell if it's not showing up, or if it's giving me bombs instead since I copied and edited the functions from the bomb bag. I also want to take the shotgun out entirely, but that may have to wait until the shells are at least working. The biggest issue I'm having is where to find the functions of items? Is it simply in the hold item script? Steal item?
Most of the code for what happens when you're holding and using an item is in scrUseItem. That's for active items like guns and the machete and the damsel. What you might want to do is add a new UI element to the top of the screen that shows how much ammo you have -- that way you can tell if your box of shells is working or not. To do this, open up scrDrawHUD and you'll see this:
if (global.drawHUD and instance_exists(oPlayer1))
{
lifeX = 8;
bombX = 64;
ropeX = 120;
moneyX = 176;
draw_set_font(global.myFont);
draw_set_color(c_white);
draw_sprite(sHeart, -1, lifeX, 8);
life = global.plife;
if (life < 0) life = 0;
draw_text(lifeX+16, 8, life);
if (global.hasStickyBombs) draw_sprite(sStickyBombIcon, -1, bombX, 8);
else draw_sprite(sBombIcon, -1, bombX, 8);
draw_text(bombX+16, 8, global.bombs);
draw_sprite(sRopeIcon, -1, ropeX, 8);
draw_text(ropeX+16, 8, global.rope);
draw_sprite(sDollarSign, -1, moneyX, 8);
draw_text(moneyX+16, 8, global.money);
What you'll want to do is create ammoX, which is the X offset of the new ammo UI element. I would actually put it in between rope and money, because money is variable length so you want it at the far right hand side. Then you just add the draw_text() and draw_sprite() functions. I used the sprite for the shotgun in the example below:
if (global.drawHUD and instance_exists(oPlayer1))
{
global.ammo = 7; // CHANGE THIS ELSEWHERE IN THE CODE, this is just for test purposes
lifeX = 8;
bombX = 64;
ropeX = 120;
ammoX = 176;
moneyX = 232;
draw_set_font(global.myFont);
draw_set_color(c_white);
draw_sprite(sHeart, -1, lifeX, 8);
life = global.plife;
if (life < 0) life = 0;
draw_text(lifeX+16, 8, life);
if (global.hasStickyBombs) draw_sprite(sStickyBombIcon, -1, bombX, 8);
else draw_sprite(sBombIcon, -1, bombX, 8);
draw_text(bombX+16, 8, global.bombs);
draw_sprite(sRopeIcon, -1, ropeX, 8);
draw_text(ropeX+16, 8, global.rope);
// I had to fiddle a bit with the x and y vars here to make things look good
draw_sprite(sShotgunRight, -1, ammoX, 16);
draw_text(ammoX+8, 8, global.ammo);
draw_sprite(sDollarSign, -1, moneyX, 8);
draw_text(moneyX+16, 8, global.money);
