[SOLVED] Getting rid of charcaters.

Started by thehivetyrant, Fri 26/03/2010 01:22:12

Previous topic - Next topic

thehivetyrant

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.

Code: ags

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?

Gilbert

There are many ways. One way is to check also the variable KillCount:


Code: ags

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


thehivetyrant

#2
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.

Code: ags

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
Code: ags
  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.

Gilbert

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.

thehivetyrant

#4
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:

Code: ags


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.


thehivetyrant

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 :)

thehivetyrant

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!

Gilbert

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

SMF spam blocked by CleanTalk