Here is the code. This is all the code that does everything. There is no extra code, except the code that initiates this(it just calls the pathfind_graph_connections function), which is called 4 frames after the level is loaded. There is a 13 wait time between when you click on the level you want, and the game starting. When you first click on what you want, the level loads, does the pathfind setup, and then however much time is left just runs. The panel that covers the screen clears, and the zombies start spawning.
Please excuse all the misteaks and errors, I'm really just trying to save myself time by commenting out stuff, instead of deleting it. There are loads of lines here that actually have been commented out because they were replaced by better, faster code, and were never deleted. (RegisterMe(), for example, was from a previous attempt at pathfinding.)
Oh, and parenthandle has already been defined as skill47 or something.
Code:
//DEFINES
define pathfind_max_nodes, 250;
define connections, skill99;
define IDno, skill97;
define pathfind_set, skill96;
define generation, skill95;
define spawn_wait_time, skill94;
define pathfind_stair, skill93;
define pathfind_zomb_pan, skill92;
define pathfind_in_my_way, flag8;
define notclose, flag7;
//Global Variables
var pathfind_node_array[pathfind_max_nodes];
var pathfind_PoV_chart[62500];
//var pathfind_path_chart[62500];//max nodes * max nodes
//var pathfind_magnitude_chart[pathfind_max_nodes];
var pathfind_next_node = -1;
var pathfind_node_number = 0;
var pathfind_ready_nodes = 0;
//entity* pathfind_counter_ent;
//entity* pathfind_counter2_ent;
var pathfind_graph_set; //true or false, tells weather the graph has been set or not
//--------------------------------NODE BASED FUNCTIONS---------------------------------
function pathfind_register_node(handleID){
pathfind_next_node += 1;
pathfind_node_number += 1;
pathfind_node_array[pathfind_next_node] = handleID;
return(pathfind_next_node);
}
function pathfind_regulate_paths(){
wait(1);
}
function pathfind_graph_connections(){
//var current_node = 0;
//var counter = 0;
//var counter2 = 0;
//var traceresult = 0;
while(pathfind_ready_nodes < pathfind_node_number){
wait(1);
}
temp.x = 0;
temp.y = 0;
while(temp.x < pathfind_node_number){
me = ptr_for_handle(pathfind_node_array[temp.x]);
while(temp.y < pathfind_node_number){
if(temp.x != temp.y){
you = ptr_for_handle(pathfind_node_array[temp.y]);
temp.z = c_trace(my.x, you.x, IGNORE_ME | IGNORE_YOU | IGNORE_MODELS);
you = ptr_for_handle(pathfind_node_array[temp.y]);
if(temp.z == 0){
you.connections += 1;
pathfind_PoV_chart[temp.x*pathfind_max_nodes+temp.y] = 1;
//if(my.z != you.z){
// my.pathfind_stair = 0;
//}
//else{
// my.pathfind_stair = -5;
//}
}
else{
pathfind_PoV_chart[temp.x*pathfind_max_nodes+temp.y] = 0;
}
}
temp.y += 1;
wait(1);
//beep();
if(you == null){
break;
}
}
temp.x += 1;
temp.y = 0;
wait(1);
if(me == null){
break;
}
}
pathfind_graph_set = true;
}
//--------------------------------ZOMBIE PATHFIND CODE
function pathfind_zombie_act_event(){
if(event_type == event_scan){
if(you.what_i_am == profgrenade){
my.health = 0;
}
}
if(event_type == event_entity){
if(my.pathfind_in_my_way == off){
//my.force_y = (random(2)-1)*1.5;
//my.pan += random(30)-15;
//my.generation = handle(you);
//my.pan = my.pathfind_zomb_pan;
//my.pathfind_in_my_way = on;
wait(1);
}
if(you.what_i_am == profzombie){
you.attacked = on;
}
}
}
action pathfind_zombie_act
{
var oldvec[3];
my.enable_scan = on;
//my.enable_entity = on;
my.event = pathfind_zombie_act_event;
//RegisterMe();
//you = player;
my.pathfind_in_my_way = off;
my.push = 3;
my.health = max_health;
my.what_i_am = profzombie;
//my.enable_shoot = on;
my.enable_impact = on;
my.alpha = 100;
my.enable_entity = on;
//my.event = zombie_shot;
you = ent_create(zombieleft, my.x, zombie_left);
my.partlarm = handle(you);
you = ent_create(zombieright, my.x, zombie_right);
my.partrarm = handle(you);
you = ent_create(zombiehead, my.x, zombie_head);
my.parthead = handle(you);
random_ehh();
while(my.health > 0){
you = ptr_for_handle(my.partlarm);
if(you != null){
if(you.health > 0){
you.pan = my.pan;
you.tilt = my.tilt;
vec_set(you.x, my.x);
}
}
else{
my.health -= 1;
vec_for_vertex(temp, me, 310);
effect(FXGore01_BloodSpray,1,temp,vector(1,0,0));
}
you = ptr_for_handle(my.partrarm);
if(you != null){
if(you.health > 0){
you.pan = my.pan;
you.tilt = my.tilt;
vec_set(you.x, my.x);
}
}
else{
my.health -= 1;
vec_for_vertex(temp, me, 309);
effect(FXGore01_BloodSpray,1,temp,vector(-1,0,0));
}
if(esc_menu_up == false){
if(my.attacked == on){
my.health -= 10;
if(my.control == on){
effect(FXGore01_BloodSpray,1,vector(my.x, my.y, my.z + 25),vector(0,0,2));
}
my.control = (my.control == off);
}
you = ptr_for_handle(my.parthead);
if(you != null){
if(you.health > 0){
you.pan = my.pan;
//vec_set(temp,player.x);
//vec_sub(temp,you.x);
//vec_to_angle(you.pan,temp);
you.tilt = my.tilt;
vec_set(you.x, my.x);
}
}
else{
my.health -= 1;
vec_for_vertex(temp, me, 311);
effect(FXGore01_BloodSpray,1,temp,vector(0,0,2));
}
//START PATHFINDING CODE
//you = ptr_for_handle(my.parenthandle);
//if(you != null){
// if(you.generation < 3){ //this is for the scanning for the player
you = player;
temp.x = c_trace(vector(my.x, my.y, my.z-40), player.x, IGNORE_PASSENTS | IGNORE_PUSH | IGNORE_SPRITES | IGNORE_ME | IGNORE_YOU);
// }
// this is for testing weather you can see the node or not...
//temp.x = c_trace(vector(my.x, my.y, my.z - 40), you.x, IGNORE_PUSH | IGNORE_SPRITES | IGNORE_PASSENTS);
//}
you = ptr_for_handle(my.parenthandle);
if(temp.x == 0){
you = player;
player.shot = true;
}
if(you != null){
/*
if(you.what_i_am == profzombie){
my.pathfind_in_my_way = on;
my.pan += (random(30)-15)*2;
my.generation = handle(you);
}
temp.y = handle(you);
if(handle(my.parenthandle) == temp.y){
my.pathfind_in_my_way == off;
}
*/
//you = ptr_for_handle(my.parenthandle);
//if(my.pathfind_in_my_way == off){
vec_set(temp,you.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp);
my.tilt = 0;
//}
if(vec_dist(my.x, you.x) < 20){
my.parenthandle = you.parenthandle;
}
}
//END PATHFINDING CODE
//my.pan = my.pathfind_zomb_pan;
temp.x=0;temp.y=0;temp.z=0;
//you = ptr_for_handle(my.parenthandle);
//if(you != null){
/*
you = ptr_for_handle(my.generation);
if(you != null){
if(vec_dist(you.x, my.x) > 20){
my.force_y = 0;
my.pathfind_in_my_way = off;
}
}
*/
if(c_move(me, vector(1,0,0), vector(0,0,-.1), GLIDE | IGNORE_ME | IGNORE_PUSH) > 0){
ent_animate(me, "creep", my.animationpercent, anm_cycle);
my.animationpercent += 1;
you = ptr_for_handle(my.parthead);
if(you!=null){
you.attacking = false;
}
you = ptr_for_handle(my.partlarm);
if(you!=null){
you.attacking = false;
}
you = ptr_for_handle(my.partrarm);
if(you!=null){
you.attacking = false;
}
}
else{
ent_animate(me, "attack", my.animationpercent, anm_cycle);
my.animationpercent += 1;
you = ptr_for_handle(my.parthead);
if(you!=null){
you.attacking = true;
}
you = ptr_for_handle(my.partlarm);
if(you!=null){
you.attacking = true;
}
you = ptr_for_handle(my.partrarm);
if(you!=null){
you.attacking = true;
}
}
//}
}
you = null;
wait(1);
}
you = ptr_for_handle(my.parthead);
if(you != null){
you.attacked = (my.attacked == on);
you.health = 0;
}
you = ptr_for_handle(my.partlarm);
if(you != null){
you.attacked = (my.attacked == on);
you.health = 0;
}
you = ptr_for_handle(my.partrarm);
if(you != null){
you.attacked = (my.attacked == on);
you.health = 0;
}
zombie_numb -= 1;
my.event = null;
my.animationpercent = 0;
kills += 1;
ent_playsound(me, zombiedie, 200);
if(my.attacked == off){
while(my.animationpercent < 100){
if(esc_menu_up == false){
ent_animate(me, "dieA", my.animationpercent, null);
my.animationpercent += 1;
if(my.animationpercent == 50){
c_updatehull(me, my.animationpercent);
}
if(my.animationpercent == 90){
c_updatehull(me, my.animationpercent);
}
}
wait(1);
}
}
else{
while(my.animationpercent < 100){
if(esc_menu_up == false){
ent_animate(me, "dieB", my.animationpercent, null);
my.animationpercent += 1;
if(my.animationpercent == 60){
c_updatehull(me, my.animationpercent);
}
}
wait(1);
}
}
my.transparent = on;
my.passable = on;
while(my.alpha > 0){
my.alpha -= 1;
wait(1);
}
ent_remove(me);
}
//--------------------------------ALL IMPORTANT NODE ACTION----------------------------
action pathfind_node{
my.IDno = pathfind_register_node(handle(me));
my.transparent = on;
my.alpha = 50;
my.pathfind_set = false;
my.push = 4;
my.connections = 0;
my.spawn_wait_time = 0;
while(c_move(me, nullvector, vector(0,0,-2), null) > 0){
wait(1);
}
pathfind_ready_nodes += 1;
my.passable = on;
while(pathfind_graph_set == false){
wait(1);
}
while(player == null){
wait(1);
}
my.generation = 3;//5;
while(1){
temp.x = 0;
//my.alpha = 25;
temp.y = 1;
if(my.generation < 4){
temp.y = c_trace(my.x, vector(player.x, player.y, player.z - 0), IGNORE_SPRITES | IGNORE_MODELS);//IGNORE_PUSH | IGNORE_PASSENTS | IGNORE_ME);//ignore models
}
if((temp.y == 0) &&(my.pathfind_set == false)){
my.generation = 1;
my.parenthandle = handle(player);
//my.pathfind_set = true;
temp.x = 0;
while(temp.x < pathfind_node_number){
if(temp.x != my.IDno){
if(pathfind_PoV_chart[my.IDno*pathfind_max_nodes+temp.x] == 1){
temp.z = pathfind_node_array[temp.x];
you = ptr_for_handle(temp.z);
//if(you.generation == 1){
// my.animation = vec_dist(you.x, player.x);
// if(vec_dist(my.x, player.x) >= my.animation){
// my.notclose = false;
// you.notclose = true;
// you.generation = 2;
// }
//}
if((you.generation > 1) && (you.pathfind_set == false)){
you.parenthandle = handle(me);
//my.alpha = 100;
you.alpha = 100;
you.generation = 2;//my.generation + 1;
you.pathfind_set = true;
you.notclose = false;
}
}
}
temp.x += 1;
}
my.pathfind_set = false;
//my.alpha = 25;
}
temp.x = 0;
else{
if((my.pathfind_set == true) && (my.generation <= 5)){
my.notclose = false;
while(temp.x < pathfind_node_number){
you = ptr_for_handle(my.parenthandle);
if((temp.x != my.IDno) && (temp.x != you.IDno)){
if(pathfind_PoV_chart[my.IDno*pathfind_max_nodes+temp.x] == 1){
temp.z = pathfind_node_array[temp.x];
you = ptr_for_handle(temp.z);
if((you.generation > my.generation) && (you.pathfind_set != true)){
you.parenthandle = handle(me);
you.generation = my.generation + 1;
you.pathfind_set = true;
you.alpha = 100;
}
}
}
temp.x += 1;
}
if((my.generation > 1) && (my.generation <= 5) && (my.spawn_wait_time <= 0) && (zombie_numb < 20)){
you = ent_create(zombie_mdl, my.x, pathfind_zombie_act);
wait(1);
you.parenthandle = my.parenthandle;
my.spawn_wait_time = random(100)+100;
zombie_numb += 1;
}
else{
my.spawn_wait_time -= 1;
}
my.pathfind_set = false;
//my.alpha = 25;
}
}
if(my.generation >= 4){
my.alpha = 0;
}
wait(1);
my.health = 1;
}
}