Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Khristian Cammilleri on Fri 31/07/2009 14:11:31

Title: Killing a Npc
Post by: Khristian Cammilleri on Fri 31/07/2009 14:11:31
In My Last Post I Asked How Can Be Killed  My Main Character By A Npc...
I Recieved Some Good Codes...and Now They Work Fine.... ;D

Now I Want To Kill A npc using a new cursor (SMASH :-X)
How exactly would be my code?

Should I Use
if((cEgo.x <= cZombie1.x+20 || cEgo.x <= cZombie1.x-20) && ((cEgo.y <= cZombie1.y + 10)  && (cEgo.y >= cZombie1.y -10))&&(attack==0)) ???

And then What??
Please i Always got a Mess With Fight Scripts....
Title: Re: Killing a Npc
Post by: Khristian Cammilleri on Fri 31/07/2009 14:16:44
For Further information
If the npc is on the right side of me,the playere must run a loop smashing in that direction....otherwise, he has to smash the npc with another loop (left)

When I "Smash" The Npc..The player Runs A loop...
while the npc is falling...
then he stop following the player...etc followcharacter(null)

Finally I have to send The npc to the room (-1)
and unlock the view for the character...

It's Pretty tricky for me...I need help...
How can I Make a code with all this?

Title: Re: Killing a Npc
Post by: Khris on Fri 31/07/2009 14:39:59
First of all, you need to understand the distance code you're using (it's wrong again).

On the x axis, you'll have two boundaries, the lower being cZombie1.x-20 and the upper being cZombie1.x+20.
So to check if the player is in between, player.x has to be greater or equal (>=) than the lower one and (&&) less or equal (<=) than the upper one.

I'm not sure why you seem to completely ignore the function I posted in your last thread (in which you should've posted this) which does all the work for you.
Title: Re: Killing a Npc
Post by: Khristian Cammilleri on Fri 31/07/2009 14:57:56
Uhmmm...So How Exactly your Code Looks Like???


And How Should I Translate It  On My Script?
Title: Re: Killing a Npc
Post by: Matti on Fri 31/07/2009 15:43:52
KhrisMUC ist talking about using the following instead of your current coordinate check:

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;
}


..so that you can simply use
  if (cZombie.DistWithin(20)) {
    ...
in repeatedly_execute.

Just place the function somewhere at the top of your script.

But I really don't get what you're trying to do right now. Is the player supposed to kill the NPC when he's near him and clicking the mouse button?
Title: Re: Killing a Npc
Post by: Khristian Cammilleri on Fri 31/07/2009 18:08:26
Yes,,,
Suppose that you want to Smash a Npc with a Stick..

I ve added one new cursor "smash"...
Then in the Global script I Have to give an Action when i use that cursor on a Npc...


How exactly should the code be?..

if the npc is on the right side of the character?
if the npc is on the left side of the character?



Title: Re: Killing a Npc
Post by: Khristian Cammilleri on Fri 31/07/2009 18:14:06
The coordinate Check is alright ;D

Title: Re: Killing a Npc
Post by: Matti on Fri 31/07/2009 18:23:16
Just check whether the player strikes in the right direction or not. This can be done by checking the player.Loop / cZombie1.Loop (1=left, 2=right) and the x-position of both characters. So if the player loop is 2 and the Zombie's x coordinate is higher than the player's x, the zombie gets hit and vice versa.