Toranks
Active member
I have an entity to release from grabs mashing buttons. This is the first lines of this entity and the problematic code. On my brother computer, I can release easy, but on my computer that is not bad but does not reach the power of him's, I can release but a bit harder with 16-bit advance Mame2x. But with with 16-bit simple2X it becomes very hard to achieve, with some enemies it becomes absolutely impossible. This is strange, but I suppose is related to some bad use of variables and commands in this code. Could someone help me improve it? Basically what I want is to add 1 + hp to the entity each time one of the buttons that I indicate at the end of the code is pressed, and if the life of the entity is filled, the player is released from the enemy grab. From the beginning this entity has worked with problems because of this code, and I had to make many modifications to make it work well over the years, and now that it was doing better than ever, this strange problem appears to me...
C#:
name grab1
type obstacle
scroll 1
health 300
speed 0
nomove 1 1
facing 1
noquake 1
shadow 0
falldie 1
antigrab 10
offscreenkill 30000
subject_to_wall 0
subject_to_platform 0
subject_to_obstacle 0
subject_to_hole 0
subject_to_gravity 0
diesound data/sounds/empty.wav
setlayer 999999998
lifebarstatus 150 20 0 1 0 2 5
lifeposition 120 240
nameposition -200 -200
nolife 1
script @script
void main()
{
void self = getlocalvar("self");
void attacker = getentityproperty(self,"parent");
void victim2 = getentityvar(self, "target");
void victim = getentityvar(self, "player");
int HP = getentityproperty(self,"health");
int HPmax = getentityproperty(self,"maxhealth");
int x1 = getentityproperty(attacker,"x");
int z1 = getentityproperty(attacker,"z");
int escape = getentityvar(self, "grabgo"); //johnny madjon
if (attacker!=NULL() && victim2 !=NULL())
{// checking if the pointers are valid
if(HP>=HPmax && escape == 1){
changeentityproperty(victim2, "position", x1, z1);
performattack(victim2, openborconstant("ANI_FOLLOW15"));
setidle(attacker, openborconstant("ANI_IDLE"));
bindentity(victim2, NULL());
performattack(attacker, openborconstant("ANI_PAIN8"));
setentityvar(self, "madjon", NULL());
killentity(self);
} else if(HP>=HPmax && escape == 2){
changeentityproperty(victim2, "position", x1, z1);
performattack(victim2, openborconstant("ANI_FOLLOW16"));
setidle(attacker, openborconstant("ANI_IDLE"));
bindentity(victim2, NULL());
performattack(attacker, openborconstant("ANI_PAIN8"));
setentityvar(self, "madjon", NULL());
killentity(self);
} else if(playerkeys(victim, 2, "moveleft") || playerkeys(victim, 2, "moveup") || playerkeys(victim, 2, "movedown") || playerkeys(victim, 2, "moveright") || playerkeys(victim, 2, "attack") || playerkeys(victim, 2, "jump") || playerkeys(victim, 2, "special")){// button is pressed?
changeentityproperty(self, "health", HP+1);
}
}// end checking valid pointers
}
@end_script
Last edited: