3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1] 2

Author Topic: Zombie Respawn - Script HELP!  (Read 2056 times)

« on: June 29, 2011, 08:09:24 PM »
Hello I am trying to make zombies respawn on this game I am making.
So far i have
Code: [Select]
int group = OBJ_0;
int skinmesh = OBJ_22;
int valueprint = OBJ_44;
int zombiescript = OBJ_66;
int zombiechar = OBJ_88;
int zombierigid = OBJ_110;
int zombiepath = OBJ_132;
int zombiesound = OBJ_154;
bool dead = false;
bool reborn = false;
bool alive = true;
int zombiehealth = IN_44;

///-----------------------------------------------------
///                  Main                              |
///-----------------------------------------------------
void Main(){
if(alive == true){
if(zombiehealth <= 0){
   dead = true;
   Death(); //start death process
   }else{
   return;
   }
}
}

///------------------------------------------------------
///                   Death                             |
///------------------------------------------------------
void Death(){
if(dead == true){
   iObjectStop(group);
   iObjectHide(skinmesh);
   iObjectStop(zombiescript);
   iObjectStop(zombiechar);
   iObjectHide(zombierigid);
   iObjectStop(zombiesound);
   reborn = true;
   Reborn();
   }else{
   Main();
   }
}

///------------------------------------------------------
///                   Reborn                            |
///------------------------------------------------------
void Reborn(){
if(reborn == true){
   iObjectReset(group);
   iObjectReset(skinmesh);
   iObjectReset(zombiescript);
   iObjectReset(zombiechar);
   iObjectReset(zombierigid);
   iObjectReset(zombiesound);
   alive = true;
   dead = false;
}
Main();
}   
But every time I press spacebar to see if it works 3D freezes.
Is this code wrong??
Or what is it???

What this is supposed to do is when the valueprint = 0 it stops all parts of the zombies then resets them.
« Reply #1 on: June 29, 2011, 08:10:56 PM »
LULZ Wrong one...sorry :D
« Reply #2 on: June 30, 2011, 11:42:11 AM »
the script is all screwed up miker... not a good habit to call Main() from script...

tell me what you are trying to do... in simple, one line sentences... in a step by step sequence...  no code, just plain english (that's the first step to getting the logic down in script)...  and i'll try to help...

--Mike
« Reply #3 on: June 30, 2011, 11:58:49 AM »
Ok
1 when the zombies health is at 0
2 hides or deletes all parts of the zombie
3. starts all parts over again at were it spawns from
« Reply #4 on: June 30, 2011, 12:20:40 PM »
ok... now i have an idea what you want to do...

ok, next... how many zombies are in the game?

--Mike
« Reply #5 on: June 30, 2011, 12:27:57 PM »
So far just one.
I wanted to get it working before i added more
« Reply #6 on: June 30, 2011, 12:38:24 PM »
ok... so we can assume that there'll be at least 4 to 5 zombies in the final game... and we're gonna plan for that, but initially use just one...

ok... next question...

are the zombies gonna roam freely and then attack when in range... or do you want em to hunt the player...

and how will the zombies get injuries... from being shot, being beat, or both...

--Mike
« Reply #7 on: June 30, 2011, 12:50:35 PM »
Follow the player
Shot
« Reply #8 on: June 30, 2011, 01:13:08 PM »
ok...

i suggest

1) setup your zombies to use the pathfinder object (you may already have done this), and set your player as the target of the pathfinder...  this will eliminate a lot of scripting logic, and you can put in obstacles to coincide with the terrain and buildings and even moving stuff...

2) use your script logic for the zombies to die and respawn...  this will be basically a state engine that will have the following states... searching, pursuing, attacking, beingshot, death, respawn...

your zombie starts out searching... this means the pathfinding ai will be controlling his movement, and your script will just monitor how far away from the player you are... if can see the player then change state to pursue... if close enough to touch player change state to attack...

these states are mainly to control the animation... if you have a dull walk, thats searching... with hands up and growling is pursuing... with hands flailing and teeth gnashing is attacking...

you should also detect when hit by bullet... this changes the state to being shot momentatily (again for animation mainly, you can temporarily drop the zonie back to searching anim and stop his forward speed)... 

also, health goes down... when health reaches zero, state changes to death... and you play death anim...  after death anim plays for a few secs, zombie char vanishes and is in respawn state where he reappears at a random or predetermined spot and his state changes to searching, for the entire thing to repeat itself...

first, set up your playfield  in the editor... terrain, houses, zombie (1), player...

you already know what you script is gonna need to do, and it seems as if you can do it, so we'll script later when you can see the result better...  for now, get the basic stuff working... get the scene together and the zombies chasing the player...

--Mike
« Last Edit: June 30, 2011, 02:01:39 PM by Mike Hense »
« Reply #9 on: July 01, 2011, 12:08:44 PM »
ok...

i suggest

1) setup your zombies to use the pathfinder object (you may already have done this), and set your player as the target of the pathfinder...  this will eliminate a lot of scripting logic, and you can put in obstacles to coincide with the terrain and buildings and even moving stuff...

2) use your script logic for the zombies to die and respawn...  this will be basically a state engine that will have the following states... searching, pursuing, attacking, beingshot, death, respawn...

your zombie starts out searching... this means the pathfinding ai will be controlling his movement, and your script will just monitor how far away from the player you are... if can see the player then change state to pursue... if close enough to touch player change state to attack...

these states are mainly to control the animation... if you have a dull walk, thats searching... with hands up and growling is pursuing... with hands flailing and teeth gnashing is attacking...

you should also detect when hit by bullet... this changes the state to being shot momentatily (again for animation mainly, you can temporarily drop the zonie back to searching anim and stop his forward speed)... 

also, health goes down... when health reaches zero, state changes to death... and you play death anim...  after death anim plays for a few secs, zombie char vanishes and is in respawn state where he reappears at a random or predetermined spot and his state changes to searching, for the entire thing to repeat itself...

first, set up your playfield  in the editor... terrain, houses, zombie (1), player...

you already know what you script is gonna need to do, and it seems as if you can do it, so we'll script later when you can see the result better...  for now, get the basic stuff working... get the scene together and the zombies chasing the player...

--Mike
Yea.....im doomed
« Reply #10 on: July 02, 2011, 10:13:31 AM »
LOL ;D ;D ;D ;D

it's not as bad as it sounds above... the hardest part is always  figuring out what you need to do... now that that's behind you, just take it one step at a time...

make your scene in the editor... set up the zombies to use the pathfinder... and set your player as the pathfinder target...

that's 90% of the game right there... the zombies will home in on the plaer, avoiding whatever obstacles you put in the way...

do that first...

i'll be around to help... as will others...

good luck...

--Mike
« Reply #11 on: July 02, 2011, 11:06:22 PM »
LOL ;D ;D ;D ;D

it's not as bad as it sounds above... the hardest part is always  figuring out what you need to do... now that that's behind you, just take it one step at a time...

make your scene in the editor... set up the zombies to use the pathfinder... and set your player as the pathfinder target...

that's 90% of the game right there... the zombies will home in on the plaer, avoiding whatever obstacles you put in the way...

do that first...

i'll be around to help... as will others...

good luck...

--Mike
Ive had that done..thats why i started that script up there. That has been done for a long time :D
« Reply #12 on: July 03, 2011, 10:06:45 AM »
ok, so all you really need is a script to respawn a dead zombie... right...

simple way is to check health... when health==0 set his move speed to zero... start the death animation...  hide the zombie... start incrementing a timer variable (so the zombie doesn't respawn right away... when the timer reaches a certain point, choose from one of several spawn points... place the zombie there... set his health to 100%...

here's the psuedocode logic...

Code: [Select]
int              health=100;
int              limbo=0;
Vector3[]     spawnPoint(3);

main(){

  if(iInitializing()){
   spawnPoint[0]=Vector3(x,y,z);
   spawnPoint[1]=Vector3(x,y,z);
   spawnPoint[2]=Vector3(x,y,z);
   iObjectLocationSet(zombie_Body,spawnPoint(iFloatRand(0,2));
  }

  get health
  if(health<=0){
    limbo++;
    stop the zombie from moving
    if(limbo==8){
      hide the zombie
    }
    if(limbo>=66){
      limbo=0;
      health=100;
     iObjectLocationSet(zombie_Body,spawnPoint(iFloatRand(0,2));
    }
  }

}

you should be able to follow this... just put code where needed...

that should do it... have a script like this for each zombie (the simplest way to do it)...
start out with one...

--Mike





« Reply #13 on: July 03, 2011, 10:14:46 AM »
Okay so i have to actually customize this.
« Reply #14 on: July 03, 2011, 10:18:09 AM »
yes... it's pseudo code (false code)... just to let you know what needs be done...

some of it is true code, but things like hide the zombie are just notes to tell you what needs to be done (iObjectHide() would be the code) for the various parts that make up the zombie...


--Mike
Pages: [1] 2