Limited air supply underwater

Version:

4.0

Added on:

13 Aug 2013 10:37

Tags:

Description:
Does what the title says. You can easily adjust the time it takes to drown to your liking by changing the p.timerStart() value.

EDIT: Updated the script with modifications to the shield functionality in water. Akin to Sonic 3, the bubble shield will grant you unlimited oxygen underwater (for as long as the shield lasts), whereas the fire and lightning shields will fade immediately upon entering the water. The laser shield will not disappear in water, but will not increase your air supply either.
void onPlayer() {
  limitedOxygen();
  shieldFade();
}

void onPlayerTimerEnd() {
  playerDrown();
}

void limitedOxygen() {
  if (p.yPos > jjWaterLevel && p.shieldType == 0 && p.timerState == TIMER::STOPPED) p.timerStart(30*70);
  if (p.yPos > jjWaterLevel && p.timerTime == 5*70) jjAlert("You are drowning!");
  if (p.yPos < jjWaterLevel) p.timerStop();
  if (p.shieldType == 2) p.timerStop();
}

void shieldFade() {
  if (p.yPos > jjWaterLevel && p.shieldType == 1) p.shieldType = 0;
  if (p.yPos > jjWaterLevel && p.shieldType == 3) p.shieldType = 0;
  if (p.yPos > jjWaterLevel && p.shieldType == 4) p.shieldType = 0;
}

void playerDrown() {
  p.kill();
  jjChat("/me forgot to come up for air");
}