Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Khristian Cammilleri on Sun 26/07/2009 19:56:48

Title: How Can I Do To Make Somebody To Kill My Main Character? [Finally Closed!]
Post by: Khristian Cammilleri on Sun 26/07/2009 19:56:48
I Have Tried Many Times But I Can't Find The Right Script...
The Basic Idea Is :  ???
If The Main Char Is Very Close The Bad Guy Attacks Him...

What Should I Use?
IsCollidingWithChar Or AreThingsOverlapping....And How It Works?? :'(

Please Need Help  ::)


Title: Re: How Can I Do To Make Somebody To Kill My Main Character?
Post by: on Sun 26/07/2009 22:17:54
CollidingWithChar is okay, but it will only work if the two characters really overlap- that will be VERY close. What I would do is check the x values, as in:

if (player.x <= cEnemy.x+20)
{
 cEnemy.say("I keel u now!");
  player.say("Ohnoes I be dead!");
}

This will make the enemy attack if the player is within 20px range, or less.
If the player is able to approach the enemy from left and right, you can:

if (player.x <= cEnemy.x+20 || player.x <= cEnemy.x-20)
Title: Re: How Can I Do To Make Somebody To Kill My Main Character?
Post by: Khristian Cammilleri on Sun 26/07/2009 22:29:43
So I Just Have To Copy Exactly That Using My Own Characters Right?
:D
That's A Very Common Question But I Never Finish To Understand It...


Thanks!  ;D
Title: Re: How Can I Do To Make Somebody To Kill My Main Character?
Post by: on Sun 26/07/2009 22:39:30
You will need to put the code into any room where the enemy attack can happen. if it's just one room, put it into that room's repeteadly_execute. There are more elegant ways, but it should work without cutting the framerate.
Title: Re: How Can I Do To Make Somebody To Kill My Main Character?
Post by: Ethan D on Sun 26/07/2009 22:45:57
well you don't need to copy that exactly in fact if you copy it exactly your main character wont die it will just say what it is told to.  If you actually want him to be attacked then you will have to run the animation of the attack and then change the room to a gameover screen you have.

Also  If you only have
if (player.x <= cEnemy.x+20 || player.x <= cEnemy.x-20)

then your player will be attacked if the enemy is 20 or less pixels to the right or left but if your for instance 30 pixels above the enemy then the attack will still occur but it will look very strange and probably wouldnt make sense.  I would recommend adding to that

if(player.x  cEnemy.x +20 || player.x <= cEnemy.x=20) && ((player.y <= cEnemy.y + 3)  && (player.y >= cEnemy.y -3))


This will make it so the enemy has to be within the 20 pixels to the left or right but also has to be within a 6 pixel area either 3 above or 3 below the character so that the enemy will actually be close to the character.
If this isn't clear enough feel free to ask.
Title: Re: How Can I Do To Make Somebody To Kill My Main Character?
Post by: Khris on Mon 27/07/2009 09:18:49
It's supposed to be
if (player.x <= cEnemy.x+20 && player.x >= cEnemy.x-20)

I'd do:
function DistWithin(this Character*, int dist) {
  int xd = player.x - this.x, yd = player.y - this.y;
  yd = yd*2;
  return xd*xd + yd*yd <= dist*dist;
}


Now you can use
  if (cEnemy.DistWithin(20)) {
    ...
in repeatedly_execute.

Note that I'm doubling yd so the area is an ellipse that's dist high and dist*2 wide.
Title: Re: How Can I Do To Make Somebody To Kill My Main Character?
Post by: .M.M. on Mon 27/07/2009 22:46:38
Or make sprites with big transparent areas for the enemy and call AreThingsOverlapping. This works only with "Pixel-prefect detection" set as "true" (look into General setings, the "Visual" part).
Title: Re: How Can I Do To Make Somebody To Kill My Main Character?
Post by: Khristian Cammilleri on Tue 28/07/2009 14:13:15
Wow! So Many Answers ;D
Thanks a lot!!!
Title: Re: How Can I Do To Make Somebody To Kill My Main Character?
Post by: Khristian Cammilleri on Tue 28/07/2009 16:08:26
Ok..Now The Player is Attacked...Then He Loses 10 HP of 100 hp
But He Loses His Health Instantly...

My Code:

function room_RepExec()
{
if ((cEgo.x <= cZombie1.x+20 || cEgo.x <= cZombie1.x-20) && ((cEgo.y <= cZombie1.y + 10)  && (cEgo.y >= cZombie1.y -10)))
{
cZombie1.LockViewFrame(5, 8, 0);cZombie1.Animate(8, 3,eOnce, eNoBlock);
PlaySound(0);gHealth-=10;
}

How Can I Fix It?
Title: Re: How Can I Do To Make Somebody To Kill My Main Character? [Worked Around]
Post by: Matti on Tue 28/07/2009 16:18:49
You could decrease the HP only during a certain frame of the zombie's animation.

Or you could use a timer variable like in the following pseudocode:

int attack=0;

// in the rep-ex:

if (zombie is close && attack==0){
 attack=30;
 hp-=10;
}

if(attack>0) attack--;
Title: Re: How Can I Do To Make Somebody To Kill My Main Character? [Worked Around]
Post by: Khristian Cammilleri on Tue 28/07/2009 16:37:41
Quote from: Mr Matti on Tue 28/07/2009 16:18:49
int attack=0;

// in the rep-ex:

if (zombie is close && attack==0){
 attack=30;
 hp-=10;
}

if(attack>0) attack--;
Mmm It Does The Same..  :-[
Or Perhaps I'm Putting it In the Wrong Place
Title: Re: How Can I Do To Make Somebody To Kill My Main Character? [Worked Around]
Post by: Matti on Tue 28/07/2009 16:40:37
Yeah, that's because 30 is a quite small number. You should try 200 or something. One second is 40 gameloops, so if the counter is set to 30, it means, the zombie attacks (more than) once a second..

EDIT:

But you should really connect the hitpoint reduction to a certain frame of the zombie's animation. Another pseudocode:

if(zombie is close && cZombie.Frame==4){
  blablabla
}

if your animation (or the frame's) delay is larger than 0, you should add the attack variable, because otherwise the HP would be reduced as long as the frame is shown..
Title: Re: How Can I Do To Make Somebody To Kill My Main Character? [Worked Around]
Post by: Khristian Cammilleri on Tue 28/07/2009 18:56:28
Yeah.. i Prefer that
Let's check it
Title: Re: How Can I Do To Make Somebody To Kill My Main Character? [SOLVED]
Post by: Khristian Cammilleri on Tue 28/07/2009 19:15:08
 ;D
Yes, It Works Perfectly

Thanks Everybody!!!
Title: Re: How Can I Do To Make Somebody To Kill My Main Character? [Re-Open]
Post by: Khristian Cammilleri on Tue 28/07/2009 21:21:25
 :)
Title: Re: How Can I Do To Make Somebody To Kill My Main Character? [Solved]
Post by: Matti on Wed 29/07/2009 01:12:02
No problem.
Title: Re: How Can I Do To Make Somebody To Kill My Main Character? [Re-Open]
Post by: Khristian Cammilleri on Sun 02/08/2009 19:25:31
I Need To Add One More Instance:

The Enemy Must Be In The Same Room...
Becouse If The Enemy Is Gone When I'm In The Same Coordinates of the npc
he stills taking me health!

I Need A New Instance plus the other ones

it should be like this
cEnemy.isInTheSameRoom(Player)

How Can I Check If they are in the same room?
Title: Re: How Can I Do To Make Somebody To Kill My Main Character? [Re-Open]
Post by: Khris on Sun 02/08/2009 19:30:03
  if (cEnemy.Room == player.Room)