Gem Saving

Version:

6.0

Added on:

29 Dec 2014 16:43

Tags:

Description:
If you add death pits in your treasure hunt levels, and gems do not re-generate, when you die in a death pit you lose all your gems, so... this will save your gems.
bool access = true;

class savedGems {
  savedGems() {
    red = green = blue = 0;
  }
  int red;
  int green;
  int blue;
};

array<int> playerArray(4);
array<savedGems> gemsArray(4);
bool load = false;

array<int>fakeHealth(4, 0);
array<bool>forced(4, false);

void onPlayer(jjPLAYER@ p) {
  if ((p.health == 0 && forced[p.localPlayerID]) || (p.health == 5 && !forced[p.localPlayerID])) { 
      fakeHealth[p.localPlayerID] = p.health;
    }
  switch(fakeHealth[p.localPlayerID]) {
      case 0:
        if (access) {
          gemsArray[p.localPlayerID].red = p.gems[GEM::RED];
            gemsArray[p.localPlayerID].green = p.gems[GEM::GREEN];
            gemsArray[p.localPlayerID].blue = p.gems[GEM::BLUE];
        jjAlert("Red gems current: " + p.gems[GEM::RED]);
          jjAlert("|Red gems saved: " + gemsArray[p.localPlayerID].red);
        jjAlert("Green gems current: " + p.gems[GEM::GREEN]);
        jjAlert("|Green gems saved: " + gemsArray[p.localPlayerID].green);
        jjAlert("Blue gems current: " + p.gems[GEM::BLUE]);
        jjAlert("|Blue gems saved: " + gemsArray[p.localPlayerID].blue);
        forced[p.localPlayerID] = false;
        access = false;
      }
      break;
    case 5:
        p.gems[GEM::RED] = gemsArray[p.localPlayerID].red;
      jjAlert("||Red gems loaded: " + p.gems[GEM::RED]);
      p.gems[GEM::GREEN] = gemsArray[p.localPlayerID].green;
      jjAlert("||Green gems loaded: " + p.gems[GEM::GREEN]);
      p.gems[GEM::BLUE] = gemsArray[p.localPlayerID].blue;
        jjAlert("||Blue gems loaded: " + p.gems[GEM::BLUE]);
          if (!access) access = true;
      forced[p.localPlayerID] = true;
      fakeHealth[p.localPlayerID] = 4;
      break;
  }
}