Solved script flash

Question that is answered or resolved.

O Ilusionista

Captain 100K
hi guys.
I am modifying a damage all enemies script to add a flash by script, but there is something wrong.
I am trying to get the enemies X and Y(a) position to call a flash, but the flash always appears at the wrong position

here is the code:
void damage_all_enemies(int damage, int drop, void atk_type)
{
int  iEntity;
        void vEntity;
        void self        = getlocalvar("self");
        int  iMax        = openborvariant("ent_max"); 

        for(iEntity=0; iEntity<iMax; iEntity++)
        {
        vEntity = getentity(iEntity);
float x = getentityproperty(vEntity, "x");
float a = getentityproperty(vEntity, "a");
if(getentityproperty(vEntity, "type")==openborconstant("TYPE_enemy"))
{
void Spawn;
Spawn = spawn01("flash", x, a, 1);
changeentityproperty(Spawn, "direction", 1);
damageentity(vEntity,self,damage,drop,openborconstant(atk_type));
}
}
}

when facing right, we can see its almost there (but the "a" position is wrong), but when facing left, the "x" position is wrong too:
WSmZMc0.png

CXHOOHk.png


What am I doing wrong?
 
What is the y offset of the flash sprites ? Maybe that's why it doesn't spawn on enemy's feet (as it should with this script).

For x pos, I don't know, maybe this has to do with "xpos" variant. I'd try this :

Code:
 float x = getentityproperty(vEntity, "x") - openborvariant("xpos");

Edit : didn't notice earlier but you are probably using an entity relative spawing function (spawn01), as the flash effect is spawned at Ms. Marvel's feet "a" position. That's probably what is causing this unwanted behavior.
 
What is the y offset of the flash sprites
I am using target "a" for this:
float a = getentityproperty(vEntity, "a");

For x pos, I don't know, maybe this has to do with "xpos" variant. I'd try this :
I tried this before, the result is even worse.

didn't notice earlier but you are probably using an entity relative spawing function (spawn01),
its not player relative, its entity relative (check the loop)
 
I am using target "a" for this:
float a = getentityproperty(vEntity, "a");

Yeah I know, I meant the actual y offset  of the sprites, not the entity one. But that's probably not the problem.




its not player relative, its entity relative (check the loop)

Are you sure ? Cause it really looks like it's using localvar("self") position to adapt the parameters you give.

I suggest you replace spawn01 call with direct call to the engine script functions to figure it out :

Code:
clearspawnentry();
setspawnentry("name", "flash");
setspawnentry("coords", x, 1, a); // should use actual z pos instead of 1 though ; x should be minus openborvariant("xpos") too.
spawn();
clearspawnentry();
 
I give you my debug functions.
It will help you ^__^

Code:
int destroy_all_enemies(void player, int kill_flag) {
    if ( openborvariant("in_level") ) {
        if ( getlevelproperty("type") != 2 ) {
            int p = getentityproperty(player,"playerindex");

            if ( !is_in_pain(player) ) {
                int i;

                for ( i = 0; i < openborvariant("count_entities"); ++i ) { // openborconstant("MAX_ENTS")
                    void ent = getentity(i);

                    if ( !getentityproperty(ent,"exists") ) continue;

                    if ( getentityproperty(ent,"type") == openborconstant("TYPE_ENEMY") ) {
                        int health = getentityproperty(ent,"health");
                        int anim_id = getentityproperty(ent,"animationid");

                        if ( kill_flag != NULL() && kill_flag ) {
                            killentity(ent);
                        } else {
                            if ( getentityproperty(ent,"aiflag","dead") || health <= 0 ) continue;
                            if ( anim_id == openborconstant("ANI_SPAWN") || anim_id == openborconstant("ANI_RESPAWN")  ) continue;
                            // Con "vulnerable" evitiamo anche di uccidere end_level_anim
                            if ( getentityproperty(ent,"vulnerable") ) {
                                float height;
                                damageentity(ent,player,health,1,openborconstant("ATK_NORMAL"));

                                height = getentityproperty(ent,"height");
                                if (height == NULL()) height = 40;
                                void flash = spawnsubentity("cflash",getentityproperty(ent,"x"),getentityproperty(ent,"z"),getentityproperty(ent,"y")+height);
                                changeentityproperty(flash,"no_adjust_base",1);
                                changeentityproperty(flash,"base",getentityproperty(ent,"y")+height);
                            }
                        }
                    }
                } // fine for
            } // fine if attacking
        }
    } // fine if level
}

int show_enemies() {
    if ( openborvariant("in_level") ) {
        if ( getlevelproperty("type") != 2 ) {
            int i, y = 100;

            drawstring( 10,y,0,"enemies: "+openborvariant("count_enemies"));

            for ( i = 0; i < openborvariant("count_entities"); ++i ) { // openborconstant("MAX_ENTS")
                void ent = getentity(i);

                if ( !getentityproperty(ent,"exists") ) continue;
                if ( getentityproperty(ent,"type") == openborconstant("TYPE_ENEMY") ) {
                    y += 10;
                    drawstring( 10,y,0," "+getentityproperty(ent,"model"));
                }
            }
        }
    }
}

void spawnsubentity(char ent, float x, float z, float a) {
    void subent;

      clearspawnentry();
      setspawnentry("name", ent);
      subent = spawn();

      changeentityproperty(subent, "position", x, z, a);

    return subent;
}

int is_in_pain(void self) {
    if ( getentityproperty(self,"aiflag","inpain") || getentityproperty(self,"aiflag","falling") || getentityproperty(self,"aiflag","dead") ) {
        return 1;
    }

    return 0;
}

Use it with line:
show_enemies(); destroy_all_enemies(self,0);
Change the code how u want. There funcs are for level debuggings (cheats)
 
Cause it really looks like it's using localvar("self") position to adapt the parameters you give.
The self is only used in damageentity, not in the spawn or position code.

I tried your code (without the xpos), and the X position is right, but not the Y position (its very high). So I changed the code to this:

Code:
void damage_all_enemies(int damage, int drop, void atk_type)
{
 	int  iEntity; 
        void vEntity;
        void self        = getlocalvar("self");
        int  iMax        = openborvariant("ent_max");   

        for(iEntity=0; iEntity<iMax; iEntity++)
        {
        vEntity = getentity(iEntity);
		float x = getentityproperty(vEntity, "x");
		float a = getentityproperty(vEntity, "a");
		float z = getentityproperty(vEntity, "z");
		void Spawn;
		if(getentityproperty(vEntity, "type")==openborconstant("TYPE_enemy"))
		{
		
		clearspawnentry();
        setspawnentry("name", "flash");
        setspawnentry("coords", x, z+1, a+30);
        spawn();
        clearspawnentry();
		damageentity(vEntity,self,damage,drop,openborconstant(atk_type));
		
		}
	}
}

And now it works. Thanks for your help.

@WD: thanks man.
 
O Ilusionista said:
Cause it really looks like it's using localvar("self") position to adapt the parameters you give.
The self is only used in damageentity, not in the spawn or position code.

I tried your code (without the xpos), and the X position is right, but not the Y position (its very high). So I changed the code to this:

Code:
void damage_all_enemies(int damage, int drop, void atk_type)
{
 	int  iEntity; 
        void vEntity;
        void self        = getlocalvar("self");
        int  iMax        = openborvariant("ent_max");   

        for(iEntity=0; iEntity<iMax; iEntity++)
        {
        vEntity = getentity(iEntity);
		float x = getentityproperty(vEntity, "x");
		float a = getentityproperty(vEntity, "a");
		float z = getentityproperty(vEntity, "z");
		void Spawn;
		if(getentityproperty(vEntity, "type")==openborconstant("TYPE_enemy"))
		{
		
		clearspawnentry();
        setspawnentry("name", "flash");
        setspawnentry("coords", x, z+1, a+30);
        spawn();
        clearspawnentry();
		damageentity(vEntity,self,damage,drop,openborconstant(atk_type));
		
		}
	}
}

And now it works. Thanks for your help.

@WD: thanks man.

ah dont use openborvariant("ent_max")  instead  use openborvariant("count_entities") for speed-up script.
 
ops, I had to use XPos or the positon is wrong

So the final script is:

Code:
void damage_all_enemies(int damage, int drop, void atk_type)
{
 	int  iEntity; 
        void vEntity;
        void self        = getlocalvar("self");
        int  iMax        = openborvariant("count_entities");   

        for(iEntity=0; iEntity<iMax; iEntity++)
        {
        vEntity = getentity(iEntity);
		float x = getentityproperty(vEntity, "x") - openborvariant("xpos");
		float a = getentityproperty(vEntity, "a");
		float z = getentityproperty(vEntity, "z");
		void Spawn;
		if(getentityproperty(vEntity, "type")==openborconstant("TYPE_enemy"))
		{
		
		clearspawnentry();
        setspawnentry("name", "flash");
        setspawnentry("coords", x, z+1, a+30);
        spawn();
        clearspawnentry();
		damageentity(vEntity,self,damage,drop,openborconstant(atk_type));
		
		}
	}
}
 
O Ilusionista said:
The self is only used in damageentity, not in the spawn or position code.

"self" is probably used again in spawn01 code, which is not displayed here.

I tried your code (without the xpos), and the X position is right, but not the Y position (its very high). So I changed the code to this:

Looks good, minus xpos is probably necessary only when using lasthitx I guess (edit : well apparently not  ;D )

 
alright thanks and this should be called through the projectile right? For example I want the flash to appear once enemy is hit by the projectile
 
I'm guessing so.  The projectile will need a followup animation.


Code:
anim	idle
	followcond	2
	followanim	1
	loop	1
	offset	15 16
	delay	3
	bbox	0 0 30 30
	attack	0 0 30 30 8 0 0 0 0 0
	frame	data/chars/misc/bal/bal1a0.png
	attack	0 0 30 30 8 0 0 0 0 0
	frame	data/chars/misc/bal/bal1b0.png

anim	follow1
       @script
       void self = getlocalvar("self");

       if (frame == 0){
       changeentityproperty(self, "velocity", 0, 0, 0);
       changeentityproperty(self, "speed", 0);
       }
       @end_script	
	offset	38 34
	delay	5
	sound	data/sfx/dsfirxpl.wav
	frame	data/chars/misc/bal/bal1c0.png
	offset	43 43
	frame	data/chars/misc/bal/bal1d0.png
	offset	50 45
	frame	data/chars/misc/bal/bal1e0.png
	frame	data/chars/misc/empty.gif
Just FYI
The script here in follow anim is for stopping the projectile's movement when it hit's.

Edit: Been meaning to try this script myself, just haven't got there yet.  Gonna need it for the BFG in Doom.
 
Back
Top Bottom