About Variables

O Ilusionista

Captain 100K
I need some help to get the variables set on a char. I understand how they works in Mugen and other languages, but something is still missing on my BOR understanding.

Explanation:

Captain America, on his hyper, throws a shield which bounces on the screen edges couple of times until gets back to Captain, then it gets destroyed.

What do I need?

Since Shield is a different entity, I want to make Captain aware of if there is no shield (IOW, the shield had returned to him), he will switch for another anim (grabbing the shield back, for example).

What I have:

at Shield code:
  int ShieldC= getglobalvar("ShieldC");// shield control

    if(ShieldC==NULL()){
    setglobalvar("ShieldC", 1);
    ShieldC = 1;
  }
(do I need the last part?)

When the shield stops to bounce, it goes to a Follow1 anim:

  void self = getlocalvar("self"); // Get calling entity.
  void Owner = getentityproperty(self, "owner"); // Get owner
  int x = getentityproperty(self, "x"); // Get current x coordinate
  int Ox = getentityproperty(Owner, "x"); // Get Owner's x coordinate

  if(x <= Ox + 10 && x >= Ox - 10){ // Close to owner's x?
    setglobalvar("ShieldC",0);
    killentity(self); //Suicide!
  }

At Captain:

int ShieldC= getglobalvar("ShieldC");// shield control
void vSelf = getlocalvar("self");
ShieldC=1;
        if(ShieldC==0){
        changeentityproperty(vSelf, "animation", openborconstant("ANI_ATTACK4"));
  }

But it doesn't works, Captain doesn't detects the shield. If you use the move more times, then it start to automatically go to attack4 anim.

What am I missing?

Some images of the debug
rjOagvu.png

d9oYFES.png

wziB4YI.png
 
I had some progress:

I isolated the shield check into another file, as a funcion:

void checkShield (int sVal, void Ani)
{
void vSelf = getlocalvar("self");
int ShieldC= getglobalvar("ShieldC");
if(ShieldC==sVal){
      performattack(vSelf, openborconstant(Ani));
  }
}

And I call it on the fame I need:
delay 600
frame data/chars/captain/Free1-5.pcx
@cmd checkShield 0 "ANI_ATTACK4"

The problem now is: Captain only goes to the ani_attack4 AFTER the frame time is completed, not right when the value is 0.

Should I use aniPos?
 
Well this is like my boomerang.

Here my method:
1) You need to set the parent when you launch the shield:
so add in your launch anim this script:
Code:
	@script
		void self = getlocalvar("self");
        	float x = getentityproperty(self, "x");
        	float z = getentityproperty(self, "z");
        	float a = getentityproperty(self, "a");

		if ( getentityproperty(self, "animpos") == 8 ) {
			void ent;

			clearspawnentry();
                        setspawnentry("name", "shield"); // LOAD ENTITY FIRST
                        ent = spawn();
			changeentityproperty(ent, "parent", self);
			changeentityproperty(ent, "base", a+42);
			changeentityproperty(ent, "direction", getentityproperty(self, "direction"));

                        if ( getentityproperty(self, "direction") == 1 ) {
                            changeentityproperty(ent, "position", x+45, z, a+42);
                        } else {
                            changeentityproperty(ent, "position", x-45, z, a+42);
                        }
		}
	@end_script
How you see I set the parent: changeentityproperty(ent, "parent", self);

2) Create a shield entity, then you can copy my script:
Code:
	@script
		void self = getlocalvar("self");
		void parent = getentityproperty(self, "parent");
		void opp = getentityproperty(self, "opponent");
        	float xdir = getentityproperty(self, "xdir");
        	float zdir = getentityproperty(self, "zdir");
        	float tossv = getentityproperty(self, "tossv");
        	float x = getentityproperty(self, "x");
        	float a = getentityproperty(self, "a");
        	float z = getentityproperty(self, "z");
		float max_vel = 2.5, vel_factor = 0.4;
		int max_dist = 120, min_dist = 45, t_dist = 5;
		int HITBYID_RESET_TIME = 200;

		// Resettiamo hitbyid ad ogni cambio di giro
		if (opp && (xdir >= max_vel || xdir <= -1*max_vel) ) changeentityproperty(opp, "hitbyid", 0);
		else if (opp && (xdir >= 0 || xdir <= vel_factor) ) changeentityproperty(opp, "hitbyid", 0);
		else if (opp && (xdir >= -1*vel_factor || xdir <= 0) ) changeentityproperty(opp, "hitbyid", 0);

		if ( getentityvar(self, 0) == NULL() && getentityproperty(self, "animpos") <= 1 ) { // Impostiamo la velocità solo all'inizio
			if ( parent ) {
				if ( getentityproperty(parent, "direction") == 1 ) xdir = max_vel;
				else xdir = -1*max_vel;
			} else {
				if ( getentityproperty(self, "direction") == 1 ) xdir = max_vel;
				else xdir = -1*max_vel;
			}

			if (parent) setentityvar(self, 1, getentityproperty(parent, "hitbyid")); // Memorizziamo lo stato del soldato
			if ( getentityproperty(self, "animpos") == 1 ) setentityvar(self,0,1);
		}

		if ( parent ) {
			z = getentityproperty(parent, "z");

			if ( getentityproperty(self, "x") > getentityproperty(parent, "x") ) { // se il boomerang è a destra del launcher...
				float dist = getentityproperty(self, "x")-getentityproperty(parent, "x");

				if ( dist > max_dist ) {
					xdir -= vel_factor;
					if ( xdir < -1*max_vel ) xdir = -1*max_vel; // Non andiamo oltre la velocità consentita
					setentityvar(self,2,1); // primo giro completo
				} else if ( dist-t_dist < min_dist && getentityvar(self,2) == 1 ) {
					performattack(parent, openborconstant("ANI_FOLLOW17"), 1);
					killentity(self);
				}
			} else { // se il boomerang è a sinistra del launcher...
				float dist = getentityproperty(parent, "x")-getentityproperty(self, "x");

				if ( dist > max_dist ) {
					xdir += vel_factor;
					if ( xdir > max_vel ) xdir = max_vel;
					setentityvar(self,2,1); // primo giro completo
				} else if ( dist-t_dist < min_dist && getentityvar(self,2) == 1 ) {
					performattack(parent, openborconstant("ANI_FOLLOW17"), 1);
					killentity(self);
				}
			}

			// Se il foot viene colpito, non leghiamo più il boomerang al foot
			if ( getentityvar(self,1) != getentityproperty(parent, "hitbyid") || opp == parent ) {
				changeentityproperty(self, "parent", NULL());
			} else if ( getentityproperty(parent, "aiflag", "inpain") || getentityproperty(parent, "aiflag", "falling") || getentityproperty(parent, "aiflag", "dead") ) {
				//changeentityproperty(self, "parent", NULL());
			}
		} else {
			if ( xdir > 0 ) xdir = max_vel;
			else xdir = -1*max_vel;

			// fai che muore quando oltrepassa lo schermo e idle il foot!!
			// su death idle il foot
			if ( xdir > 0 && x-openborvariant("xpos") > openborvariant("hresolution") ) {
				killentity(self);
			} else if ( xdir <= 0 && x-openborvariant("xpos") < 0 ) {
				killentity(self);
			}

		}

		//changeentityproperty(self, "position", x, z, a);
		changeentityproperty(self, "velocity", xdir, zdir, tossv);
	@end_script

So in this case when captain get the shield he performs the "ANI_FOLLOW17" anim.

3) To perform a stall animation when you launch the shield you can use this trick: loop 1 3 4 where 3rd frame is the stall frame

However if you don't like my script, to perform a bounce near offscreen offset you can use onblocksscript event or you can check the offset with:
left bound: openborvariant("xpos")
right bound: openborvariant("xpos")+openborvariant("hresolution")
 
Back
Top Bottom