Flashbang

Version:

2.0

Added on:

28 Mar 2014 22:23

Tags:

Description:
It works like its Counter Strike counterpart.
  1. /*Flash Grenade*/
  2. /*Author: szmol96*/
  3.  
  4. bool doOnce = false;
  5. const float gravity = 0.5;
  6. int flashCount = 0;
  7. int blindTime = 3; //The time your screen stays white in seconds.
  8.  
  9. jjPAL myPal;
  10.  
  11. void onLevelLoad() {
  12.   jjObjectPresets[OBJECT::FIREBALLBULLET].behavior = flashNade;
  13.   jjObjectPresets[OBJECT::FIREBALLBULLET].bulletHandling = HANDLING::IGNOREBULLET;
  14.   jjObjectPresets[OBJECT::FIREBALLBULLET].playerHandling = HANDLING::PARTICLE;
  15.   jjObjectPresets[OBJECT::FIREBALLBULLET].counterEnd = 5;
  16. }
  17.  
  18. void flashNade(jjOBJ@ grenade) {
  19.   jjPLAYER@ p = jjLocalPlayers[0];
  20.  
  21.   if (grenade.state == STATE::START) {
  22.     grenade.xSpeed = p.direction * 5 + p.xSpeed;
  23.     grenade.ySpeed = p.ySpeed - 5;
  24.     grenade.state = STATE::FLY;
  25.   }
  26.  
  27.   grenade.age++;
  28.   if (grenade.age > 150) {
  29.     grenade.state = STATE::EXPLODE;
  30.     grenade.delete();
  31.     jjPARTICLE@ smoke = jjAddParticle(PARTICLE::SMOKE);
  32.       if (smoke !is null) {
  33.         smoke.xPos = grenade.xPos;
  34.         smoke.yPos = grenade.yPos;
  35.       }
  36.     jjPARTICLE@ smoke2 = jjAddParticle(PARTICLE::SMOKE);
  37.       if (smoke2 !is null) {
  38.         smoke2.xPos = grenade.xPos + 4;
  39.         smoke2.yPos = grenade.yPos;
  40.       }
  41.     jjPARTICLE@ smoke3 = jjAddParticle(PARTICLE::SMOKE);
  42.       if (smoke3 !is null) {
  43.         smoke3.xPos = grenade.xPos - 4;
  44.         smoke3.yPos = grenade.yPos;
  45.       }
  46.     jjPARTICLE@ spark = jjAddParticle(PARTICLE::SPARK);
  47.       if (spark !is null) {
  48.         spark.xPos = grenade.xPos;
  49.         spark.yPos = grenade.yPos + 5;
  50.         spark.ySpeed = -2;
  51.       }
  52.     jjPARTICLE@ spark2 = jjAddParticle(PARTICLE::SPARK);
  53.       if (spark2 !is null) {
  54.         spark2.xPos = grenade.xPos + 2;
  55.         spark2.yPos = grenade.yPos - 5;
  56.         spark2.xSpeed = -1;
  57.       }
  58.     jjPARTICLE@ spark3 = jjAddParticle(PARTICLE::SPARK);
  59.       if (spark3 !is null) {
  60.         spark3.xPos = grenade.xPos - 2;
  61.         spark3.yPos = grenade.yPos - 5;
  62.         spark3.xSpeed = 1;
  63.       }
  64.   }
  65.  
  66.   if (jjMaskedPixel(grenade.xPos + grenade.xSpeed, grenade.yPos)) {
  67.     grenade.xSpeed = -1 * (grenade.xSpeed / 2);
  68.   }
  69.   if (jjMaskedPixel(grenade.xPos, grenade.yPos + grenade.ySpeed)) {
  70.     grenade.ySpeed = -1 * (grenade.ySpeed / 2);
  71.   } else {
  72.     grenade.ySpeed = grenade.ySpeed + gravity;
  73.   }
  74.  
  75.   grenade.xPos = grenade.xPos + grenade.xSpeed;
  76.   grenade.yPos = grenade.yPos + grenade.ySpeed;
  77.  
  78.   if ((grenade.xPos - p.xPos) * p.direction > 0 && grenade.xPos > p.cameraX && grenade.yPos > p.cameraY && grenade.xPos < p.cameraX + 640 && grenade.yPos < p.cameraY + 480 && grenade.state==STATE::EXPLODE) {
  79.     flashCount = blindTime * 70;
  80.   }
  81.  
  82.   grenade.determineCurAnim(ANIM::AMMO, 1, true);
  83.   grenade.determineCurFrame();
  84.   grenade.draw();
  85. }
  86.  
  87. void onPlayer(jjPLAYER@ p) {
  88.   if (flashCount > 0) {
  89.     if (doOnce == false) {
  90.       myPal.fill(255, 255, 255, 1);
  91.       myPal.apply();
  92.       doOnce = true;
  93.     }
  94.     flashCount--;
  95.   } else {
  96.     if (doOnce == true) {
  97.       myPal.reset();
  98.       myPal.apply();
  99.       doOnce = false;
  100.     }
  101.   }
  102. }