//Bomb Arrow Script for 2.55
//v0.2
//By ZoriaRPG
//19th March, 2019
//v0.1 : Initial
//v0.2 : Fix comppile, and fix how we check if the arrow is dead to create the explosion.
// : We cannot run the explosion after while(this->isValid()), because the script runs out of scope if the
// : sprite is no longer on the screen. Thus, we check its deadstate, while it is valid.
lweapon script ReplaceOnDeath
{
void run(int newWeaponType, int requireItem, int requireCounter, int CounterAmount, bool flipOnDeath, bool newDirOnDeath, int newDir, int newScript) //could be flags here
{
itemdata bomb; bool found; bool super; int x; int y; int pow;
if ( requireItem > 0 )
{
bomb = Game->LoadItemData(Link->ItemA);
if ( bomb->ID == requireItem ) found = true;
if ( !found )
{
bomb = Game->LoadItemData(Link->ItemB);
if ( bomb->Family == IC_BOMB ) { found = true; }
}
if ( !found ) Quit(); //quit if bombs not in a slot
}
pow = bomb->Power;
if ( requireCounter )
{
if ( !Game->Counter[requireCounter] < CounterAmount ) Quit(); //quit if not enough bombs
else Game->Counter[requireCounter] -=CounterAmount;
}
while(this->isValid())
{
x = this->X; y = this->Y;
if ( this->DeadState != WDS_ALIVE ) //When the arrow itself dies, make an explosion.
{
lweapon boom = Screen->CreateLWeapon(newWeaponType);
boom->Damage = pow;
boom->X = x;
boom->Y = y;
if ( flipOnDeath ) ReflectWeapon(boom, this->Angular);
else if ( newDirOnDeath ) { boom->Dir = newDir; boom->Flip = FlipRev(boom); }
if ( Abs(newScript) < 511 ) boom->Script = newScript;
}
Waitframe();
}
}
int FlipRev(lweapon l){
if ( l->Dir == DIR_DOWN || l->Dir == DIR_UP && !l->Flip ) return 2;
if ( l->Dir == DIR_DOWN || l->Dir == DIR_UP && l->Flip ) return 0;
if ( l->Dir == DIR_LEFT || l->Dir == DIR_RIGHT && !l->Flip ) return 1;
if ( l->Dir == DIR_LEFT || l->Dir == DIR_RIGHT && l->Flip ) return 0;
return -1;
}
lweapon ReflectWeapon(lweapon l, bool angular)
{
l->Dir = DirRev(l->Dir);
l->Flip = FlipRev(l);
l->Angular = angular;
if ( angular )
{
if (l->Angle >= 180 ) l->Angle -= 180;
else l->Angle += 180;
}
}
}
Comments