Enemies drop ammo

Version:

2.0

Added on:

28 Sep 2013 16:22

Tags:

Description:
Here's a simple bit of a code that enables random ammo drops from enemies, alongside the standard drops. Mostly based on cooba's Fire Shield burn code. Feel free to edit the code to your liking, if say you don't want players having access to a certain kind of ammo yet. Note that non-local players will not be able to see your ammo drops if you are playing Coop online, and that in splitscreen mode, the amount of ammo dropped by an enemy varies depending on the number of local players.

EDIT: Fixed a bug where JJ2 would consider other objects to be enemies (e.g. Destruct Scenery)
jjOBJ@ enemy;
 
void onPlayer() {
  for (int i = 1; i < jjObjectCount; i++) {
    @enemy = jjObjects[i];
    if (enemy.objType >= 16 && enemy.state == STATE::KILL && enemy.isActive && jjGameTicks%7 == 0) {
      randomizer();
    }
  }
}
 
void randomizer() {
  switch (jjRandom()%8) {
    case 0: jjAddObject(OBJECT::BOUNCERAMMO3, enemy.xPos, enemy.yPos, p.playerID, CREATOR::PLAYER); break;
    case 1: jjAddObject(OBJECT::ICEAMMO3, enemy.xPos, enemy.yPos, p.playerID, CREATOR::PLAYER); break;
    case 2: jjAddObject(OBJECT::SEEKERAMMO3, enemy.xPos, enemy.yPos, p.playerID, CREATOR::PLAYER); break;
    case 3: jjAddObject(OBJECT::RFAMMO3, enemy.xPos, enemy.yPos, p.playerID, CREATOR::PLAYER); break;
    case 4: jjAddObject(OBJECT::TOASTERAMMO3, enemy.xPos, enemy.yPos, p.playerID, CREATOR::PLAYER); break;
    case 5: jjAddObject(OBJECT::TNTAMMO3, enemy.xPos, enemy.yPos, p.playerID, CREATOR::PLAYER); break;
    case 6: jjAddObject(OBJECT::GUN8AMMO3, enemy.xPos, enemy.yPos, p.playerID, CREATOR::PLAYER); break;
    case 7: jjAddObject(OBJECT::GUN9AMMO3, enemy.xPos, enemy.yPos, p.playerID, CREATOR::PLAYER); break;
  }
}