Author Topic: OnDamaged do somethings but only once  (Read 251 times)

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
OnDamaged do somethings but only once
« on: July 25, 2012, 02:35:44 am »


                I'm trying to make a raid type encounter, and the creature will do certain things during points of its health, but only once at each stage. It works great for one stage, but never get's to stage2 as I'm using a 'return', but don't know a way around it. Any suggestions is welcome... Here's what I've got now.


apparently I don't know the secret to posting code without it jumbling up. ':blink:'

int step1 = GetLocalInt  (OBJECT_SELF, "step1");
int step2 = GetLocalInt  (OBJECT_SELF, "step2");int step3 = GetLocalInt  (OBJECT_SELF, "step3");
int step4 = GetLocalInt  (OBJECT_SELF, "step4");
int nMaxHP = GetMaxHitPoints(); // OBJECT_SELF (the caller) is default
int nCurHP = GetCurrentHitPoints(); // OBJECT_SELF (the caller) is default

//Step1
if (step1 == 1){return;}//Another option besides return to get to step2?
if (nCurHP < (nMaxHP / 2))
{
// stop whatever the creature is doing
ClearAllActions();
ActionSpeakString("I'm at 50%!");
SetLocalInt(OBJECT_SELF,"step1",1);//so step1 only happens once.
}
//Step2
if (step2 == 1){return;}
if (nCurHP < (nMaxHP / 4))
{
// stop whatever the creature is doing
ClearAllActions();
ActionSpeakString("I'm at 20%!");
SetLocalInt(OBJECT_SELF,"step2",1);//so step2 only happens once.
}
               
               

               


                     Modifié par Buddywarrior, 25 juillet 2012 - 01:50 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
OnDamaged do somethings but only once
« Reply #1 on: July 25, 2012, 02:53:58 am »


               

Buddywarrior wrote...

 I'm trying to make a raid type encounter, and the creature will do certain things during points of its health, but only once at each stage. It works great for one stage, but never get's to stage2 as I'm using a 'return', but don't know a way around it. Any suggestions is welcome... Here's what I've got now.

int step1 = GetLocalInt  (OBJECT_SELF, "step1");     int step2 = GetLocalInt  (OBJECT_SELF, "step2");     int step3 = GetLocalInt  (OBJECT_SELF, "step3");     int step4 = GetLocalInt  (OBJECT_SELF, "step4");
     int nMaxHP = GetMaxHitPoints(); // OBJECT_SELF (the caller) is default     int nCurHP = GetCurrentHitPoints(); // OBJECT_SELF (the caller) is default
//Step1
    if (step1 == 1){return;}//Another option besides return to get to step2?    if (nCurHP < (nMaxHP / 2))          {               // stop whatever the creature is doing               ClearAllActions();               ActionSpeakString("I'm at 50%!");               SetLocalInt(OBJECT_SELF,"step1",1);//so step1 only happens once.          }
//Step2
    if (step2 == 1){return;}    if (nCurHP < (nMaxHP / 4))          {               // stop whatever the creature is doing               ClearAllActions();               ActionSpeakString("I'm at 20%!");               SetLocalInt(OBJECT_SELF,"step2",1);//so step2 only happens once.          }


Your format is messy. Try something like this:

int nStep = GetLocalInt(OBJECT_SELF, "step");
int nMax = GetMaxHitPoints();
int nCur = GetCurrentHitPoints();
if(nStep == 0  && (nCur < (nMax/2)))
  {
 nStep++;
 SetLocalInt(OBJECT_SELF, "step", nstep);
  // Do 1/2 HP behavior
  }
if(nStep == 1 && (nCur < (nMax/4)))
 {
nStep++;
SetLocalInt(OBJECT_SELF, "step", nstep);
// Do 1/4 HP behavior
 }
...

Edit: Adding the resetting of the local integer, as this may not be obvious- technically you can do this just once at the end.
               
               

               


                     Modifié par WhiZard, 25 juillet 2012 - 02:05 .
                     
                  


            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
OnDamaged do somethings but only once
« Reply #2 on: July 25, 2012, 03:14:54 am »


               I had to remove all the null/white spaces to correct it, can't we use [code=auto:0] anymore to post? Sorry this reply is off topic from my original intention.