It's limited to one enemy at a time and maybye the boss are immune to the mind control?
Yes, I use that type of script on my game. I use a spepecific type of attack (ATTACK8) which triggers PAIN8 animation, where I trigger a function to change all of this:
- candamage
- type
- hostile
- subject to screen
The whole code is this (contains codes that are related to my project):
Code:
void mindControl (int mControl){
//Douglas Baldan / O Ilusionista - 2018.08.21
void self = getlocalvar("self");
int MindControl = getglobalvar("MindControl2");
if (mControl==1){//start mind control
if (getglobalvar("MindControl2")==NULL()) {
changeentityproperty(self, "hostile", "TYPE_ENEMY");
changeentityproperty(self, "type", openborconstant("TYPE_NPC"));
changeentityproperty(self, "candamage", "TYPE_ENEMY");
setglobalvar("MindControl2", 1);
spawner("dizzyfx", 0, 55, 1);
changeentityproperty(self,"subject_to_screen",1);
}
}
if (mControl==0){// finish mind control
changeentityproperty(self, "hostile", "TYPE_PLAYER");
changeentityproperty(self, "type", openborconstant("TYPE_ENEMY"));
changeentityproperty(self, "candamage", "TYPE_PLAYER");
setglobalvar("MindControl2", NULL());
void vSpawn;
vSpawn = spawn01("eaph", 0, 55, 1);
changeentityproperty(self,"subject_to_screen",0);
}
}
I use a custom pain instead of didhit because I can control other things easily, like drawmethod, effects, etc.
Plus, I don't need to add a name check for every enemy on the game - it they have PAIN8, they will trigger it. Robots doesn't have it and this is why you can't mind control them.
It's limited to one character at time to avoid cheapness (this is why I use a global variable, to control it). And bosses are imune because changing them to NPC will end the stage immediately - since either there is no more enemies or the boss having BOSS 1 will trigger this.
Just be warned that this could be a little more complex in some cases - for example, projectiles. Since what they can hit are tied on their headers (and not on the function which calls them), an enemy-now-npc which uses a projectile will still hit you.
On my game, to bypass this, I do the following:
- Detect the entity type on the animation where it will use a projectile. If its NPC, force it to change to another animation
- on the new animation, I use a function that I have where I can spawn projectiles and change what they hit, on the fly.
This is the function I am talking about
Code:
void shooterCD(void Shot, void Can, float dx, float dy, float dz, float Vx, float Vy, float Vz, int Dir)
{ // Shooting projectile with speed control and CanDamage control
// Douglas Baldan - Based on Bloodbane's codes
void self = getlocalvar("self");
int Dire;
int Direction = getentityproperty(self, "direction");
int x = getentityproperty(self, "x");
int y = getentityproperty(self, "a");
int z = getentityproperty(self, "z");
void vShot;
if (Direction == 0){ //Is entity facing left?
dx = -dx; //Reverse X direction to match facing
if (Dir == 1){
Dire = 0;
} else if (Dir == -1){
Dire = 1;
}
} else if (Direction == 1){ //Is entity facing right?
if (Dir == 1){
Dire = 1;
} else if (Dir == -1){
Dire = 0;
}
}
vShot = projectile(Shot, x+dx, z+dz, y+dy, Dire, 0, 0, 0);
changeentityproperty(vShot, "velocity", Vx, Vz, Vy);
changeentityproperty(vShot, "speed", Vx);
changeentityproperty(vShot, "candamage", Can);
}
There are few other things to cover - there was a bug I can't remember very well but consists in some enemies not dying after the boss is dead. This is why when you kill a boss on my game, under the Boss mode, the enemies will just explod.
maxman "I noticed "hostile" exists in the entity properties. But what is it for, anyway? I don't see any info about it." For the same thing HOSTILE works in character header - to define to which type of entity you will be hostile too.
For example, if set HOSTILE ENEMY, the character will only be hostile to nemies, and not to obstacles (but you can still hit them if you set the CANDAMAGE) but...when you run a "findtarget" function, it won't never "see" an obstacle as a valid target.
uTunnels shared an old trick long time ago: this is why you can make moves which grabs (like when Zangief runs and grab) to not target obstacles.