Potion Effects

Version:

2.0

Added on:

13 Apr 2015 14:10

Tags:

Description:
This is a really awesome script that gives you the ability to create your own potion effects! Hope you like it! :)

v2.0: Fixed the snippet, it didn't work because I made a big mistake, I put effectLevel as a simple int not an int array. So the code should 100% work. Try to contact me if it doesn't work ;)
  1. /*********************************Potion/Effect Script********************************************/
  2.  
  3. array<bool> effectID(4, false);
  4. array<int> fakeTimeSeconds(4, 0);
  5. array<int> timeSeconds(4, 0);
  6. array<int> timeMinutes(4, 0);
  7. int activePotions;
  8.  
  9. array<int> effectQueue(4, 0);
  10. array<int> effectLevel(4, 0);
  11.  
  12. void onLevelLoad() {
  13.     jjObjectPresets[OBJECT::CHERRY].determineCurAnim(ANIM::PICKUPS, 78);
  14.   jjObjectPresets[OBJECT::CHERRY].special = jjObjectPresets[OBJECT::CHERRY].determineCurAnim(ANIM::PICKUPS,78,false);
  15.   jjObjectPresets[OBJECT::CHERRY].determineCurFrame();
  16.   jjObjectPresets[OBJECT::CHERRY].scriptedCollisions = true;
  17.   jjObjectPresets[OBJECT::LETTUCE].determineCurAnim(ANIM::PICKUPS, 78);
  18.   jjObjectPresets[OBJECT::LETTUCE].special = jjObjectPresets[OBJECT::LETTUCE].determineCurAnim(ANIM::PICKUPS,78,false);
  19.   jjObjectPresets[OBJECT::LETTUCE].determineCurFrame();
  20.   jjObjectPresets[OBJECT::LETTUCE].scriptedCollisions = true;
  21.   jjObjectPresets[OBJECT::EGGPLANT].determineCurAnim(ANIM::PICKUPS, 78);
  22.   jjObjectPresets[OBJECT::EGGPLANT].special = jjObjectPresets[OBJECT::EGGPLANT].determineCurAnim(ANIM::PICKUPS,78,false);
  23.   jjObjectPresets[OBJECT::EGGPLANT].determineCurFrame();
  24.   jjObjectPresets[OBJECT::EGGPLANT].scriptedCollisions = true;
  25.   jjObjectPresets[OBJECT::DONUT].determineCurAnim(ANIM::PICKUPS, 78);
  26.   jjObjectPresets[OBJECT::DONUT].special = jjObjectPresets[OBJECT::DONUT].determineCurAnim(ANIM::PICKUPS,78,false);
  27.   jjObjectPresets[OBJECT::DONUT].determineCurFrame();
  28.   jjObjectPresets[OBJECT::DONUT].scriptedCollisions = true;
  29. }
  30.  
  31. void onPlayer() {
  32.     if (effectID[0]) {
  33.       --fakeTimeSeconds[0];
  34.     timeSeconds[0] = fakeTimeSeconds[0] / 70;
  35.     if (timeMinutes[0] > 0 && timeSeconds[0] == 0) {
  36.         --timeMinutes[0];
  37.       fakeTimeSeconds[0] = 70 * 60;
  38.     }
  39.     else if (timeMinutes[0] <= 0 && timeSeconds[0] == 0) {
  40.         effectID[0] = false;
  41.       --activePotions;
  42.       removeEffect(0);
  43.       effectLevel[0] = 0;
  44.     }
  45.   }
  46.   if (effectID[1]) {
  47.       --fakeTimeSeconds[1];
  48.     timeSeconds[1] = fakeTimeSeconds[1] / 70;
  49.     if (timeMinutes[1] > 0 && timeSeconds[1] == 0) {
  50.         --timeMinutes[1];
  51.       fakeTimeSeconds[1] = 70 * 60;
  52.     }
  53.     else if (timeMinutes[1] <= 0 && timeSeconds[1] == 0) {
  54.         effectID[1] = false;
  55.       --activePotions;
  56.       removeEffect(1);
  57.     }
  58.   }
  59.   if (effectID[2]) {
  60.       --fakeTimeSeconds[2];
  61.     timeSeconds[2] = fakeTimeSeconds[2] / 70;
  62.     if (timeMinutes[2] > 0 && timeSeconds[2] == 0) {
  63.         --timeMinutes[2];
  64.       fakeTimeSeconds[2] = 70 * 60;
  65.     }
  66.     else if (timeMinutes[2] <= 0 && timeSeconds[2] == 0) {
  67.         effectID[2] = false;
  68.       --activePotions;
  69.       removeEffect(2);
  70.     }
  71.   }
  72.   if (effectID[3]) {
  73.       --fakeTimeSeconds[3];
  74.     timeSeconds[3] = fakeTimeSeconds[3] / 70;
  75.     if (timeMinutes[3] > 0 && timeSeconds[3] == 0) {
  76.         --timeMinutes[3];
  77.       fakeTimeSeconds[3] = 70 * 60;
  78.     }
  79.     else if (timeMinutes[3] <= 0 && timeSeconds[3] == 0) {
  80.         effectID[3] = false;
  81.       --activePotions;
  82.       removeEffect(3);
  83.     }
  84.   }
  85.  
  86.   potionEffects();
  87. }
  88.  
  89. bool onDrawLives(jjPLAYER@ p, jjCANVAS@ canvas) {
  90.     if (effectID[0]) {
  91.       canvas.drawSprite(jjSubscreenWidth - 630, jjSubscreenHeight-340+(20 * effectQueue[0]), ANIM::AMMO, 12, 0, 0, SPRITE::NORMAL, 0);
  92.     if (effectLevel == 1) canvas.drawString(jjSubscreenWidth - 620, jjSubscreenHeight-340+(20 * effectQueue[0]), "Poison: " + timeMinutes[0] + "/" + timeSeconds[0], STRING::SMALL, STRING::NORMAL);
  93.     else if (effectLevel == 2) canvas.drawString(jjSubscreenWidth - 620, jjSubscreenHeight-340+(20 * effectQueue[0]), "Poison II: " + timeMinutes[0] + "/" + timeSeconds[0], STRING::SMALL, STRING::NORMAL);
  94.   }
  95.   if (effectID[1]) {
  96.       canvas.drawSprite(jjSubscreenWidth - 630, jjSubscreenHeight-340+(20 * effectQueue[1]), ANIM::AMMO, 4, 4, 0, SPRITE::NORMAL, 0);
  97.     canvas.drawString(jjSubscreenWidth - 620, jjSubscreenHeight-340+(20 * effectQueue[1]), "Blindness: " + timeMinutes[1] + "/" + timeSeconds[1], STRING::SMALL, STRING::NORMAL);
  98.   }
  99.   if (effectID[2]) {
  100.       canvas.drawSprite(jjSubscreenWidth - 630, jjSubscreenHeight-340+(20 * effectQueue[2]), ANIM::PICKUPS, 41, 0, 0, SPRITE::NORMAL, 0);
  101.     canvas.drawString(jjSubscreenWidth - 620, jjSubscreenHeight-340+(20 * effectQueue[2]), "Regeneration: " + timeMinutes[2] + "/" + timeSeconds[2], STRING::SMALL, STRING::NORMAL);
  102.   }
  103.   if (effectID[3]) {
  104.       canvas.drawSprite(jjSubscreenWidth - 630, jjSubscreenHeight-340+(20 * effectQueue[3]), /*Sprite Group*/, /*Sprite Group Animation*/, /*Sprite Group Animation Frame*/, /*Direction*/, /*SPRITE::Sprite Mode*/, /*param*/);
  105.     canvas.drawString(jjSubscreenWidth - 620, jjSubscreenHeight-340+(20 * effectQueue[3]), "Your Potion Effect: " + timeMinutes[3] + "/" + timeSeconds[3], STRING::SMALL, STRING::NORMAL);
  106.   }
  107.   return false;
  108. }
  109.  
  110. void onObjectHit(jjOBJ@ obj, jjOBJ@ bullet, jjPLAYER@ p, int force) {
  111.     switch(obj.eventID) {
  112.       case OBJECT::CHERRY:
  113.         fakeTimeSeconds[0] = 70 * 45;
  114.       timeMinutes[0] = 0;
  115.         effectID[0] = true;
  116.       effectLevel = 1;
  117.       if (effectLevel == 0) {
  118.           ++activePotions;
  119.           effectQueue[0] = activePotions;
  120.       }
  121.       obj.scriptedCollisions = false;
  122.       obj.behavior = BEHAVIOR::EXPLOSION2;
  123.       obj.frameID = 0;
  124.       jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ1, 30);
  125.       jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ2, 30);
  126.       jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ3, 30);
  127.       jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ4, 30);
  128.       break;
  129.     case OBJECT::LETTUCE:
  130.         fakeTimeSeconds[1] = 70 * 5;
  131.       timeMinutes[1] = 0;
  132.         effectID[1] = true;
  133.       ++activePotions;
  134.       effectQueue[1] = activePotions;
  135.       obj.scriptedCollisions = false;
  136.       obj.behavior = BEHAVIOR::EXPLOSION2;
  137.       obj.frameID = 0;
  138.       jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ1, 30);
  139.       jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ2, 30);
  140.       jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ3, 30);
  141.       jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ4, 30);
  142.       break;
  143.     case OBJECT::EGGPLANT:
  144.         fakeTimeSeconds[2] = 70 * 45;
  145.       timeMinutes[2] = 1;
  146.         effectID[2] = true;
  147.       ++activePotions;
  148.       effectQueue[2] = activePotions;
  149.       obj.scriptedCollisions = false;
  150.       obj.behavior = BEHAVIOR::EXPLOSION2;
  151.       obj.frameID = 0;
  152.       jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ1, 30);
  153.       jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ2, 30);
  154.       jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ3, 30);
  155.       jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ4, 30);
  156.       break;
  157.     case OBJECT::DONUT:
  158.         fakeTimeSeconds[3] = 70 * 45;
  159.       timeMinutes[3] = 0;
  160.         effectID[3] = true;
  161.       ++activePotions;
  162.       effectQueue[3] = activePotions;
  163.       obj.scriptedCollisions = false;
  164.       obj.behavior = BEHAVIOR::EXPLOSION2;
  165.       obj.frameID = 0;
  166.       jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ1, 30);
  167.       jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ2, 30);
  168.       jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ3, 30);
  169.       jjSample(p.xPos, p.yPos, SOUND::COMMON_DRINKSPAZZ4, 30);
  170.       break;
  171. }
  172.  
  173. void removeEffect(int id) {
  174.   for(int i = 0; i < 9; i++) {
  175.     if(effectQueue[i] == 0)
  176.       continue;
  177.     else if(effectQueue[i] > effectQueue[id])
  178.         effectQueue[i]--;
  179.   }
  180.   effectQueue[id]=0;
  181. }
  182.  
  183. void potionEffects() {
  184.     if (effectID[0]) {
  185.       if (effectLevel == 1) {
  186.       if (p.health > 1 && jjGameTicks % 280 == 0) {
  187.         p.health = p.health - 1;
  188.     }
  189.     } else if (effectLevel == 2) {
  190.     if (jjGameTicks % 140 == 0) {
  191.         p.health = p.health - 1;
  192.     }
  193.     }
  194.     if (p.health == 0) {
  195.       effectID[0] = false;
  196.         --activePotions;
  197.       removeEffect(0);
  198.       effectLevel = 0;
  199.     }
  200.   }
  201.   if (effectID[1]) {
  202.       if (jjGameTicks % 140 == 0) {
  203.         p.lighting = 0;
  204.       if (p.health == 0) {
  205.           effectID[1] = false;
  206.         --activePotions;
  207.         removeEffect(1);
  208.       }
  209.     }
  210.   } else p.lighting = 100;
  211.   if (effectID[2]) {
  212.       if (p.health <= jjMaxHealth && jjGameTicks % 560 == 0) {
  213.         p.health = p.health + 1;
  214.     }
  215.     if (p.health == 0) {
  216.       effectID[2] = false;
  217.       --activePotions;
  218.       removeEffect(2);
  219.     }
  220.   }
  221.   if (effectID[3]) {
  222.       /*Put here what the effect does*/
  223.         if (p.health == 0) {
  224.       effectID[3] = false;
  225.       --activePotions;
  226.       removeEffect(3);
  227.     }    
  228.   }
  229. }
  230.  
  231. /***********************************************************************************************************/