UGX-Mods

Call of Duty 5: World at War => Help Desk => Scripting => Topic started by: NaviLlicious on May 25, 2014, 10:50:00 pm

Title: Make zombies respawn when player walks to far away?
Post by: NaviLlicious on May 25, 2014, 10:50:00 pm
Was wondering how I would make the zombies respawn when a player walks to far away from the zombies like on Mob of the Dead, I have an elevator and a teleporter setup but when the player uses one of them It puts them In an area the zombies can't get to unless they respawn
Title: Re: Make zombies respawn when player walks to far away?
Post by: daedra descent on May 25, 2014, 10:53:28 pm
Get the axis(zombie) array and do the function dodamage(); on them.
Title: Re: Make zombies respawn when player walks to far away?
Post by: NaviLlicious on May 25, 2014, 11:04:58 pm
Get the axis(zombie) array and do the function dodamage(); on them.
Which .gsc would axis(zombie) be under?
Title: Re: Make zombies respawn when player walks to far away?
Post by: daedra descent on May 25, 2014, 11:41:28 pm
It wasn't a function. I was specifying that an zombies are on the team "axis".

http://www.zeroy.com/script/ (http://www.zeroy.com/script/)

This has most engine defined functions including dodamage();. hold ctrl + f and search for "dodamage". It'll tell you how to properly use the function.
Title: Re: Make zombies respawn when player walks to far away?
Post by: NaviLlicious on May 25, 2014, 11:52:24 pm
So how would I apply that to the zombies and how would I edit how far the player can go before the zombie starts taking damage?
Title: Re: Make zombies respawn when player walks to far away?
Post by: GrantDaddy007 on May 26, 2014, 12:03:47 am
Was wondering how I would make the zombies respawn when a player walks to far away from the zombies like on Mob of the Dead, I have an elevator and a teleporter setup but when the player uses one of them It puts them In an area the zombies can't get to unless they respawn

The way I went about this with zombie train is:
Code Snippet
Plaintext
zombies = getaispeciesarray("axis");

for (i = 0; i < zombies.size; i++)
{


zombies[i] dodamage( zombies[i].health + 666, zombies[i].origin );
playsoundatposition( "nuked", zombies[i].origin );
}

What this does is kill of any remaining zombies.  I used a trigger mult...  It will end the round and start the next one.

Hope this helps!  :P
Title: Re: Make zombies respawn when player walks to far away?
Post by: NaviLlicious on May 26, 2014, 03:56:28 am
The way I went about this with zombie train is:
Code Snippet
Plaintext
zombies = getaispeciesarray("axis");

for (i = 0; i < zombies.size; i++)
{


zombies[i] dodamage( zombies[i].health + 666, zombies[i].origin );
playsoundatposition( "nuked", zombies[i].origin );
}

What this does is kill of any remaining zombies.  I used a trigger mult...  It will end the round and start the next one.

Hope this helps!  :P
Thanks, you said you used a trigger mult for It? I tried putting a trig multiple In and It keeps the zombies from spawning until It's activated this Is how I put It In
Code Snippet
Plaintext
{
trigger = getent ( "axisdamage", "targetname" );
zombies = getaispeciesarray("axis");
   trigger waittill ("trigger");
for (i = 0; i < zombies.size; i++)
{


zombies[i] dodamage( zombies[i].health + 666, zombies[i].origin );
playsoundatposition( "nuked", zombies[i].origin );
}
}
Title: Re: Make zombies respawn when player walks to far away?
Post by: DuaLVII on May 26, 2014, 07:58:11 am
Untested Template

Code Snippet
Plaintext
run_zombie_check()
{
zombies = getaiarray("axis");
array_thread(zombies,::dist_check);
}

dist_check()
{
max_dist_for_respawn = 2000;
too_far_away = false;
all_players = GetPlayers();
while(1)
{
for(i = 0; i < all_players.size; i++)
{
zombie_distance = Distance(all_players[i].origin, self.origin);
if( zombie_distance >= max_dist_for_respawn)
{
too_far_away = true;
}
else
{
too_far_away = false;
break;
}
}
if(too_far_away == true)
{
self dodamage((self.health * 100), self.origin);
//level.zombie_total++; //May not work when the round_spawning function in zombiemode.gsc has finished it's while flow
//Could try making a seperate spawn script to spawn a zombie before killing this one which would keep the wave alive.
}
wait(1);
}
}
Title: Re: Make zombies respawn when player walks to far away?
Post by: NaviLlicious on May 27, 2014, 10:08:46 pm
Untested Template

Code Snippet
Plaintext
run_zombie_check()
{
zombies = getaiarray("axis");
array_thread(zombies,::dist_check);
}

dist_check()
{
max_dist_for_respawn = 2000;
too_far_away = false;
all_players = GetPlayers();
while(1)
{
for(i = 0; i < all_players.size; i++)
{
zombie_distance = Distance(all_players[i].origin, self.origin);
if( zombie_distance >= max_dist_for_respawn)
{
too_far_away = true;
}
else
{
too_far_away = false;
break;
}
}
if(too_far_away == true)
{
self dodamage((self.health * 100), self.origin);
//level.zombie_total++; //May not work when the round_spawning function in zombiemode.gsc has finished it's while flow
//Could try making a seperate spawn script to spawn a zombie before killing this one which would keep the wave alive.
}
wait(1);
}
}
Sorry for the late reply, tried this script but when I get really far from the zombies they don't die/respawn
Title: Re: Make zombies respawn when player walks to far away?
Post by: DuaLVII on May 27, 2014, 10:32:33 pm
Did you create a new gsc for this and execute it correctly (may need to adjust max distance variable a little lower)
Title: Re: Make zombies respawn when player walks to far away?
Post by: jjbradman on May 27, 2014, 10:34:07 pm
because it gets an array of the zombies of zombies once. that means i gets a list of 1 zombies at game start. then a new zombie spawn outside that array. so code wont affect it

Post Merge: May 27, 2014, 10:36:35 pm
this will work using your code but i would do this stuff using zombiemodespawner. no need of getting arrays.
Code Snippet
Plaintext
run_zombie_check()
{
while(1)
{
zombies = getaiarray("axis");
array_thread(zombies,::dist_check);
wait 10;
}
}
Title: Re: Make zombies respawn when player walks to far away?
Post by: NaviLlicious on May 27, 2014, 10:36:48 pm
Did you create a new gsc for this and execute it correctly (may need to adjust max distance variable a little lower)
Yeah I made a new .gsc for It I will try to make the distance smaller

Post Merge: May 27, 2014, 10:37:29 pm
because it gets an array of the zombies of zombies once. that means i gets a list of 1 zombies at game start. then a new zombie spawn outside that array. so code wont affect it

Post Merge: May 27, 2014, 10:36:35 pm
this will work using your code but i would do this stuff using zombiemodespawner. no need of getting arrays.
Code Snippet
Plaintext
run_zombie_check()
{
while(1)
{
zombies = getaiarray("axis");
array_thread(zombies,::dist_check);
wait 10;
}
}
I will also try this thanks guys
Title: Re: Make zombies respawn when player walks to far away?
Post by: DuaLVII on May 27, 2014, 10:39:11 pm
Thats the thing you'd run zombie_check through a loop.

However I came up with a better idea which envoles the second function but as a defined function to an ai through round spawning in zombiemode gsc.

The previous script was just a quick knock up untested idea.



I'll post my new idea up in script form tomorrow. bit late for me right now, so I'll edit this part out.
Title: Re: Make zombies respawn when player walks to far away?
Post by: NaviLlicious on May 27, 2014, 10:46:01 pm
Thats the thing you'd run zombie_check through a loop.

However I came up with a better idea which envoles the second function but as a defined function to an ai through round spawning in zombiemode gsc.

The previous script was just a quick knock up untested idea.



I'll post my new idea up in script form tomorrow. bit late for me right now, so I'll edit this part out.
Alright I appreciate the help guys thanks a bunch
Title: Re: Make zombies respawn when player walks to far away?
Post by: jjbradman on May 27, 2014, 10:50:32 pm
search self thread zombie_damage_failsafe(); in zombiemodespawner and add
Code Snippet
Plaintext
self thread check_distance();

then add this to the bottom of the file
Code Snippet
Plaintext
check_distance()
{
while(1)
{
all_players = GetPlayers();
for(i = 0; i < all_players.size; i++)
{
zombie_distance = Distance(all_players[i].origin, self.origin);
if( zombie_distance >= level.max_dist_for_respawn)
{
self.too_far_away = true;
}
else
{
self.too_far_away = false;
break;
}
}

if(self.too_far_away == true)
{

zombie = spawn_zombie( spawner );//here you need get your spawners somehow and check distance to select one close to the player
//HEY HERE!!!!
zombie.team = "axis";
zombie thread dozombiestuff();

self dodamage((self.health * 100), self.origin);
//level.zombie_total++; //May not work when the round_spawning function in zombiemode.gsc has finished it's while flow
//Could try making a seperate spawn script to spawn a zombie before killing this one which would keep the wave alive.
}

wait 1;
}
}
and add this
Code Snippet
Plaintext
	level.max_dist_for_respawn = 2000;


under this
Code Snippet
Plaintext
init()
{

edit: add this at the bottom of the file also
Code Snippet
Plaintext
dozombiestuff()
{
self thread zombie_spawn_init("zombie");
self thread zombie_think();
self thread zombie_setup_attack_properties();
//self thread find_flesh(); i dont rememebr if you need this one
}
Title: Re: Make zombies respawn when player walks to far away?
Post by: NaviLlicious on May 27, 2014, 11:12:31 pm
search self thread zombie_damage_failsafe(); in zombiemodespawner and add
Code Snippet
Plaintext
self thread check_distance();

then add this to the bottom of the file
Code Snippet
Plaintext
check_distance()
{
while(1)
{
all_players = GetPlayers();
for(i = 0; i < all_players.size; i++)
{
zombie_distance = Distance(all_players[i].origin, self.origin);
if( zombie_distance >= level.max_dist_for_respawn)
{
self.too_far_away = true;
}
else
{
self.too_far_away = false;
break;
}
}

if(self.too_far_away == true)
{
self dodamage((self.health * 100), self.origin);
//level.zombie_total++; //May not work when the round_spawning function in zombiemode.gsc has finished it's while flow
//Could try making a seperate spawn script to spawn a zombie before killing this one which would keep the wave alive.
}

wait 1;
}
}
and add this
Code Snippet
Plaintext
	level.max_dist_for_respawn = 2000;

under this
Code Snippet
Plaintext
init()
{
just need to spawn the other zombie closer to the player good luck dual :P
This does kill the zombies when you get far enough away but doesn't spawn the zombies In the current zone the player Is In
Title: Re: Make zombies respawn when player walks to far away?
Post by: jjbradman on May 27, 2014, 11:18:33 pm
ye i mentioned that that still needs to be done :P i might have time to add it in a few hours
Title: Re: Make zombies respawn when player walks to far away?
Post by: NaviLlicious on May 27, 2014, 11:19:18 pm
ye i mentioned that that still needs to be done :P i might have time to add it in a few hours
Oh xD sorry didn't see that alright man like I said I appreciate It and no rush
Title: Re: Make zombies respawn when player walks to far away?
Post by: jjbradman on May 28, 2014, 03:42:01 am
ok i modified my topic whi the code. it just needs to get your spawner to trigger the closer one to the player
Title: Re: Make zombies respawn when player walks to far away?
Post by: NaviLlicious on May 28, 2014, 03:58:40 am
ok i modified my topic whi the code. it just needs to get your spawner to trigger the closer one to the player
The zombies die and the round doesn't end but the zombies also don't respawn even when standing In a zone how would I make the spawners trigger when a player gets close to them?
Title: Re: Make zombies respawn when player walks to far away?
Post by: jjbradman on May 28, 2014, 05:27:03 am
if you look in the script theres a part in which i mentioned you somehow have to acquiare the spawners and then check distance :l emm can you show me your spawners kvps?

Post Merge: May 28, 2014, 05:44:25 am
lol i should make a tut on how to do this after it gets finished xD
Title: Re: Make zombies respawn when player walks to far away?
Post by: NaviLlicious on May 28, 2014, 09:46:03 am
The KVP's are the normal zombie KVP's here are the targetnames for them "targetname" "initial_zone_spawner" "targetname" "zone1_spawner" "targetname" "zone2_spawner" the number goes up from there
Title: Re: Make zombies respawn when player walks to far away?
Post by: DuaLVII on May 28, 2014, 09:57:01 am
Here's my progress on my version of the respawn which I've coded into the round_spawning under zombiemode think with additional functions to making this work.

For testing I set the distance to 1000 and so far there seems to be no glitches in the process however I did this without playable_area also so I need to also make sure zombie deaths by distance don't spawn powerups.

DuaLVII - Respawn Test (http://www.youtube.com/watch?v=-kUr55eIT_s#ws)



Edit: This will run with zones so they will respawn to a zone a player is in, I'm just using one zone on this at the moment.
Title: Re: Make zombies respawn when player walks to far away?
Post by: NaviLlicious on May 28, 2014, 10:54:52 am
Here's my progress on my version of the respawn which I've coded into the round_spawning under zombiemode think with additional functions to making this work.

For testing I set the distance to 1000 and so far there seems to be no glitches in the process however I did this without playable_area also so I need to also make sure zombie deaths by distance don't spawn powerups.

DuaLVII - Respawn Test (http://www.youtube.com/watch?v=-kUr55eIT_s#ws)



Edit: This will run with zones so they will respawn to a zone a player is in, I'm just using one zone on this at the moment.
Some zombies that respawned weren't following the player Is that because there were no nodes? Looks good
Title: Re: Make zombies respawn when player walks to far away?
Post by: DuaLVII on May 28, 2014, 11:29:50 am
Some zombies that respawned weren't following the player Is that because there were no nodes? Looks good

Not that there were no nodes there was just no exterior goal for them to go to, but it works.
Title: Re: Make zombies respawn when player walks to far away?
Post by: NaviLlicious on May 28, 2014, 02:43:50 pm
Not that there were no nodes there was just no exterior goal for them to go to, but it works.
Gotcha
Title: Re: Make zombies respawn when player walks to far away?
Post by: DuaLVII on May 29, 2014, 09:38:04 am
Update, All issues I was having before are fixed and powerups don't spawn on zombie deaths from distance.
Just going to do a hard test on it before sending it out.

DuaLVII's - Respawning Update (http://www.youtube.com/watch?v=eCYjgqhVxdA#ws)
Title: Re: Make zombies respawn when player walks to far away?
Post by: NaviLlicious on May 29, 2014, 10:19:42 am
Very nice can't wait I appreciate It dude
Title: Re: Make zombies respawn when player walks to far away?
Post by: DuaLVII on June 01, 2014, 08:49:50 am
I've done a hard test on this script with zombie spawn delays of 0.1 and wait between rounds as 5 seconds and all worked really well.

I've harshly modified the round_spawning feature which delayed me putting this out for a little while because if round_spawning was to bug out in higher waves it could go terribly wrong so it shouldn't do this.

I won't put this up as a tutorial for now until it's properly tested so consider it as a beta.



Open up _zombiemode.gsc and search for `level.overridePlayerDamage = ::player_damage_override;` around line 103.
Below add the following;
Code Snippet
Plaintext
level.zombies_to_add = 0;

Next find `round_spawning()` around line 1435.
Replace the whole round_spawning() function with this;
Code Snippet
Plaintext
round_spawning()
{
level endon( "intermission" );
/#
level endon( "kill_round" );
#/

if( level.intermission )
{
return;
}

if( level.enemy_spawns.size < 1 )
{
ASSERTMSG( "No spawners with targetname zombie_spawner in map." );
return;
}

/#
if ( GetDVarInt( "zombie_cheat" ) == 2 || GetDVarInt( "zombie_cheat" ) >= 4 )
{
return;
}
#/

ai_calculate_health();

count = 0;

//CODER MOD: TOMMY K
players = get_players();
for( i = 0; i < players.size; i++ )
{
players[i].zombification_time = 0;
}

max = level.zombie_vars["zombie_max_ai"];

multiplier = level.round_number / 5;
if( multiplier < 1 )
{
multiplier = 1;
}

// After round 10, exponentially have more AI attack the player
if( level.round_number >= 10 )
{
multiplier *= level.round_number * 0.15;
}

player_num = get_players().size;

if( player_num == 1 )
{
max += int( ( 0.5 * level.zombie_vars["zombie_ai_per_player"] ) * multiplier );
}
else
{
max += int( ( ( player_num - 1 ) * level.zombie_vars["zombie_ai_per_player"] ) * multiplier );
}



if(level.round_number < 3 && level.script == "nazi_zombie_asylum")
{
if(get_players().size > 1)
{

max = get_players().size * 3 + level.round_number;

}
else
{

max = 6;

}
}
else if ( level.first_round )
{
max = int( max * 0.2 );
}
else if (level.round_number < 3)
{
max = int( max * 0.4 );
}
else if (level.round_number < 4)
{
max = int( max * 0.6 );
}
else if (level.round_number < 5)
{
max = int( max * 0.8 );
}


level.zombie_total = max;
mixed_spawns = 0; // Number of mixed spawns this round.  Currently means number of dogs in a mixed round

// DEBUG HACK:
//max = 1;
old_spawn = undefined;
while(1) //while( count < max )
{

spawn_point = level.enemy_spawns[RandomInt( level.enemy_spawns.size )];

if( !IsDefined( old_spawn ) )
{
old_spawn = spawn_point;
}
else if( Spawn_point == old_spawn )
{
spawn_point = level.enemy_spawns[RandomInt( level.enemy_spawns.size )];
}
old_spawn = spawn_point;

// iPrintLn(spawn_point.targetname + " " + level.zombie_vars["zombie_spawn_delay"]);
while( get_enemy_count() > 31 )
{
wait( 0.05 );
}

// MM Mix in dog spawns...
if ( IsDefined( level.mixed_rounds_enabled ) && level.mixed_rounds_enabled == 1 )
{
spawn_dog = false;
if ( level.round_number > 30 )
{
if ( RandomInt(100) < 3 )
{
spawn_dog = true;
}
}
else if ( level.round_number > 25 && mixed_spawns < 3 )
{
if ( RandomInt(100) < 2 )
{
spawn_dog = true;
}
}
else if ( level.round_number > 20 && mixed_spawns < 2 )
{
if ( RandomInt(100) < 2 )
{
spawn_dog = true;
}
}
else if ( level.round_number > 15 && mixed_spawns < 1 )
{
if ( RandomInt(100) < 1 )
{
spawn_dog = true;
}
}

if ( spawn_dog )
{
keys = GetArrayKeys( level.zones );
for ( i=0; i<keys.size; i++ )
{
if ( level.zones[ keys[i] ].is_occupied )
{
akeys = GetArrayKeys( level.zones[ keys[i] ].adjacent_zones );
for ( k=0; k<akeys.size; k++ )
{
if ( level.zones[ akeys[k] ].is_active &&
!level.zones[ akeys[k] ].is_occupied &&
level.zones[ akeys[k] ].dog_locations.size > 0 )
{
maps\_zombiemode_dogs::special_dog_spawn( undefined, 1 );
level.zombie_total--;
wait_network_frame();
}
}
}
}
}
}

ai = spawn_zombie( spawn_point );
if( IsDefined( ai ) )
{
level.zombie_total--;
ai thread dist_check();
ai thread round_spawn_failsafe();
count++;
}
if(count >= max)
{
while(get_enemy_count() + level.zombie_total > 0)
{
kill_and_replace(true);
if(level.zombies_to_add > 0)
break;
wait(0.1);
}
//iPrintLn("zombie_total is set to " + level.zombie_total);
level.zombies_to_add = 0; // fail safe
}
max = run_respawn_check(max);
wait( level.zombie_vars["zombie_spawn_delay"] );
wait_network_frame();
if(count >= max)
{
//iPrintLnBold("round_spawning() has ended");
break;
}
//iPrintLn("zombie_total is set to " + level.zombie_total);
}
thread last_zombie_runner();
}



Below the end of the round_spawning function, Add these 4 functions in;

Code Snippet
Plaintext
run_respawn_check(max)
{
kill_and_replace(true);
if(level.zombies_to_add > 0)
{
//iPrintLn("zombie_to_add is set to " + level.zombies_to_add);
max += level.zombies_to_add;
level.zombie_total += level.zombies_to_add;
level.zombies_to_add = 0;
kill_and_replace(false);
iPrintLn("zombie_total is set to " + level.zombie_total);
}
return max;
}

last_zombie_runner()
{
if( level.round_number > 3 )
{
while( 1 )
{
zombies = getaiarray( "axis" );
if( zombies.size == 1 && zombies[0].has_legs == true )
{
var = randomintrange(1, 4);
zombies[0] set_run_anim( "sprint" + var );                       
zombies[0].run_combatanim = level.scr_anim[zombies[0].animname]["sprint" + var];
}
else if(zombies.size <= 0)
break;
wait(0.5);

//zombies = getaiarray("axis"); DuaLVII : WTF?
}
}
}

dist_check()
{
self endon("death");
max_dist_for_respawn = 1000;
too_far_away = false;
all_players = GetPlayers();
wait(5); // time to spawn and move around a bit before checking
while(1)
{
for(i = 0; i < all_players.size; i++)
{
zombie_distance = Distance(all_players[i].origin, self.origin);
if( zombie_distance >= max_dist_for_respawn)
{
too_far_away = true;
}
else
{
too_far_away = false;
break;
}
}
if(too_far_away == true)
{
//level.zombies_to_add++;
self.kill_and_replace = true;
//self dodamage((self.health * 100), self.origin); //Killing before round_spawning has a chance to pick up on it could result in round end
break;
}
wait(1);
}
}

kill_and_replace(check)
{
zombies = getaiarray( "axis" );
for(i = 0; i < zombies.size; i++)
{
if(isDefined(zombies[i].kill_and_replace) && zombies[i].kill_and_replace == true)
{
if(check == true)
{
level.zombies_to_add++;
}
else
{
zombies[i] dodamage((zombies[i].health * 100), zombies[i].origin);
}
}
}
}

Save the _zombiemode.gsc and then open up your _zombiemode_spawner.gsc
Search for `zombie_can_drop_powerups( zombie )` and replace the function with this;

Code Snippet
Plaintext
zombie_can_drop_powerups( zombie )
{
if( zombie.damageweapon == "zombie_cymbal_monkey" || isDefined(zombie.kill_and_replace) && zombie.kill_and_replace == true )
{
return false;
}

return true;
}
Title: Re: Make zombies respawn when player walks to far away?
Post by: NaviLlicious on June 01, 2014, 02:22:02 pm
Seems to work perfectly thanks a bunch!