Changing en entity to a difrent one: script help...

PS_VITA

Active member
I'm trying to change these window background objects from type none to type obstacle - but only under the condition that
2 or more enemies exist on the screen -  I have set anim idle to loop 1

please see the code below.



Code:
name	   windowb
health	   10000
type	    NONE
nolife 1
nodieblink 3
facing 1
candamage	none 
projectilehit   player enemy npc 
offscreenkill 70000
noatflash 1
flash woodhit
nomove 1 1
subject_to_wall 0


load gdebris


anim spawn
@script
    void self = getlocalvar("self");
    if(frame==0){
      changeentityproperty(self, "Subject_to_Gravity", 0);
      changeentityproperty(self, "Subject_to_Wall", 0);

    }
@end_script
	loop	0
        delay	3
        offset 0 0
        frame data/levels/st2c/windowb0.png







anim idle
@script
    void self = getlocalvar("self");
    void target = findtarget(self); // locked opponent


    if( target != NULL() && getentityproperty(target,"exists")){
      int vEnemy = openborvariant("count_enemies");

    if ( vEnemy > 1 ) {
        changeentityproperty(self, "type", openborconstant("TYPE_OBSTACLE"));
      }
   }
	@end_script
@script
    void self = getlocalvar("self");
    if(frame==0){
      changeentityproperty(self, "Subject_to_Gravity", 0);
      changeentityproperty(self, "Subject_to_Wall", 0);
    }
@end_script
@script
       void self = getlocalvar("self");
       int health = getentityproperty(self,"health");
       if (health < 10000){
       changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW1"));
       }
@end_script
       loop 1
       move 0
       delay	3
       offset 0 0
       platform 1 1 1 1 1 1 1 1
       bbox   65 40 55 100                   #bbox   0 0 156 144
       frame data/levels/st2c/windowb0.png

 
anim FOLLOW1
       @script
       void self = getlocalvar("self");
       if (frame==1){
       changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW2"));
       }
       @end_script
       loop 0
       delay	3
       move 0
       offset 0 0
platform 1 1 1 1 1 1 1 1
       frame data/levels/st2c/windowb.png
       frame data/levels/st2c/windowb.png
       spawnframe 0 0 0 0 0
       custentity gdebris


anim FOLLOW2
@script
    void self = getlocalvar("self");
    if(frame==1){
    changeentityproperty(self, "type", openborconstant("TYPE_NONE"));
    }
@end_script
       @script
       void self = getlocalvar("self");
       if (frame==1){
       changeentityproperty(self, "animation", openborconstant("ANI_FOLLOW2"));
       }
       @end_script
       loop 1
       delay	5555
       move 0
       offset 0 0
       platform 1 1 1 1 1 1 1 1
       frame data/levels/st2c/windowb.png
       frame data/levels/st2c/windowb.png



This is the script in question :

Code:
@script
    void self = getlocalvar("self");
    void target = findtarget(self); // locked opponent


    if( target != NULL() && getentityproperty(target,"exists")){
      int vEnemy = openborvariant("count_enemies");

    if ( vEnemy > 1 ) {
        changeentityproperty(self, "type", openborconstant("TYPE_OBSTACLE"));
      }
   }
	@end_script
 
The scripts in the entity text are .... messy. Two are redundant, another might work but redundant and not good, one probably not going to work, and the rest should work.

Before I could share type changing script, I need to ask, what is actually you're trying to make here? why can't this window be obstacle from the start?
 
Bloodbane said:
The scripts in the entity text are .... messy. Two are redundant, another might work but redundant and not good, one probably not going to work, and the rest should work.

Before I could share type changing script, I need to ask, what is actually you're trying to make here? why can't this window be obstacle from the start?

*sighs* I was hoping you wouldn't ask because I'm pretty sure there are probably  many ways of doing this better.  Lol

It's basically a background window which can be broken by enemies who spawn "hobstacle" in their fall animation.  "Hobstacle" is an entity which can hurt obstacles.

But some enemies can also destroy obstacles in different stages but I wanted for a particular stage which happens to have these windows to be able to be switched from none to obstacles.

That way enemies don't go try to break the windows or be hostile to them unless I want to.
 
Hey guys whenever you change a TYPE NONE entity and say that you had set it to have 100 health - if you change it to a TYPE OBSTACLE is it supposed to loose or modify the entity health to a default one?
 
PS VITA said:
Hey guys whenever you change a TYPE NONE entity and say that you had set it to have 100 health - if you change it to a TYPE OBSTACLE is it supposed to loose or modify the entity health to a default one?

First, changing type just changes the type property, nothing else. But that's the problem. The engine uses types to control most of an entity's behavior routines, and just setting a new type alone is likely to cause all sorts of issues.

Second, whatever you are trying to accomplish with this, it won't work.

I get the feeling this relates back to your other thread about falling enemies hitting obstacles, but you've over complicated the issue so much at this point I can't even tell what you're trying to do any more. I can promise that type swapping without an extensive understanding of how they work will only make a bigger mess.

Why don't you start from the beginning and tell us specifically what you want to happen on screen, and let's see what we can do from there.

DC
 
Thank you guys- I ended up just creating a different entity and spawn framed the broken window once the actual window got broken. I didn't want to keep adding more entities to the model.txt file - but I guess that's okay since

changing the window from type_none to type_obstacle did not behave as expected at all.
 
Back
Top Bottom