Jump to content

Photo

Magic Mirror-like FFC Script


  • Please log in to reply
10 replies to this topic

#1 idontknow8

idontknow8

    Senior

  • Members

Posted 24 July 2016 - 01:16 PM

Can anyone make a script so that when any projectile (arrow, magic, rock, fireball, sword beams, etc) hits this FFC, it gets reflected back in the direction it came from?  This includes those from Link and from enemies.

 

Can you make two more similar ones:  One that reflect the item 90 degrees clockwise and another that reflects it 90 degrees counter-clockwise?

 

Thank you!



#2 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 24 July 2016 - 05:49 PM

Sure. If you can wait a day or so. I have functions specifically for that in std-update.

 

I thought you wanted the Z3 mirror, which I've already made...twice.



#3 idontknow8

idontknow8

    Senior

  • Members

Posted 26 July 2016 - 01:32 AM

No, what's the Z3 mirror?

 

I just want a FFC Script that makes a freeform combo reflect magic, and also want it to so that I could easily copy & paste this script to other script I already have.



#4 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 26 July 2016 - 01:49 AM

No, what's the Z3 mirror?
 
I just want a FFC Script that makes a freeform combo reflect magic, and also want it to so that I could easily copy & paste this script to other script I already have.


Wait... Only magic now? You said any projectile, above...
 
ffc script ReflectMagic{
	void run(){
		eweapon e; lweapon l; int q;
		while(true){
			for ( q = 1; q < Screen->NumLWeapons(); q++ ) {
				l = Screen->LoadLWeapon(q);
				if ( l->ID == LW_MAGIC ) {
					if ( Collision(l, this) ) { 
						l->Dir = __DirRev(l->Dir);
						l->Flip = __FlipRef(l);
					}
				}
			}
			for ( q = 1; q <= Screen->NumEWeapons(); q++ ) {
				e = Screen->LoadEWeapon(q); 
				if ( e->ID == EW_MAGIC ) {
					if ( Collision(e, this) ) {
						e->Dir = __DirRev(e->Dir);
						e->Flip = __FlipRef(e);
					}
				}
			}
				
			Waitframe();
		}
	}
	void __FlipRef(lweapon l){
		if ( l->Dir == DIR_DOWN || l->Dir == DIR_UP && !l->Flip ) l->Flip = 2; 
		if ( l->Dir == DIR_LEFT || l->Dir == DIR_RIGHT && !l->Flip ) l->Flip == 1;
	}

	void __FlipRef(eweapon l){
		if ( l->Dir == DIR_DOWN || l->Dir == DIR_UP && !l->Flip ) l->Flip = 2; 
		if ( l->Dir == DIR_LEFT || l->Dir == DIR_RIGHT && !l->Flip ) l->Flip == 1;
	}
	
	int __DirRev(int dir) {
		if ( dir == DIR_LEFT) return DIR_RIGHT;
		if ( dir == DIR_DOWN) return DIR_UP;
		if ( dir == DIR_UP) return DIR_DOWN;
		if ( dir == DIR_RIGHT) return DIR_LEFT;
		if ( dir == DIR_LEFTUP) return DIR_RIGHTDOWN;
		if ( dir == DIR_RIGHTDOWN) return DIR_LEFTUP;
		if ( dir == DIR_LEFTDOWN) return DIR_RIGHTUP;
		if ( dir == DIR_RIGHTUP) return DIR_LEFTDOWN;
	}
}

Edited by ZoriaRPG, 26 July 2016 - 01:59 AM.


#5 idontknow8

idontknow8

    Senior

  • Members

Posted 26 July 2016 - 11:14 PM

Oops!  I mispoke.  I did mean any projectile.  But it's good to know how to do just magic too, which I see you've already done.  So how would you edit this to be ANY projectile???



#6 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 26 July 2016 - 11:22 PM

Just expand the if statement with if ( i>Type == LW_MAGIC ) using inclusive ORs...

if ( l->Type == LW_MAGIC || l->Type ==  LW_ARROW || l->Type == LW_BEAM )
I didn't test that code, so it could have very minor typos/typo-esque bugs. (I'm not even sure if I compiled it.) I pounded out 2500 lines or more, plus extensive testing, and deugging today, and now I'm unsure which of the requests I properly tested.

Usually, I post them, and if there is a problem, I go back and fix it, if the user requesting it, or another member doesn't do it first. That allows me to get 99% complete code into the hands of the user as soon as possible, rather than making the user wait for me to have time to proof it properly.

Edited by ZoriaRPG, 27 July 2016 - 12:08 AM.


#7 idontknow8

idontknow8

    Senior

  • Members

Posted 26 July 2016 - 11:28 PM

Ah!  Great thank you!



#8 idontknow8

idontknow8

    Senior

  • Members

Posted 27 July 2016 - 02:29 PM

Error 117:  Cannot cast from void to float...

l->Flip = __FlipRef(l);


#9 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 27 July 2016 - 09:57 PM

Demo Quest

 

Here's the finished product:
 


 
Note: Objects will only be reflected once. Allowing them to repeatedly reflect is too buggy.


Edited by ZoriaRPG, 27 July 2016 - 09:58 PM.


#10 idontknow8

idontknow8

    Senior

  • Members

Posted 28 July 2016 - 01:36 AM

got errors saying "lweapontoeweapon undeclared" and same thing for "eweapontolweapon"



#11 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 28 July 2016 - 12:49 PM

 
import "std.zh"

//////////////////////////////
/// Reflect Weapons by FFC ///
/// By: ZoriaRPG           ///
/// v1.0                   ///
/// 28th July, 2016        ///
////////////////////////////////////////////////////////////////////////////////////////////////////
/// FFC Data Args:                                                                               ///
/// D0: Set to '1' or above, to cause reflected weapons to turn into their opposite:             ///
///     eweapons become lweapons, and lweapons become eweapons, similar to the standard mirrors. ///
////////////////////////////////////////////////////////////////////////////////////////////////////



const int REFLECT_SENSITIVITY = 12;
const int MISC_STATUS = 5;
const int WEAP_STATUS_REFL = 101;             

ffc script ReflectMagic{
    void run(int changetype){
        eweapon e; lweapon l; int q; int w;
        while(true){
            for ( w = 1; w <= Screen->NumLWeapons(); w++ ) {
                l = Screen->LoadLWeapon(w);
                if ( ( l->ID == LW_MAGIC || l->ID == LW_ARROW || l->ID == LW_BEAM  ) && l->Misc[MISC_STATUS] != WEAP_STATUS_REFL ) {
                    if ( __DistXY(this,l,REFLECT_SENSITIVITY) ) {
                        if ( !changetype ) {
                            l->Dir = __DirRev(l->Dir);
                            l->Flip = __FlipRef(l);
                            l->Misc[MISC_STATUS] = WEAP_STATUS_REFL;
                        }
                        if ( changetype ) {
                            if ( __LWeaponToEWeaponID(l->ID) >= 0 ) {
                                l->Dir = __DirRev(l->Dir);
                                l->Flip = __FlipRef(l);
                                eweapon b = __LWeaponToEWeapon(l);
                                l->Misc[MISC_STATUS] = WEAP_STATUS_REFL;
                                b->Misc[MISC_STATUS] = WEAP_STATUS_REFL;
                                Remove(l);
                            }
                        }
                    }
                }
            }
            for ( q = 1; q <= Screen->NumEWeapons(); q++ ) {
                e = Screen->LoadEWeapon(q);
                if ( ( e->ID == EW_MAGIC || e->ID == EW_ARROW || e->ID == EW_BEAM || e->ID == EW_WIND || e->ID == EW_FIREBALL || e->ID == EW_ROCK ) && e->Misc[MISC_STATUS] != WEAP_STATUS_REFL ) {
                    if ( __DistXY(this,e,REFLECT_SENSITIVITY) ) {
                        if ( !changetype ) {
                            e->Misc[MISC_STATUS] = WEAP_STATUS_REFL;
                            e->Dir = __DirRev(e->Dir);
                            e->Flip = __FlipRef(e);
                        }
                        if ( changetype ) {
                            if ( __EWeaponToLWeaponID(e->ID) >= 0 ) {
                                e->Dir = __DirRev(e->Dir);
                                e->Flip = __FlipRef(e);
                                lweapon c = __EWeaponToLWeapon(e);
                                c->Misc[MISC_STATUS] = WEAP_STATUS_REFL;
                                Remove(e);
                            }
                        }
                    }
                }
            }
                
            Waitframe();
        }
    }
    
    int __FlipRef(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;
    }

    int __FlipRef(eweapon 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;
    }
    
    int __DirRev(int dir) {
        if ( dir == DIR_LEFT) return DIR_RIGHT;
        if ( dir == DIR_DOWN) return DIR_UP;
        if ( dir == DIR_UP) return DIR_DOWN;
        if ( dir == DIR_RIGHT) return DIR_LEFT;
        if ( dir == DIR_LEFTUP) return DIR_RIGHTDOWN;
        if ( dir == DIR_RIGHTDOWN) return DIR_LEFTUP;
        if ( dir == DIR_LEFTDOWN) return DIR_RIGHTUP;
        if ( dir == DIR_RIGHTUP) return DIR_LEFTDOWN;
    }
    
    bool __DistX(ffc a, lweapon b, int distance) {
        int dist;
        if ( a->X > b->X ) dist = a->X - b->X;
        else dist = b->X - a->X;
        return ( dist <= distance );
    }
    bool __DistX(ffc a, eweapon b, int distance) {
        int dist;
        if ( a->X > b->X ) dist = a->X - b->X;
        else dist = b->X - a->X;
        return ( dist <= distance );
    }
    
    bool __DistY(ffc a, lweapon b, int distance) {
        int dist;
        if ( a->Y > b->Y ) dist = a->Y - b->Y;
        else dist = b->Y - a->Y;
        return ( dist <= distance );
    }
    bool __DistY(ffc a, eweapon b, int distance) {
        int dist;
        if ( a->Y > b->Y ) dist = a->Y - b->Y;
        else dist = b->Y - a->Y;
        return ( dist <= distance );
    }
    bool __DistXY(ffc a, lweapon b, int distance) {
        int distx; int disty;
        if ( a->X > b->X ) distx = a->X - b->X;
        else distx = b->X - a->X;
    
        if ( a->Y > b->Y ) disty = a->Y - b->Y;
        else disty = b->Y - a->Y;

        return ( distx <= distance && disty <= distance );
    }

    bool __DistXY(ffc a, eweapon b, int distance) {
        int distx; int disty;
        if ( a->X > b->X ) distx = a->X - b->X;
        else distx = b->X - a->X;
    
        if ( a->Y > b->Y ) disty = a->Y - b->Y;
        else disty = b->Y - a->Y;

        return ( distx <= distance && disty <= distance );
    }
    lweapon __EWeaponToLWeapon(eweapon a){
        int type = EWeaponToLWeaponID(a->ID);
        //if ( type == -1 ) return type;
        lweapon b = Screen->CreateLWeapon(type);
        b->X = a->X;
        b->Y = a->Y;
        b->Z = a->Z;
        b->Jump = a->Jump;
        b->Extend = a->Extend;
        b->TileWidth = a->TileWidth;
        b->TileHeight = a->TileHeight;
        b->HitWidth = a->HitWidth;
        b->HitHeight = a->HitHeight;
        b->HitZHeight = a->HitZHeight;
        b->HitXOffset = a->HitXOffset;
        b->HitYOffset = a->HitYOffset;
        b->DrawXOffset = a->DrawXOffset;
        b->DrawYOffset = a->DrawYOffset;
        b->DrawZOffset = a->DrawZOffset;
        b->Tile = a->Tile;
        b->CSet = a->CSet;
        b->DrawStyle = a->DrawStyle;
        b->Dir = a->Dir;
        b->OriginalTile = a->OriginalTile;
        b->OriginalCSet = a->OriginalCSet;
        b->FlashCSet = a->FlashCSet;
        b->NumFrames = a->NumFrames;
        b->Frame = a->Frame;
        b->ASpeed = a->ASpeed;
        b->Damage = a->Damage;
        b->Step = a->Step;
        b->Angle = a->Angle;
        b->Angular = a->Angular;
        b->CollDetection = a->CollDetection;
        b->DeadState = a->DeadState;
        b->Flash = a->Flash;
        b->Flip = a->Flip;
        for (int i = 0; i < 16; i++)
            b->Misc[i] = a->Misc[i];
        return b;
    }



    //Copy the attributes of a given lweapon to a new eweapon.
    //Returns -1 on error, including if the type (weap->ID) conversion is illegal.
    eweapon __LWeaponToEWeapon(lweapon a){
        int type = LWeaponToEWeaponID(a->ID);
    //    if ( type == -1 ) return type;
        eweapon b = Screen->CreateEWeapon(type);
        b->X = a->X;
        b->Y = a->Y;
        b->Z = a->Z;
        b->Jump = a->Jump;
        b->Extend = a->Extend;
        b->TileWidth = a->TileWidth;
        b->TileHeight = a->TileHeight;
        b->HitWidth = a->HitWidth;
        b->HitHeight = a->HitHeight;
        b->HitZHeight = a->HitZHeight;
        b->HitXOffset = a->HitXOffset;
        b->HitYOffset = a->HitYOffset;
        b->DrawXOffset = a->DrawXOffset;
        b->DrawYOffset = a->DrawYOffset;
        b->DrawZOffset = a->DrawZOffset;
        b->Tile = a->Tile;
        b->CSet = a->CSet;
        b->DrawStyle = a->DrawStyle;
        b->Dir = a->Dir;
        b->OriginalTile = a->OriginalTile;
        b->OriginalCSet = a->OriginalCSet;
        b->FlashCSet = a->FlashCSet;
        b->NumFrames = a->NumFrames;
        b->Frame = a->Frame;
        b->ASpeed = a->ASpeed;
        b->Damage = a->Damage;
        b->Step = a->Step;
        b->Angle = a->Angle;
        b->Angular = a->Angular;
        b->CollDetection = a->CollDetection;
        b->DeadState = a->DeadState;
        b->Flash = a->Flash;
        b->Flip = a->Flip;
        for (int i = 0; i < 16; i++)
            b->Misc[i] = a->Misc[i];
        return b;
    }
    
    //Converts the ID (type) of a given weapon to its opposite class.
    //Returns -1 if the type is illegal.
    int __EWeaponToLWeaponID(int type){
        if ( type == EW_ARROW ) return LW_ARROW;
        if ( type == EW_BRANG ) return LW_BRANG;
        if ( type == EW_BEAM ) return LW_BEAM;
        if ( type == EW_MAGIC ) return LW_MAGIC;
        if ( type == EW_BOMB ) return LW_BOMB;
        if ( type == EW_BOMBBLAST ) return LW_BOMBBLAST;
        if ( type == EW_SBOMB ) return LW_SBOMB;
        if ( type == EW_SBOMBBLAST ) return LW_SBOMBBLAST;
        if ( type == EW_WIND ) return LW_WIND;
        if ( type >= 31 && type <= 40 ) return type;
        else return -1;
    }

    //Converts the ID (type) of a given weapon to its opposite class.
    //Returns -1 if the type is illegal.
    int __LWeaponToEWeaponID(int type){
        if ( type == LW_ARROW ) return EW_ARROW;
        if ( type == LW_BRANG ) return EW_BRANG;
        if ( type == LW_BEAM ) return EW_BEAM;
        if ( type == LW_MAGIC ) return EW_MAGIC;
        if ( type == LW_BOMB ) return EW_BOMB;
        if ( type == LW_BOMBBLAST ) return EW_BOMBBLAST;
        if ( type == LW_SBOMB ) return EW_SBOMB;
        if ( type == LW_SBOMBBLAST ) return EW_SBOMBBLAST;
        if ( type == LW_WIND ) return EW_WIND;
        if ( type >= 31 && type <= 40 ) return type;
        else return -1;
    }

}
 



1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users