Limited Ammo and Ammo Drops

By LadylexUK

This is the kode I used for my First Person Shooter Wonderland Attacks. In this game you have limited ammo and can reload your gun. You can collect additional ammo in the form of an ammo crate which is dropped by the enemy at death. Due to the phantom footsteps bug I did not use sound effects in the player (as I had him muted) but used a sound board instead. As a result there are extra lines of kode that count the number of shots and reloads so you can play a sound effect outside the player.

In the player brain

  1. WHEN [right trigger][pressed] //This is the control option for firing the gun
  2. …WHEN [numvar:bullets][greater than or equal to][1]
  3. …/…WHEN DO [numvar:bullets][decrement by][1]
  4. …/…WHEN DO [global][numvar:shots][incremented by][1] // You can count the number of shots fired, and/or use it in a soundboard
  5. …/…WHEN DO [shoot][fx:Astro Blaster Projectile][at speed][50][launch frequency][20][lifetime][1.5][in direction][random vector][cone][direction][camera forward][angle][1.5][without targeting]

    Setting up the amount of bullets and ammo packs available and displaying that

  6. WHEN [once] DO [numvar:ammo packs][equals][clamp][min][0][max][10][numvar:ammo packs]
  7. …WHEN DO [numvar:ammo packs][equals][10] // starting amount
  8. …WHEN DO [numvar:bullets][equals][10] // starting amount
  9. WHEN [numvar:bullets][equal to][0] DO [display][text: OUT OF AMMO][screen center]
  10. WHEN DO [numvar:total ammo][equals][(][numvar: ammo packs][multiplied by][10][)]
  11. WHEN DO [display][numvar:bullets][screen bottom left][x large font]
  12. WHEN DO [display][numvar: total ammo][screen bottom left][small font]

    Reloading mechanism

  13. WHEN [control:x][pressed]
  14. …WHEN [numvar:bullets][less than][10] // so you can only reload if you have less than 10 bullets in your gun (max of 19)
  15. …/…WHEN [numvar:ammo packs][greater than or equal to][1] DO [numvar:bullets][increment by][10]
  16. …/…/…WHEN DO [numvar: ammo packs][decrement by][1]
  17. …/…/…WHEN DO [global][numvar:reloads][incremented by][1] // you can count number of reloads and/or use in a soundboard

17. alternate …/…/…WHEN DO [play sound][sound:reload sound]

In enemy brains

WHEN [started to][is dead] DO [create][IWP:ammo crate][at position][position]

In ammo crate (templated item)

  1. WHEN DO [play fx][fx:Navigation Interest][on][me]
  2. WHEN DO [pace][equals][5] // This is so the effect does not remain in the world for a long time after the crate is picked up
  3. WHEN [detect][player] DO [objvar:collector][equals][it]
  4. …WHEN [objvar:collector][numvar:ammo packs][less than][10]
  5. …/…WHEN [started to] DO [objvar:collector][numvar:ammo packs][increment by][1] // in  my game each ammo crate contained 2 ammo packs.
  6. …/…./…WHEN DO [global][numvar:collect][increment by][1] // You can use this in a sound board to create a sound when collected
  7. …/…/…WHEN DO [destroy me]

In sound board

WHEN [global][numvar:collect][increased] DO [play sound][Your choice of sound here][everywhere] // use similar kode for all the global variables for reloading and shooting

Comments are closed.

Powered by WordPress.com.

Up ↑

%d bloggers like this: