Advertisement
ZoriaRPG

Daira NPC and EWeapon Scripts (v0.2) for 2.55

Mar 7th, 2019
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.24 KB | None | 0 0
  1. /////////////////////////////////////////////////////
  2. /// Daira NPC Script for 2.55                     ///
  3. /// v0.2                                          ///
  4. /// 7th March, 2019                               ///
  5. ///                                               ///
  6. /// Original Daira by: Tamamo, and NightmareJames ///
  7. /// This version, by: ZoriaRPG                    ///
  8. /////////////////////////////////////////////////////
  9. npc script DairaNPC
  10. {
  11.     void run()
  12.     {
  13.  
  14.         //Original Tile
  15.         int OTile = this->OriginalTile;
  16.  
  17.         //Movement Variables
  18.         float counter = -1;
  19.         int step = this->Step;
  20.         int rate = this->Rate;
  21.         int homing = this->Homing;
  22.         int hunger = this->Hunger;
  23.        
  24.         //Weapon Variables
  25.         eweapon wpn;
  26.         int damage = this->WeaponDamage;
  27.         int attackTimer;
  28.         int attackWait; //Time between swings.
  29.         bool throw = (this->BFlags[4]); //Behavioural FLag 4
  30.         //bool shielded = this->Attributes[0]&4;
  31.         int wSprite = this->WeaponSprite; //Ghost_GetAttribute(ghost,1,-1);
  32.  
  33.         //Behavior
  34.         while(this->isValid())
  35.         {
  36.  
  37.             //Attacking
  38.             if(!attackTimer) //Attacks when Link is in Range, and within Line of Sight
  39.             {
  40.                 if ( this->LinkInRange(80) )
  41.                 {
  42.                     bool LoS = false;
  43.                     switch(this->Dir)
  44.                     {
  45.                        
  46.                         case DIR_UP:
  47.                         {
  48.                             if ( Link->Y > this->Y ) break; //Facing Link
  49.                             if ( Abs(Link->X - this->X) <= 16 ) LoS = true; break;
  50.                         }
  51.                         case DIR_DOWN:
  52.                         {
  53.                             if ( Link->Y < this->Y ) break;
  54.                             if ( Abs(Link->X - this->X) <= 16 ) LoS = true; break;
  55.                         }
  56.                         case DIR_LEFT:
  57.                         {
  58.                             if ( Link->X > this->X ) break;
  59.                             if ( Abs(Link->Y - this->Y) <= 16 ) LoS = true; break;
  60.                         }
  61.                         case DIR_RIGHT:
  62.                         {
  63.                             if ( Link->X < this->X ) break;
  64.                             if ( Abs(Link->Y - this->Y) <= 16 ) LoS = true; break;
  65.                         }
  66.                         default: break;
  67.                     }
  68.                        
  69.                     if ( LoS )
  70.                     {
  71.                         attackWait--;
  72.                         if(attackWait<=0)
  73.                         {
  74.                             attackTimer = 21;
  75.                             attackWait = 60;
  76.                         }
  77.                     }
  78.                 }
  79.             }
  80.  
  81.             if(attackTimer>0) //Attacking?
  82.             {
  83.                 if(this->OriginalTile == OTile)
  84.                 {
  85.                     wpn=Screen->CreateEWeapon(EW_BEAM);
  86.                     wpn->Dir = Ghost_Dir;
  87.                     wpn->Step= 200;
  88.                     wpn->UseSprite(wSprite);
  89.                     wpn->Damage=damage;
  90.                     wpn->Angular=false;
  91.                     wpn->Script = 1; //daira axe
  92.                     wpn->CSet = this->CSet;
  93.                 }
  94.                 else if(!wpn->isValid())
  95.                 {
  96.                     this->OriginalTile = OTile;
  97.                     Waitframe();
  98.                     attackTimer = 0;
  99.                     continue;
  100.                 }
  101.                 this->OriginalTile = OTile + 20*Div(28-attackTimer, 7);
  102.                 wpn->Tile = this->OriginalTile+this->Dir+16;
  103.                 wpn->X = this->X;
  104.                 wpn->Y = this->Y;
  105.                 wpn->DeadState = WDS_ALIVE;
  106.                 if(attackTimer>14)
  107.                 {
  108.                     if((this->Dir == DIR_UP || this->Dir == DIR_DOWN))
  109.                         wpn->Y -= 16;
  110.                     else wpn->X -= InFrontX(this->Dir, 0);
  111.                 }
  112.                 else if(attackTimer>7)
  113.                 {
  114.                     if(this->Dir == DIR_UP || this->Dir == DIR_DOWN)
  115.                     {
  116.                         if(this->Dir == DIR_UP )
  117.                             wpn->Y -= 16;
  118.                     }
  119.                     else
  120.                     {
  121.                         wpn->X += InFrontX(this->Dir, 0);
  122.                     }
  123.                 }
  124.                 else
  125.                 {
  126.                     wpn->X += InFrontX(this->Dir,0);
  127.                     wpn->Y += InFrontY(this->Dir,0);
  128.                 }
  129.                 //the weapon hit boxes are small.
  130.                 SetWpnHitOffsets(wpn, Div(28-attackTimer, 7), this->Dir);
  131.                 attackTimer--;
  132.             }
  133.             else if(wpn->isValid())
  134.             {
  135.                 this->OriginalTile = OTile;
  136.                 if(throw)
  137.                 {
  138.                     wpn=Screen->CreateEWeapon(EW_BEAM);
  139.                     wpn->Dir = Ghost_Dir;
  140.                     wpn->Step= 200;
  141.                     wpn->UseSprite(wSprite);
  142.                     wpn->Damage=damage;
  143.                     wpn->Angular=false;
  144.                     wpn->Script = 1; //daira axe
  145.                    
  146.                     this->OriginalTile = this->OriginalTile + 80 + (this->Dir*4);
  147.                 }
  148.             }
  149.             if(this->HP <= 0)
  150.             {
  151.                 wpn->DeadState = WDS_DEAD;
  152.                 Quit();
  153.             }
  154.             Waitframe();
  155.         }
  156.     }
  157.     void SetWpnHitOffsets(eweapon wpn, int frame, int dir)
  158.     {
  159.         //Set Default Collision Properties
  160.         wpn->CollDetection = true;
  161.         wpn->HitXOffset = 0;
  162.         wpn->HitYOffset = 0;
  163.         wpn->HitWidth = 16;
  164.         wpn->HitHeight = 16;
  165.  
  166.         //Modify it based off attack frame.
  167.         switch(frame)
  168.         {
  169.             case 1:
  170.             {
  171.                 if(dir == DIR_UP || dir == DIR_DOWN)
  172.                 {
  173.                     wpn->CollDetection = false;
  174.                     return;
  175.                 }
  176.                 else
  177.                     wpn->HitWidth = 8;
  178.                 if(dir == DIR_RIGHT)
  179.                     wpn->HitXOffset = 8;
  180.                 break;
  181.             }
  182.             case 2:
  183.             {
  184.                 if(dir == DIR_UP || dir==DIR_DOWN)
  185.                 {
  186.                     wpn->HitHeight = 8;
  187.                     return;
  188.                 }
  189.                 else
  190.                     wpn->HitWidth = 8;
  191.                 if(dir == DIR_LEFT)
  192.                 wpn->HitXOffset = 8;
  193.                 break;
  194.             }
  195.             case 3:
  196.             {
  197.                 wpn->HitXOffset = Cond(dir==DIR_LEFT, 8, 0);
  198.                 wpn->HitYOffset = Cond(dir==DIR_UP, 8, 0);
  199.                 wpn->HitWidth = Cond(dir==DIR_LEFT||dir==DIR_RIGHT, 8, 16);
  200.                 wpn->HitHeight = Cond(dir==DIR_UP||dir==DIR_DOWN, 8, 16);
  201.                 break;
  202.             }
  203.             default: //Out of range.
  204.             {
  205.                 wpn->DeadState = WDS_DEAD;
  206.                 return;
  207.             }
  208.         }
  209.     }
  210. }
  211.  
  212.  
  213. ////////////////////////////////////
  214. /// Axe Weapon Handler For Daira ///
  215. ////////////////////////////////////
  216. eweapon script dairaaxe
  217. {
  218.     void run()
  219.     {
  220.         this->X = Clamp(this->X, 1, 255);
  221.         this->Y = Clamp(this->Y, 1, 175);
  222.         int timer = 22;
  223.         while(this->isValid())
  224.         {
  225.             this->X = Clamp(this->X, 1, 255);
  226.             this->Y = Clamp(this->Y, 1, 175);
  227.             --timer;
  228.             if ( timer < 1 ) { Remove(this); Quit(); }
  229.             Waitframe();
  230.         }
  231.     }
  232. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement