Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: thehivetyrant on Fri 26/03/2010 01:22:12

Title: [SOLVED] Getting rid of charcaters.
Post by: thehivetyrant on Fri 26/03/2010 01:22:12
Hi,

I'm trying to get rid of a character when i kill him. I'm having several issues.

I place this code within rep_ex section of the global script. So it repeatedly check whether it's true.


if(EnemyHealth[1] < 1)                    // if the enemy's health is 0 or less.
 {
   KillCount += 1;                           // Add 1 to killcount interger variable. This part causes problems since when enemy is dead it just
                                           //adds one every game loop since the condition is true. I only want this to happen once. :(
   cStitches.LockView(3);                // Changes view to a blob of blood
   cStitches.StopMoving();               // Make the enemy stop following the character.
}


Generally it's the adding to the variable thats the problem. is there a way to disable a character all together or possibly a way to only run a part inside that if statement once?
Title: Re: Getting rid of charcaters.
Post by: Gilbert on Fri 26/03/2010 01:27:21
There are many ways. One way is to check also the variable KillCount:



if((EnemyHealth[1] < 1)&&(KillCount==0))                    // if the enemy's health is 0 or less.
 {
   KillCount += 1;                           // Add 1 to killcount interger variable. This part causes problems since when enemy is dead it just
                                           //adds one every game loop since the condition is true. I only want this to happen once. :(
   cStitches.LockView(3);                // Changes view to a blob of blood
   cStitches.StopMoving();               // Make the enemy stop following the character.
}

Title: Re: Getting rid of charcaters.
Post by: thehivetyrant on Fri 26/03/2010 02:05:40
Haha please explain another way then  :P

Since i have multiple enemies which the player can kill, each adds 1 to the variable.
I cant be sure which the player will kill first so i can't use that way.

I did try checking whether the enemy 'cStitches' is in View 3.


if(EnemyHealth[1] < 1 && cStitches.View != 3)
 {
   KillCount += 1;
   cStitches.StopMoving();
   cStitches.LockView(3);
 }


This should go through once because both are not true and then stop.

But the enemy turns into the blood blob and then continues to move. I cannot fathom why.
It may have something to do with code elsewhere.

I just had a check, my  cStitches.FollowCharacter(cGrim,  10, 0); was in the rep_ex also.
But i placed it into 'When room first loads' so it would only tell them to follow at the start, i was hoping if i tell it to stop i'd stop forever.

Is there any errors on the above mumbo jumbo?

Thanks in advance
ps: forgive my spelling, keyboards acting up.
Title: Re: Getting rid of charcaters.
Post by: Gilbert on Fri 26/03/2010 02:10:35
Add this after cStitches.StopMoving(); and see if this fixes your problem:
cStitches.FollowCharacter(null);

Otherwise the character will still continue to follow the player. The StopMoving() will only stop him for that moment.
Title: Re: Getting rid of charcaters.
Post by: thehivetyrant on Fri 26/03/2010 02:17:56
That fixed the following problem good and proper, and i understand why which is good.

However i notied another problem now.

They turn to a blood blob, it adds 1 to kill count, it seems to keep adding to the kill count if the player is colliding with the blob. if he's not colliding then it doesnt add any.

Strange!

Do you think i need to be more specific with he View? since it's only when i collide, in past code i have:



if (cStitches.PPCollidesWithC(cGrim) && !cStitches.Animating) //Enemy is colliding & not animating
  {
    cStitches.LockView(VATTACK); // Enter attack animation view
    cStitches.Animate(0, 2, eOnce, eNoBlock, eForwards); //animate once through
  }
  if(cStitches.View == VATTACK && cStitches.Frame == 5)  //animation done
  {
    if(cStitches.PPCollidesWithC(cGrim))
    {
      PlayerHP -= StitchesAttackPower; // reduce health variable by 10
      HP.Width -= StitchesAttackPower; // reduce healthbar by 10 pixels
    }
    cStitches.UnlockView();
  }


PPcollide works the same as usual collision, but is for a Pixel perfect script is all.

Title: Re: Getting rid of charcaters.
Post by: thehivetyrant on Fri 26/03/2010 02:28:25
This could probably have something to do with it, it's also in rep_ex and probably activates when colliding;

Even though he's stuck in blood blob view, he changes behind the scenes to the attack animation (doesn't actually show) and then my Original code loops again adding moreto Killcount.

Sound plausible?


If so, it seems i should add an if statement that checks whether he's not in view 3 before doing attack collision detecton.

ps: your up late :)
Title: Re: Getting rid of charcaters.
Post by: thehivetyrant on Fri 26/03/2010 02:34:38
Yeah adding an if statement over the attack collision checking whether he's in View 3 or not, worked.

I wouldn't have been able to get to this conclusion without you.

It's really good to talk things through, free's up the brain.

Thanks chummy!
Title: Re: [SOLVED] Getting rid of charcaters.
Post by: Gilbert on Fri 26/03/2010 03:56:47
Alternatively you may also set up a variable for each enemy which is set to some other values when the enemy is killed, so you may check this later.

But anyway, there are many ways to accomplish the same goal. As long as a way work and is not overcomplicated it's ok.

Glad to hear that your problems were solved. :D