A new template AI,he can Dodging,defense or rebound ball,weapons,defense basic attack.Drink milk or beer when he had very little HP or MP,get far from enemy while they are lying,countermeasure and defense those melee attack,and most important,dash attack and punch.
I'll use this in LF2 Timelapse.
Edit:It's all finish now!He can beat a Fighter!
I'll use this in LF2 Timelapse.
Edit:It's all finish now!He can beat a Fighter!
Code:
//Sauce's Template AI.
void id() {
left(0, 0);
right(0, 0);
up(0, 0);
down(0, 0);
D(0, 0);
J(0, 0);
A(0, 0);
//Defining variables.
array < int > enemies;
array < int > balls;
array < int > drinks;
array < int > weapons;
array < int > flyingweapons;
enemies.resize(0);
balls.resize(0);
drinks.resize(0);
weapons.resize(0);
flyingweapons.resize(0);
bool warning = false;
bool specialmove = false;
int heavy = -1;
int milk = -1;
int beer = -1;
int choice = -1;
int Easy = 2;
int Normal = 1;
int Difficult = 0;
int CRAZY = -1;
float mindashx = 3 * self.data.dash_distance;
float maxdashx = 11 * self.data.dash_distance;
float mindashz = 3 * self.data.dash_distancez;
float maxdashz = 11 * self.data.dash_distancez;
//Stage check.
if (stage_clear) {
right(1, 0);
if (self.state == 2)
J();
}
//Detection.
for (int i = 0; i < 400; i++) {
if (game.exists[i]) {
if (TYPE(i) == 0 && TEAM(i) != self.team && !(ID(i) == 52 && RANGETF(i, 240, 251)) && HP(i) > 0)
enemies.insertLast(i);
else if (TYPE(i) == 3 && TEAM(i) != self.team)
balls.insertLast(i);
else if (TYPE(i) == 6 && STATE(i) == 1004)
drinks.insertLast(i);
else if (STATE(i) != 1002 && STATE(i) != 2000 && TEAM(i) != self.team)
weapons.insertLast(i);
else if (TEAM(i) != self.team)
flyingweapons.insertLast(i);
}
}
//Sort.
if (EXIST(enemies))
enemies.sort(
function (a, b) {
return abs(DX(a)) + abs(DZ(a)) < abs(DX(b)) + abs(DZ(b));
}
);
if (EXIST(balls))
balls.sort(
function (a, b) {
return abs(DX(a)) + abs(DZ(a)) < abs(DX(b)) + abs(DZ(b));
}
);
if (EXIST(drinks))
drinks.sort(
function (a, b) {
return abs(DX(a)) + abs(DZ(a)) < abs(DX(b)) + abs(DZ(b));
}
);
if (EXIST(weapons))
weapons.sort(
function (a, b) {
return abs(DX(a)) + abs(DZ(a)) < abs(DX(b)) + abs(DZ(b));
}
);
if (EXIST(flyingweapons))
flyingweapons.sort(
function (a, b) {
return abs(DX(a)) + abs(DZ(a)) < abs(DX(b)) + abs(DZ(b));
}
);
//Print.
clr();
if (EXIST(enemies))
print("Enemy coming!" + "\n");
if (EXIST(balls))
print("Ball coming!" + "\n");
if (EXIST(drinks))
print("There's a drink!" + "\n");
if (EXIST(weapons))
print("Weapon!" + "\n");
if (EXIST(flyingweapons))
print("Weapon attacking!" + "\n");
print("Distancex:" + DX(enemies[0]) + "\n");
print("Distancez:" + DZ(enemies[0]) + "\n");
//Dodging dash attack.
if (DX(enemies[0]) * VX(enemies[0]) < 0 && ABSRANGE(enemies[0], 180, 30) && (STATE(enemies[0]) == 5 || RANGETF(enemies[0], 90, 94))) {
specialmove = true;
warning = true;
DODGE(enemies[0]);
}
//Dodging,defense or rebound ball.
if (EXIST(balls)) {
if (DX(balls[0]) * VX(balls[0]) < 0 && (STATE(balls[0]) == 3000 || STATE(balls[0]) >= 3005)) {
if (ABSRANGE(balls[0], 180, 30)) {
specialmove = true;
warning = true;
DODGE(balls[0]);
}
if (ABSRANGE(balls[0], 120, 14) || (VZ(balls[0]) != 0 && ABSRANGE(balls[0], 100, 20)))
D();
else if (self.state <= 1 && ABSRANGE(balls[0], 140, 14) && STATE(balls[0]) == 3000)
A();
} else if (ABSRANGE(balls[0], 90, 30) && ID(balls[0]) == 200 && RANGETF(balls[0], 60, 65) && self.facing != FACING(balls[0]) && INFRONT(balls[0])) {
specialmove = true;
warning = true;
if (DX(balls[0]) <= -45)
left(1, 1);
else if (DX(balls[0]) >= 45)
right(1, 1);
if (DZ(balls[0]) >= 14)
up(1, 1);
else if (DZ(balls[0]) <= -14)
down(1, 1);
else if (ABSRANGE(balls[0], 45, 14))
D();
}
}
//Dodging or defense flyingweapon.
if (EXIST(flyingweapons)) {
if (DX(flyingweapons[0]) * VX(flyingweapons[0]) < 0) {
if (ABSRANGE(flyingweapons[0], 180, 30)) {
specialmove = true;
warning = true;
DODGE(flyingweapons[0]);
}
if (ABSRANGE(flyingweapons[0], 100, 14) || (VZ(flyingweapons[0]) != 0 && ABSRANGE(flyingweapons[0], 80, 20)))
D();
}
}
//Jump over obstacles.
if (EXIST(weapons)) {
for (uint i = 0; i < weapons.length(); i++) {
if (TYPE(weapons[i]) == 2 && STATE(weapons[i]) == 2004 && ABSRANGE(weapons[i], 100, 14)) {
heavy = i;
break;
}
}
if (heavy != -1) {
specialmove = true;
if (DX(weapons[heavy]) <= 0)
left(1, 0);
else
right(1, 0);
if (DZ(weapons[heavy]) >= 0)
up(1, 1);
else
down(1, 1);
if (self.state == 2)
J();
}
}
//Drink.
if (EXIST(drinks)) {
for (uint i = 0; i < drinks.length(); i++) {
if (ID(drinks[i]) == 122) {
milk = i;
break;
}
}
for (uint i = 0; i < drinks.length(); i++) {
if (ID(drinks[i]) == 123) {
beer = i;
break;
}
}
if (self.hp <= self.max_hp / 3 && self.weapon_type == 0 && milk != -1)
choice = milk;
else if (self.hp >= self.max_hp / 5 * 4 && self.mp <= 400 && self.weapon_type == 0 && beer != -1)
choice = beer;
if (choice != -1) {
specialmove = true;
if (DX(drinks[choice]) <= -50)
left(1, 0);
else if (DX(drinks[choice]) <= -10)
left(1, 1);
else if (DX(drinks[choice]) >= 50)
right(1, 0);
else if (DX(drinks[choice]) >= 10)
right(1, 1);
if (DZ(drinks[choice]) <= -14)
up(1, 1);
else if (DZ(drinks[choice]) >= 14)
down(1, 1);
if (abs(DX(drinks[choice])) >= 200 && self.state == 2)
J();
else if (ABSRANGE(drinks[choice], 80, 14) && self.state == 2)
D();
if (ABSRANGE(drinks[choice], 10, 14))
A();
}
}
if (self.weapon_type == 6 && self.state <= 2 && !ABSRANGE(enemies[0], 200, 50))
A();
if (RANGESF(55, 58) && ABSRANGE(enemies[0], 200, 50))
D();
//Throwing weapon.
if (self.weapon_type != 0 && self.weapon_type != 6) {
specialmove = true;
if (DX(enemies[0]) <= 0)
left(1, 0);
else
right(1, 0);
if (self.state == 2)
A();
}
//Get far from enemy.
if (STATE(enemies[0]) == 14 || self.weapon_type == 6) {
specialmove = true;
GETFARFROM(enemies[0]);
}
//Walking.
if (specialmove == false) {
if (DX(enemies[0]) <= 0)
left(1, 1);
else
right(1, 1);
if (DZ(enemies[0]) <= 0)
up(1, 1);
else
down(1, 1);
}
//Punch.
if (PUNCHABLE(enemies[0]) && self.fall <= 15 && STATE(enemies[0]) != 14 && STATE(enemies[0]) != 16 && BLINK(enemies[0]) == 0 && self.weapon_type == 0 && !warning) {
if (!INFRONT(enemies[0]) || (self.facing != FACING(enemies[0]) && ABSRANGE(enemies[0], 10, 14)))
TURN();
if (abs(DZ(enemies[0])) <= 20) {
up(0, 0);
down(0, 0);
}
A();
}
//Catch.
if (STATE(enemies[0]) == 16 && ABSRANGE(enemies[0], 130, 30)) {
specialmove = true;
if (DX(enemies[0]) <= -10)
left(1, 1);
else if (DX(enemies[0]) >= 10)
right(1, 1);
else {
if (self.x >= bg_width / 2)
left(1, 1);
else
right(1, 1);
}
if (DZ(enemies[0]) <= -14)
up(1, 1);
else if (DZ(enemies[0]) >= 14)
down(1, 1);
}
//Catching.
if (EXIST(enemies) && RANGESF(121, 121)) {
if (self.ctimer >= 60) {
left(0, 0);
right(0, 0);
}
A(1, 0);
}
//Defense.
if (GOINGTOBEHITED(enemies[0])) {
specialmove = true;
warning = true;
if (!INFRONT(enemies[0]) || (INFRONT(enemies[0]) && (self.facing == FACING(enemies[0]))))
TURN();
D();
}
//Dash attack.
if (difficulty <= Difficult && abs(DX(enemies[0])) >= mindashx && abs(DX(enemies[0])) <= maxdashx && ((abs(DZ(enemies[0])) >= mindashz && abs(DZ(enemies[0])) <= maxdashz) || abs(DZ(enemies[0])) <= 14) && ((DZ(enemies[0]) == 0 || abs(DX(enemies[0])) / abs(DZ(enemies[0])) >= mindashx / mindashz) || abs(DZ(enemies[0])) <= 14) && BLINK(enemies[0]) == 0 && STATE(enemies[0]) != 14 && self.weapon_type == 0 && !warning) {
specialmove = true;
DASH(enemies[0]);
}
if (self.state == 5 && ABSRANGE(enemies[0], 150, 30) && INFRONT(enemies[0]))
A();
//Countermeasure.
if (ID(enemies[0]) == 1) //Enemy is Deep.
{
if (self.state == 12 && (RANGETF(enemies[0], 266, 270) || RANGETF(enemies[0], 295, 295) || RANGETF(enemies[0], 304, 304)))
J();
}
if (ID(enemies[0]) == 2) //Enemy is John.
{
if (self.state == 12 && ((RANGETF(enemies[0], 237, 239) || (RANGETF(enemies[0], 292, 293)))))
J();
}
if (ID(enemies[0]) == 4) //Enemy is Henry.
{
if (self.state == 12 && RANGETF(enemies[0], 237, 239))
J();
if (RANGETF(enemies[0], 250, 255) && ABSRANGE(enemies[0], 200, 80)) {
specialmove = true;
left(0, 0);
right(0, 0);
up(0, 0);
down(0, 0);
}
}
if (ID(enemies[0]) == 5) //Enemy is Rudolf.
{
if (self.state == 12 && (RANGETF(enemies[0], 76, 79) || RANGETF(enemies[0], 86, 89)))
J();
}
if (ID(enemies[0]) == 6) //Enemy is Louis.
{
}
if (ID(enemies[0]) == 7) //Enemy is Firen.
{
if (RANGETF(enemies[0], 72, 75) && ABSRANGE(enemies[0], 60, 14))
D(0, 0);
if (RANGETF(enemies[0], 285, 289) && ABSRANGE(enemies[0], 60, 50))
D();
}
if (ID(enemies[0]) == 8) //Enemy is Freeze.
{
if (self.state == 2 && (RANGETF(enemies[0], 250, 252) || RANGETF(enemies[0], 260, 268)) && ABSRANGE(enemies[0], 200, 40) && INFRONT(enemies[0])) {
J();
A();
}
}
if (ID(enemies[0]) == 9) //Enemy is Dennis.
{
}
if (ID(enemies[0]) == 10) //Enemy is Woody.
{
if (self.state == 12 && (RANGETF(enemies[0], 70, 72) || RANGETF(enemies[0], 90, 91) || RANGETF(enemies[0], 250, 254)))
J();
}
if (ID(enemies[0]) == 11) //Enemy is Davis.
{
if (RANGETF(enemies[0], 274, 274))
A();
if (RANGETF(enemies[0], 73, 74) || RANGETF(enemies[0], 290, 293) || RANGETF(enemies[0], 300, 303)) {
if (self.state == 12 && ABSRANGE(enemies[0], 70, 14))
J();
}
}
if (ID(enemies[0]) == 38) //Enemy is Bat.
{
}
if (ID(enemies[0]) == 50) //Enemy is LouisEX.
{
if (self.state == 12 && (RANGETF(enemies[0], 243, 245) || RANGETF(enemies[0], 250, 253)))
J();
}
if (ID(enemies[0]) == 51) //Enemy is Firzen.
{
if (RANGETF(enemies[0], 255, 257)) {
specialmove = true;
left(0, 0);
right(0, 0);
up(0, 0);
down(0, 0);
GETFARFROM(enemies[0]);
}
}
if (ID(enemies[0]) == 52) //Enemy is Julian.
{
if (RANGETF(enemies[0], 255, 257)) {
specialmove = true;
left(0, 0);
right(0, 0);
up(0, 0);
down(0, 0);
GETFARFROM(enemies[0]);
}
}
}
//Defining functions.
float DX(int i) {
return game.objects[i].x - self.x;
}
float DY(int i) {
return game.objects[i].y - self.y;
}
float DZ(int i) {
return game.objects[i].z - self.z;
}
float VX(int i) {
return game.objects[i].x_velocity;
}
float VY(int i) {
return game.objects[i].y_velocity;
}
float VZ(int i) {
return game.objects[i].z_velocity;
}
float ID(int i) {
return game.objects[i].data.id;
}
float TYPE(int i) {
return game.objects[i].data.type;
}
float FRAME(int i) {
return game.objects[i].frame1;
}
float STATE(int i) {
return game.objects[i].data.frames[game.objects[i].frame1].state;
}
float TEAM(int i) {
return game.objects[i].team;
}
float FALL(int i) {
return game.objects[i].fall;
}
float BDEFEND(int i) {
return game.objects[i].bdefend;
}
float AREST(int i) {
return game.objects[i].arest;
}
float VREST(int i) {
return game.objects[i].vrest;
}
float BLINK(int i) {
return game.objects[i].blink;
}
float HP(int i) {
return game.objects[i].hp;
}
bool EXIST(int[] a) {
return (a.length() != 0);
}
bool RANGEX(int i, int a, int b) {
return game.objects[i].x - self.x >= a && game.objects[i].x - self.x <= b;
}
bool RANGEY(int i, int a, int b) {
return game.objects[i].y - self.y >= a && game.objects[i].y - self.y <= b;
}
bool RANGEZ(int i, int a, int b) {
return game.objects[i].z - self.z >= a && game.objects[i].z - self.z <= b;
}
bool RANGESF(int a, int b) {
return self.frame >= a && self.frame <= b;
}
bool RANGETF(int i, int a, int b) {
return game.objects[i].frame1 >= a && game.objects[i].frame1 <= b;
}
bool ABSRANGE(int i, int a, int b) {
return abs(game.objects[i].x - self.x) <= a && abs(game.objects[i].z - self.z) <= b;
}
bool INFRONT(int i) {
return (game.objects[i].x - self.x) * (self.facing ? -1 : 1) > 0;
}
bool FACING(int i) {
return game.objects[i].facing;
}
bool PUNCHABLE(int i) {
const ObjectArray @obj = game.objects;
const FrameArray @obj_f = obj[i].data.frames;
const FrameArray @obj_sf = obj[self.num].data.frames;
const ItrArray @obj_sitr = obj_sf[61].itrs;
const BdyArray @obj_bdy = obj_f[obj[i].frame1].bdys;
if (obj_f[obj[i].frame1].bdy_count > 0) {
float itrx = obj_sitr[0].x - obj_sf[61].centerx + obj_sitr[0].w;
float bdyx1 = abs(obj_bdy[0].x - obj_f[obj[i].frame1].centerx);
float bdyx2 = abs(obj_bdy[0].x - obj_f[obj[i].frame1].centerx + obj_bdy[0].x);
if ((abs(DX(i)) <= itrx + bdyx1 || abs(DX(i)) <= itrx + bdyx2) && abs(DZ(i)) <= 25)
return true;
}
return false;
}
bool GOINGTOBEHITED(int i) {
const ObjectArray @obj = game.objects;
const FrameArray @obj_f = obj[i].data.frames;
const FrameArray @obj_sf = obj[self.num].data.frames;
const ItrArray @obj_itr = obj_f[obj[i].frame1].itrs;
const BdyArray @obj_sbdy = obj_sf[obj[self.num].frame1].bdys;
if (obj_f[obj[i].frame1].itr_count > 0 && obj_itr[0].kind == 0 && obj_sf[self.frame].bdy_count > 0) {
int itrx1 = game.objects[i].x + (obj_itr[0].x - obj_f[obj[i].frame1].centerx) * (FACING(i) ? -1 : 1);
int itrx2 = game.objects[i].x + (obj_itr[0].x - obj_f[obj[i].frame1].centerx + obj_itr[0].w) * (FACING(i) ? -1 : 1);
int bdyx1 = self.x + (obj_sbdy[0].x - obj_sf[self.frame].centerx) * (self.facing ? -1 : 1);
int bdyx2 = self.x + (obj_sbdy[0].x - obj_sf[self.frame].centerx + obj_sbdy[0].w) * (self.facing ? -1 : 1);
int itry1 = game.objects[i].y - obj_f[obj[i].frame1].centery + obj_itr[0].y;
int itry2 = game.objects[i].y - obj_f[obj[i].frame1].centery + obj_itr[0].y + obj_itr[0].h;
int bdyy1 = self.y - obj_sf[self.frame].centery + obj_sbdy[0].y;
int bdyy2 = self.y - obj_sf[self.frame].centery + obj_sbdy[0].y + obj_sbdy[0].h;
if (((itrx2 >= bdyx1 && itrx1 <= bdyx2) ||
(itrx2 <= bdyx1 && itrx1 >= bdyx2) ||
(itrx2 >= bdyx2 && itrx1 <= bdyx1) ||
(itrx2 <= bdyx2 && itrx1 >= bdyx1)) &&
(itry2 >= bdyy1 && itry1 <= bdyy2) &&
abs(DZ(i)) <= 14)
return true;
}
if (DX(i) * VX(i) < 0 && (VX(i) == 0 || abs(DX(i)) <= abs(VX(i)) * 7) && (VZ(i) == 0 || abs(DZ(i)) <= abs(VZ(i)) * 7) && abs(DZ(i)) <= 20)
return true;
return false;
}
void TURN() {
if (!self.facing)
left(1, 0);
else
right(1, 0);
}
void DODGE(int i) {
if (!INFRONT(i))
TURN();
if (self.z == bg_zwidth2)
up(1, 1);
else if (self.z == bg_zwidth1)
down(1, 1);
else if (VZ(i) >= 0)
up(1, 1);
else
down(1, 1);
if (self.state == 2)
D();
}
void GETFARFROM(int i) {
if (ABSRANGE(i, 200, 50)) {
if (DX(i) >= 0)
left(1, 0);
else
right(1, 0);
if (DZ(i) >= 0)
up(1, 1);
else
down(1, 1);
if (self.state == 2)
J();
}
}
void DASH(int i) {
if (DX(i) <= 0)
left(1, 0);
else
right(1, 0);
if (DZ(i) <= -14)
up(1, 1);
else if (DZ(i) >= 14)
down(1, 1);
else {
up(0, 0);
down(0, 0);
}
if (self.state == 2 || self.frame == 215)
J();
}
Sauce,No.1 player in China.
I don't need any fame,because I know who I am.
project:
lf2-AI Mod By Sauce
lf2-AI Mod By Sauce