Drop Ammo on Death

Version:

2.0

Added on:

01 Dec 2014 17:36

Tags:

Description:
When you die you will drop your ammo on the ground, and you can get your ammo back.
//Script by XxMoNsTeR

/*************************************************Drop Ammo on Death***********************************************/

bool droppedAmmo = false;
uint realAmmoDropping = 0;
int latestXPos;
int latestYPos;
int initialLatestXPos;
int initialLatestYPos;
int splitchance = 0;

void onPlayer() {
    if (p.health == 0 && !droppedAmmo) {
      latestXPos = p.xPos;
    latestYPos = p.yPos;
    initialLatestXPos = latestXPos;
    initialLatestYPos = latestYPos;
      p.xPos = 1 * 32;
    p.yPos = 1 * 32;
    realAmmoDropping = p.ammo[WEAPON::BOUNCER] / 3;
    for (uint ammoDropping = 0; ammoDropping < realAmmoDropping; ammoDropping++) {
      jjAddObject(OBJECT::BOUNCERAMMO3, latestXPos, latestYPos, p.playerID, CREATOR::PLAYER);
      splitAmmo();
    }
    realAmmoDropping = p.ammo[WEAPON::ICE] / 3;
    for (uint ammoDropping = 0; ammoDropping < realAmmoDropping; ammoDropping++) {
      jjAddObject(OBJECT::ICEAMMO3, latestXPos, latestYPos, p.playerID, CREATOR::PLAYER);
    splitAmmo();
    }
    realAmmoDropping = p.ammo[WEAPON::RF] / 3;
    for (uint ammoDropping = 0; ammoDropping < realAmmoDropping; ammoDropping++) {
      jjAddObject(OBJECT::RFAMMO3, latestXPos, latestYPos, p.playerID, CREATOR::PLAYER);
    splitAmmo();
    }
    realAmmoDropping = p.ammo[WEAPON::SEEKER] / 3;
    for (uint ammoDropping = 0; ammoDropping < realAmmoDropping; ammoDropping++) {
      jjAddObject(OBJECT::SEEKERAMMO3, latestXPos, latestYPos, p.playerID, CREATOR::PLAYER);
    splitAmmo();
    }
    realAmmoDropping = p.ammo[WEAPON::TOASTER] / 3;
    for (uint ammoDropping = 0; ammoDropping < realAmmoDropping; ammoDropping++) {
      jjAddObject(OBJECT::TOASTERAMMO3, latestXPos, latestYPos, p.playerID, CREATOR::PLAYER);
    splitAmmo();
    }
    realAmmoDropping = p.ammo[WEAPON::TNT] / 3;
    for (uint ammoDropping = 0; ammoDropping < realAmmoDropping; ammoDropping++) {
      jjAddObject(OBJECT::TNTAMMO3, latestXPos, latestYPos, p.playerID, CREATOR::PLAYER);
    splitAmmo();
    }
    realAmmoDropping = p.ammo[WEAPON::GUN8] / 3;
    for (uint ammoDropping = 0; ammoDropping < realAmmoDropping; ammoDropping++) {
      jjAddObject(OBJECT::GUN8AMMO3, latestXPos, latestYPos, p.playerID, CREATOR::PLAYER);
    splitAmmo();
    }
    realAmmoDropping = p.ammo[WEAPON::GUN9] / 3;
    for (uint ammoDropping = 0; ammoDropping < realAmmoDropping; ammoDropping++) {
      jjAddObject(OBJECT::GUN9AMMO3, latestXPos, latestYPos, p.playerID, CREATOR::PLAYER);
    splitAmmo();
    }
    droppedAmmo = true;
  } else if (p.health == 5 && droppedAmmo) {
      droppedAmmo = false;
    p.ammo[WEAPON::BOUNCER] = 0;
      p.ammo[WEAPON::GUN8] = 0;
      p.ammo[WEAPON::GUN9] = 0;
      p.ammo[WEAPON::TNT] = 0;
      p.ammo[WEAPON::TOASTER] = 0;
      p.ammo[WEAPON::SEEKER] = 0;
      p.ammo[WEAPON::ICE] = 0;
      p.ammo[WEAPON::RF] = 0;
  }
}

void splitAmmo() {
    splitchance = jjRandom() % 9;
  latestXPos = initialLatestXPos;
  latestYPos = initialLatestYPos;
  switch(splitchance) {
      case 1:
        latestXPos = latestXPos - jjRandom() % 33;
      latestYPos = latestYPos + jjRandom() % 33;
      break;
    case 2:
        latestYPos = latestYPos + jjRandom() % 33;
        break;
    case 3:
        latestXPos = latestXPos + jjRandom() % 33;
      latestYPos = latestYPos + jjRandom() % 33;
      break;
    case 4:
        latestXPos = latestXPos - jjRandom() % 33;
      break;
    case 5:
        latestXPos = latestXPos + jjRandom() % 33;
      break;
    case 6:
        latestXPos = latestXPos - jjRandom() % 33;
      latestYPos = latestYPos - jjRandom() % 33;
      break;
    case 7:
        latestYPos = latestYPos - jjRandom() % 33;
      break;
    case 8:
        latestXPos = latestXPos + jjRandom() % 33;
      latestYPos = latestYPos - jjRandom() % 33;
      break;
      default:
        latestXPos = latestXPos;
      latestYPos = latestYPos;
      break;    
  }
}

/************************************************************************************************************************/