How to make my zombie unfriendly?[solved]

Started by , Sun 10/04/2011 17:49:15

Previous topic - Next topic

Bogdan

So I had some problems with scripting.
I'm trying to make a shooter game.
It is 2d and there is one walkable area on which you can walk and it's one line (all characters are on the same Y-coordinate).
The thing I was trying to do is next:
Once you walk onto a region, a zombie will come walking to you.
Once he gets near you he will try to kill you.
You have 100 health points(global variable is defined as hp).
Every time you move away he should follow you and attack you.
I was trying to do that part of the script(where he is following you) with player.Walk command, but it didn't work. He was just standing in one place and didn't move. Somehow with AddWaypoint I menage to make him move, but once I make too many waypoints an error occurs and stops the game. I'm 100% there is a way to do this, although I don't know how.
Perhaps you guys could help me on this.
Here's the script:
Code: ags

//there are some things that I cut from the GlobalScript(keyboard movement), because I don't have any problem with that.
//I need help for this part down.
//this part of the script is in the GlobalScript > Repeatedly_execute function.
//variable terror is at 0, and once you walk onto a region it goes to 1 and zombie should attack you.
//once zombie gets close to you, variable strike(what was on 0 too) goes to 1 and variable terror goes to 2.
//once variable strike gets to 1 zombie should hit you.
// after few seconds he would hit you again.
// if you go away from him, he would follow you again and do the same thing once he gets near you again.
// the way I scripted this doesn't seem to work. :(
// I hope you can help me and thank you in forward.
 if (terror==1) {  
  cZombie1.AddWaypoint (player.x, player.y);
}
  if (cZombie1.x == player.x +10) {   
   terror = 2;
   strike = 1;
  }
  if (strike ==1) {
    cZombie1.StopMoving ();
    cZombie1.ChangeView (8);
   cZombie1.Animate (0, 3, eOnce, eNoBlock, eForwards);
   hp -= 25;
   strike = 0;
   SetTimer (1, 2000);
   cZombie1.ChangeView (1);
  }
  if (IsTimerExpired (1)) {
    strike = 1;
  }
   else if (hp <= 0) {
   Display("you died");
  }
  while (terror ==2) {
    if (player.Moving != 0) {
      terror = 1;
  }
   
  }

Icey

Well I can help with one thing.
Code: ags



cZombie1.FollowCharacter(cplayer, 5, 80);





cZombie1.FollowCharacter(Character* chartofollow, optional int dist,
                          optional int eagerness)

Bogdan

Wow...
Thanks man. That is solved then(I didn't know there was that command o.o).
But I still have problems with other stuff.
Like zombie attacking the main char. Animation that I scripted never happens. :/

Matti

#3
.. because
if (cZombie1.x == player.x +10) {}   
is unlikely to ever being called. Characters don't walk pixel by pixel, so you should have an area for the zombie to attack:
if (cZombie1.x > player.x + 8 && cZombie1.x < player.x + 12) {}   


EDIT:

Quote from: Bogdan on Sun 10/04/2011 18:08:50
I didn't know there was that command

If you just type in "cZombie." the autocomplete window shows you every possible character function.

Icey

Quote from: Bogdan on Sun 10/04/2011 18:08:50
Wow...
Thanks man. That is solved then(I didn't know there was that command o.o).
But I still have problems with other stuff.
Like zombie attacking the main char. Animation that I scripted never happens. :/


No prob.

Bogdan

Well, thanks guys.
My problems are solved... for now.  ;D

SMF spam blocked by CleanTalk