Advertisement
ZoriaRPG

Guardian NPC Script for Classic.zh [v1.0]

Aug 13th, 2019
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.37 KB | None | 0 0
  1. #include "std.zh"
  2.  
  3. ///////////////////////
  4. /// GUARDIANS       ///
  5. /// NPC Script      ///
  6. /// For ZC 2.55     ///
  7. /// v1.0            ///
  8. /// 13th Aug., 2019 ///
  9. ///////////////////////
  10.  
  11.  
  12. npc script Guardian
  13. {
  14.     const int LASER_LAYER       = 3;
  15.     const int LASER_COLOUR      = 0x04;
  16.     const int LASER_OPACITY     = 128;
  17.     const int ANGLE_VISION      = 60;
  18.     const int SHOT_STEP     = 120;
  19.     const int COODOWN       = 150;
  20.     const int WTYPE         = EW_SCRIPT1;
  21.     const int SHOT_SFX      = 70;
  22.    
  23.     void run (int angleOfVision, int shotStep, int shotCooldownTime, int weaponType, int shotSFX, int laserColour)
  24.     {  
  25.         //Get attributes
  26.         angleOfVision = (this->InitD[0] > 0 ) ? this->InitD[0] : ANGLE_VISION;
  27.         shotStep = (this->InitD[1] > 0 ) ? this->InitD[1] : SHOT_STEP;
  28.         shotCooldownTime = ((this->InitD[2] > 0) ? (this->InitD[2]) : COODOWN);
  29.         weaponType = (this->InitD[3] > 0 ) ? this->InitD[3] : WTYPE;
  30.         shotSFX = (this->InitD[4] > 0 ) ? this->InitD[4]: SHOT_SFX;
  31.         laserColour = (this->InitD[5] > 0 ) ? this->InitD[5]: LASER_COLOUR;
  32.  
  33.         int laserStartX;
  34.         int laserStartY;
  35.  
  36.         eweapon beam;
  37.  
  38.         while(this->isValid())
  39.         {
  40.             laserStartX = this->X + 8;
  41.             laserStartY = this->Y + 8;
  42.             //Shooting
  43.             if ( shotCooldownTime > 0 )
  44.                 --shotCooldownTime;
  45.             //Only one beam at a time
  46.             else if ( !beam->isValid() )
  47.             {
  48.                 //Check angle to Link against angle of vision
  49.                 //If Link is within this angle
  50.                 if ( (Abs((Angle(CenterX(this), CenterY(this), CenterLinkX(), CenterLinkY())) - (Dir4Angle(this->Dir)))) <= angleOfVision/2 )
  51.                 {
  52.                     shotCooldownTime = (this->InitD[2] > 0 ) ? this->InitD[2] : COODOWN; //can reduce down by reading InitD again -Z
  53.        
  54.                     laserStartX = CenterX(this);
  55.                     laserStartY = CenterY(this);
  56.                    
  57.                    
  58.                     /*beam = Screen->CreateEWeapon(weaponType);
  59.                     beam->X = laserStartX;
  60.                     beam->Y = laserStartY;
  61.                     beam->Angular = true;
  62.                     beam->Angle = ArcTan(Link->X-beam->X, Link->Y-beam->X);
  63.                     beam->Step = shotStep;*/
  64.                     beam = FireLaser(weaponType, laserStartX, laserStartY, 0, shotStep, this->WeaponDamage);
  65.                     beam->DrawXOffset = 999; //Draw off-screen
  66.                     Audio->PlaySound(shotSFX);
  67.                     //beam->DrawXOffset = 999; //Draw off-screen
  68.                 }
  69.             }
  70.  
  71.             //Draw laser beam
  72.             if ( beam->isValid() )
  73.             {
  74.                 Screen->Line(LASER_LAYER, laserStartX, laserStartY, CenterX(beam), CenterY(beam), laserColour, 1, 0, 0, 0, LASER_OPACITY);
  75.             }
  76.  
  77.             Waitframe();
  78.         }
  79.     }
  80.    
  81.     // Set the weapon's direction based on its angle;
  82.     // Can also makes weapons unblockable
  83.     void LaserDir(eweapon wpn)
  84.     {
  85.         float angle=wpn->Angle%6.2832;
  86.         int dir;
  87.        
  88.         if(angle<0)
  89.         angle+=6.2832;
  90.        
  91.         if(angle<0.3927 || angle>5.8905)
  92.         dir=DIR_RIGHT;
  93.         else if(angle<1.1781)
  94.         dir=DIR_RIGHTDOWN;
  95.         else if(angle<1.9635)
  96.         dir=DIR_DOWN;
  97.         else if(angle<2.7489)
  98.         dir=DIR_LEFTDOWN;
  99.         else if(angle<3.5343)
  100.         dir=DIR_LEFT;
  101.         else if(angle<4.3197)
  102.         dir=DIR_LEFTUP;
  103.         else if(angle<5.1051)
  104.         dir=DIR_UP;
  105.         else
  106.         dir=DIR_RIGHTUP;
  107.         wpn->Dir=dir;
  108.     }
  109.  
  110.  
  111.     eweapon FireLaser(int weaponID, int x, int y, float angle, int step, int damage)
  112.     {
  113.         eweapon wpn=Screen->CreateEWeapon(weaponID);
  114.         wpn->X=x;
  115.         wpn->Y=y;
  116.         wpn->Step=step;
  117.         wpn->Damage=damage;
  118.         wpn->Angular=true;
  119.         wpn->Angle=ArcTan(Link->X-x, Link->Y-y)+angle;
  120.  
  121.  
  122.         LaserDir(wpn);
  123.        
  124.         return wpn;
  125.     }
  126.  
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement