Cycling weapons but only showing ones with ammo

Ok so a quick bit of background....

Basically I have a "choose weapon" button that when tapped changes the players weapon using the following expression:

( game.weapon-selected +1)%X

That works really well, however here is the issue... I only want weapons that have ammo > 0 to appear. (If the weapon doesn't have any ammo I don't want it to be selectable).

So I thought a quick hack around this would be to simply have a rule that says:

IF game.weapon1-ammo > 0

{ do something}

Otherwise

{change attribute ( game.weapon-selected +1)%X}

That way I check to see if the weapon has ammo and if not I just jump to the next one...now again this actually works well however the issue comes when I fire the last bit of ammo from weapon 1 it also fires the first shot of weapon 2 at the same time...

so my question is:

a) can anyone suggest a cleaner (better) method for this problem of cycling through weapons but only showing those that have ammo?

b) if not, then using my current method what can i do to stop firing the next weapon straight away when I run out of ammo of my previous gun?

Thanks in advance :-)

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2013
    Here's a demo.

    Click on the white square to change weapons. The white square displays WeaponNumber: Ammo. Click on the red square to fire the current weapon.
  • RoksaltRoksalt Member Posts: 87
    Hey @tatiang,

    Thanks for the demo. I like the use of tables...

    However there is still the same issue when changing from one weapon to the next in which the next weapon instantly when I run out of ammo of my previous weapon.

    How would I fix this?

    Cheers
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Oh yes, I see that... sorry. Let me see if I can fix that.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    This is usually fixed by adding a short timer, which I've done in this version.
  • RoksaltRoksalt Member Posts: 87
    Great. Thanks so much!
Sign In or Register to comment.