Advertisement
ZoriaRPG

Daira NPC and EWeapon Scripts for 2.55

Mar 7th, 2019
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.88 KB | None | 0 0
  1. npc script DairaNPC
  2. {
  3.     void run()
  4.     {
  5.  
  6.         //Original Tile
  7.         int OTile = this->OriginalTile;
  8.  
  9.         //Movement Variables
  10.         float counter = -1;
  11.         int step = this->Step;
  12.         int rate = this->Rate;
  13.         int homing = this->Homing;
  14.         int hunger = this->Hunger;
  15.        
  16.         //Weapon Variables
  17.         eweapon wpn;
  18.         int damage = this->WeaponDamage;
  19.         int attackTimer;
  20.         int attackWait; //Time between swings.
  21.         bool throw = (this->Attributes[0]&1);
  22.         //bool shielded = this->Attributes[0]&4;
  23.         int wSprite = this->WeaponSprite; //Ghost_GetAttribute(ghost,1,-1);
  24.  
  25.         //Behavior
  26.         while(this->isValid())
  27.         {
  28.  
  29.             //Attacking
  30.             if(Distance(Link->X, Link->Y, this->X, this->Y) < 80 && attackTimer==0) //Attacks when close to Link.
  31.             {
  32.                 attackWait--;
  33.                 if(attackWait<=0)
  34.                 {
  35.                     attackTimer = 21;
  36.                     attackWait = 60;
  37.                 }
  38.             }
  39.  
  40.             if(attackTimer>0) //Attacking?
  41.             {
  42.                 if(this->OriginalTile == OTile)
  43.                 {
  44.                     wpn=Screen->CreateEWeapon(EW_BEAM);
  45.                     wpn->Dir = Ghost_Dir;
  46.                     wpn->Step= 200;
  47.                     wpn->UseSprite(wSprite);
  48.                     wpn->Damage=damage;
  49.                     wpn->Angular=false;
  50.                     wpn->Script = 1; //daira axe
  51.                     wpn->CSet = this->CSet;
  52.                 }
  53.                 else if(!wpn->isValid())
  54.                 {
  55.                     this->OriginalTile = OTile;
  56.                     Waitframe();
  57.                     attackTimer = 0;
  58.                     continue;
  59.                 }
  60.                 this->OriginalTile = OTile + 20*Div(28-attackTimer, 7);
  61.                 wpn->Tile = this->OriginalTile+this->Dir+16;
  62.                 wpn->X = this->X;
  63.                 wpn->Y = this->Y;
  64.                 wpn->DeadState = WDS_ALIVE;
  65.                 if(attackTimer>14)
  66.                 {
  67.                     if((this->Dir == DIR_UP || this->Dir == DIR_DOWN))
  68.                         wpn->Y -= 16;
  69.                     else wpn->X -= InFrontX(this->Dir, 0);
  70.                 }
  71.                 else if(attackTimer>7)
  72.                 {
  73.                     if(this->Dir == DIR_UP || this->Dir == DIR_DOWN)
  74.                     {
  75.                         if(this->Dir == DIR_UP )
  76.                             wpn->Y -= 16;
  77.                     }
  78.                     else
  79.                     {
  80.                         wpn->X += InFrontX(this->Dir, 0);
  81.                     }
  82.                 }
  83.                 else
  84.                 {
  85.                     wpn->X += InFrontX(this->Dir,0);
  86.                     wpn->Y += InFrontY(this->Dir,0);
  87.                 }
  88.                 //the weapon hit boxes are small.
  89.                 SetWpnHitOffsets(wpn, Div(28-attackTimer, 7), this->Dir);
  90.                 attackTimer--;
  91.             }
  92.             else if(wpn->isValid())
  93.             {
  94.                 this->OriginalTile = OTile;
  95.                 if(throw)
  96.                 {
  97.                     wpn=Screen->CreateEWeapon(EW_BEAM);
  98.                     wpn->Dir = Ghost_Dir;
  99.                     wpn->Step= 200;
  100.                     wpn->UseSprite(wSprite);
  101.                     wpn->Damage=damage;
  102.                     wpn->Angular=false;
  103.                     wpn->Script = 1; //daira axe
  104.                    
  105.                     this->OriginalTile = this->OriginalTile + 80 + (this->Dir*4);
  106.                 }
  107.             }
  108.             if(this->HP <= 0)
  109.             {
  110.                 wpn->DeadState = WDS_DEAD;
  111.                 Quit();
  112.             }
  113.             Waitframe();
  114.         }
  115.     }
  116.     void SetWpnHitOffsets(eweapon wpn, int frame, int dir)
  117.     {
  118.         //Set Default Collision Properties
  119.         wpn->CollDetection = true;
  120.         wpn->HitXOffset = 0;
  121.         wpn->HitYOffset = 0;
  122.         wpn->HitWidth = 16;
  123.         wpn->HitHeight = 16;
  124.  
  125.         //Modify it based off attack frame.
  126.         if(frame == 1)
  127.         {
  128.             if(dir == DIR_UP || dir == DIR_DOWN)
  129.             {
  130.                 wpn->CollDetection = false;
  131.                 return;
  132.             }
  133.             else
  134.                 wpn->HitWidth = 8;
  135.             if(dir == DIR_RIGHT)
  136.                 wpn->HitXOffset = 8;
  137.         }
  138.         else if(frame == 2)
  139.         {
  140.             if(dir == DIR_UP || dir==DIR_DOWN)
  141.             {
  142.                 wpn->HitHeight = 8;
  143.                 return;
  144.             }
  145.             else
  146.                 wpn->HitWidth = 8;
  147.             if(dir == DIR_LEFT)
  148.             wpn->HitXOffset = 8;
  149.         }
  150.         else if(frame == 3)
  151.         {
  152.             wpn->HitXOffset = Cond(dir==DIR_LEFT, 8, 0);
  153.             wpn->HitYOffset = Cond(dir==DIR_UP, 8, 0);
  154.             wpn->HitWidth = Cond(dir==DIR_LEFT||dir==DIR_RIGHT, 8, 16);
  155.             wpn->HitHeight = Cond(dir==DIR_UP||dir==DIR_DOWN, 8, 16);
  156.         }
  157.         else //Out of range.
  158.         {
  159.             wpn->DeadState = WDS_DEAD;
  160.             return;
  161.         }
  162.     }
  163. }
  164.  
  165. eweapon script dairaaxe
  166. {
  167.     void run()
  168.     {
  169.         this->X = Clamp(this->X, 1, 255);
  170.         this->Y = Clamp(this->Y, 1, 175);
  171.         int timer = 22;
  172.         while(this->isValid())
  173.         {
  174.             this->X = Clamp(this->X, 1, 255);
  175.             this->Y = Clamp(this->Y, 1, 175);
  176.             --timer;
  177.             if ( timer < 1 ) { Remove(this); Quit(); }
  178.             Waitframe();
  179.         }
  180.     }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement