Author Topic: GetMaxHitPoints() as a float?  (Read 471 times)

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
GetMaxHitPoints() as a float?
« on: July 26, 2012, 05:46:44 pm »


                I'm using GetMaxHitPoints()  to identify different stages in combat on a creature, but I would like more control by using a float instead of an int. For example, using int I can have the creature say something at 50% health, but not at 75% health.

int nMax = GetMaxHitPoints(); //Max HP
int nCur = GetCurrentHitPoints(); //Current HP
float fFifty = nMax * 0.5;

if (nCur < (nMax\\2){//this works}

if (nCur < fFifty){ //this does not work}

" COMPARISON TEST HAS INVALID OPERANDS" is the error I get. Is this because GetMaxHitPoints and GetCurrentHitPoints are int and can't be changed to float even when using IntToFloat?


Thanks as always for the support.  '<img'>
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
GetMaxHitPoints() as a float?
« Reply #1 on: July 26, 2012, 06:04:49 pm »


               simpy use IntToFloat on nCur or FloatToInt on fFifty like this
int nFifty = FloatToInt(nMax*0.5);

or you can avoid using floats completely like this:
int nSeventyFive = (nMax*100)/75; (nMax*75)/100;

EDIT: pretty serious and stupid mistake, thanks FailedBard for catching that
               
               

               


                     Modifié par ShaDoOoW, 26 juillet 2012 - 09:58 .
                     
                  


            

Legacy_Buddywarrior

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
GetMaxHitPoints() as a float?
« Reply #2 on: July 26, 2012, 09:27:47 pm »


               

ShaDoOoW wrote...

simpy use IntToFloat on nCur or FloatToInt on fFifty like this
int nFifty = FloatToInt(nMax*0.5);

or you can avoid using floats completely like this:
int nSeventyFive = (nMax*100)/75;


Never fails to be humbled here. Thank you kindly Shadow.
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
GetMaxHitPoints() as a float?
« Reply #3 on: July 26, 2012, 10:11:25 pm »


               I think ShadoOow may have meant this though:

int nSeventyFive = (nMax*75)/100;


               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
GetMaxHitPoints() as a float?
« Reply #4 on: July 26, 2012, 11:01:05 pm »


               FB: yes my mistake

anyway - is it possible to convert int to float also using math like this:
float f = d6()*1.0;

It might be advantaging when you are dealing with two numbers already and one of them is static. Also it might be a good subject to profilling this method over IntToFloat function.
               
               

               
            

Legacy_Axe_Murderer

  • Full Member
  • ***
  • Posts: 199
  • Karma: +0/-0
GetMaxHitPoints() as a float?
« Reply #5 on: July 27, 2012, 02:13:31 am »


               float f = d6();
the = operator makes the conversion from int to float because f is defined as a float. Multiplying by 1.0f makes the expression a float prior to the assignment, but it is superfulous and wasteful since it doesn't change the value of the expression and you will get the conversion already with the = operator. Stated another way, it is pointless to introduce another operator just to force the datatype conversion you will already get in the assignment. It only makes sense when you do it directly in the boolean comparison in the statement, or with parameter passing:
int n = whatever;
if( (n *1.0) < 3.1415926 ) DoSomething( n *1.0 ); // parameter expects a float

Here it makes sense because you are avoiding the cost of maintaining a separate floating point variable simply to hold the same value in a different format, solely for use in comparisons and parameters. Additionally, you can only go from int to float using such a method, not the other way around. For example,
if( n < (3.1415926 *1) ) DoSomething();
won't work because the multiplication won't allow the expression to become less precise, only more precise. This is crucially important sometimes because the boolean often computes differently when it's been converted to a float...particularly with the == and != comparison operators. Consider n set to 3 in the following for instance...

Of course using IntToFloat() and FloatToInt() is much clearer to read if you're going to do it directly like that anyway:
int n = whatever;
if( IntToFloat( n ) < 3.1415926 ) DoSomething( IntToFloat( n ));
-or-
if( n < FloatToInt( 3.1415926 )) DoSomething( IntToFloat( n ));


Since the performance difference is likely to be less than negligable, I would say writing the code more clearly is the wiser choice in the long run. But it probably really boils down to personal preference. And if you want to change from float to int for the boolean op, you are compelled to use FloatToInt.
               
               

               


                     Modifié par Axe_Murderer, 27 juillet 2012 - 02:09 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
GetMaxHitPoints() as a float?
« Reply #6 on: July 27, 2012, 03:07:21 am »


               @Axe

float f = d6();
Does not work in NWScript.

The = operator will not convert the int into a float.

Both
float f = d6() * 1.0;
float f = 1.0 * d6();
Will work,  since the product of both is a float.


-------
@Shadow

My guess is that the *1.0 would be faster, Just because there is no overhead for the function call.  But since it does happen through the VM profiling would not hurt.  The * operator is a function call in the VM after all.  
               
               

               


                     Modifié par Lightfoot8, 27 juillet 2012 - 02:13 .
                     
                  


            

Legacy_Axe_Murderer

  • Full Member
  • ***
  • Posts: 199
  • Karma: +0/-0
GetMaxHitPoints() as a float?
« Reply #7 on: July 27, 2012, 03:20:40 am »


               Ok, I forget.

Regardless, I still promote using the functions for clarity. Names are decidedly easier to read than are symbols and numbers. I expect they are probably slightly less efficient than math however. So inside an intense loop, you might measure a noticeable difference...perhaps.
               
               

               
            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
GetMaxHitPoints() as a float?
« Reply #8 on: July 27, 2012, 12:58:40 pm »


               I like this ,especially for a boss with lots of HP.Can you post your working script?
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
GetMaxHitPoints() as a float?
« Reply #9 on: July 27, 2012, 01:42:42 pm »


               I do exactly this for certain boss fights.


//Additional Script for the Master of the Void Boss Fight - Damage event


#include "nwnx_funcs"
#include "invoke_inc"
#include "ritual_inc"
#include "nos_sounds_inc"
void DoCrystalHealing(int i)
{

 object oCrystal = GetNearestObjectByTag("dark_crystal");
 if(oCrystal == OBJECT_INVALID || !GetIsObjectValid(oCrystal))
    {
        return;
    }
    SetLocalObject(oCrystal,"INV_TARGET",OBJECT_SELF);
    SetLocalInt(oCrystal,"INV_HEAL",i);
    AssignCommand(oCrystal,DoSpell(22,oCrystal, OBJECT_SELF));
}

object GetAClone()
{
int i;
 for(i=1;i<=10;i++)
 {
    object oClone = GetLocalObject(OBJECT_SELF,"SHADOW_COPY_"+IntToString(i));
    if(GetIsObjectValid(oClone) && !GetIsDead(oClone))
        {
            return oClone;
        }
 }
 return OBJECT_INVALID;

}

void WakfuFun2(object oPC)
{
    DelayCommand(1.00,SpeakString("Hey there.... wana play?"));
    NWNXFuncs_SetSkill(OBJECT_SELF,SKILL_SPELLCRAFT,127);
    DelayCommand(2.00,DoSpell(5,OBJECT_SELF,OBJECT_SELF));
    DelayCommand(6.00,ActionCastSpellAtObject(SPELL_EPIC_HELLBALL,oPC,METAMAGIC_ANY,TRUE,0,PROJECTILE_PATH_TYPE_DEFAULT,TRUE));
    DelayCommand(9.00,ActionCastSpellAtObject(SPELL_EPIC_RUIN,oPC,METAMAGIC_ANY,TRUE,0,PROJECTILE_PATH_TYPE_DEFAULT,TRUE));
    DelayCommand(15.00,ActionCastSpellAtObject(SPELL_EPIC_RUIN,oPC,METAMAGIC_ANY,TRUE,0,PROJECTILE_PATH_TYPE_DEFAULT,TRUE));
    DelayCommand(25.00,DoSpell(5,OBJECT_SELF,OBJECT_SELF));
    DelayCommand(30.00,ToggleRitualMode(OBJECT_SELF));
    DelayCommand(31.00,ProcessPossibleRitual(OBJECT_SELF,"Estuans Interius"));
    DelayCommand(32.00,ProcessPossibleRitual(OBJECT_SELF,"Ira veh"));
    DelayCommand(33.00,ProcessPossibleRitual(OBJECT_SELF,"Estuans Int"));
    DelayCommand(34.00,ProcessPossibleRitual(OBJECT_SELF,"Ira Veh"));
    DelayCommand(35.70,ProcessPossibleRitual(OBJECT_SELF,"Sephiroth"));
    DelayCommand(38.00,SpeakString("This is a friend of mine... Meet Sephiroth"));
    DelayCommand(48.00,SpeakString("Slow down... Relax!!"));
    DelayCommand(49.00,DoSpell(5,OBJECT_SELF,OBJECT_SELF));
    DelayCommand(50.00,ToggleRitualMode(OBJECT_SELF));
    DelayCommand(52.00,ProcessPossibleRitual(OBJECT_SELF,"i curse all who enter"));
    DelayCommand(54.00,ProcessPossibleRitual(OBJECT_SELF,"this circle ever pure"));
    DelayCommand(56.00,ProcessPossibleRitual(OBJECT_SELF,"be they friend or foe"));
    DelayCommand(58.00,ProcessPossibleRitual(OBJECT_SELF,"their feet grow ever old"));
    effect eImmob = EffectCutsceneImmobilize();
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eImmob,OBJECT_SELF,15.00);
    DelayCommand(69.00,DoSpell(5,OBJECT_SELF,OBJECT_SELF));
}


void WakfuFun(object oPC)
{
    DelayCommand(1.00,SpeakString("Im gonna enjoy ripping you apart!!"));
    NWNXFuncs_SetSkill(OBJECT_SELF,SKILL_SPELLCRAFT,127);
    DelayCommand(2.00,DoSpell(5,OBJECT_SELF,OBJECT_SELF));
    DelayCommand(6.00,ActionCastSpellAtObject(SPELL_EPIC_HELLBALL,oPC,METAMAGIC_ANY,TRUE,0,PROJECTILE_PATH_TYPE_DEFAULT,TRUE));
    DelayCommand(9.00,ActionCastSpellAtObject(SPELL_EPIC_RUIN,oPC,METAMAGIC_ANY,TRUE,0,PROJECTILE_PATH_TYPE_DEFAULT,TRUE));
    DelayCommand(15.00,ActionCastSpellAtObject(SPELL_EPIC_RUIN,oPC,METAMAGIC_ANY,TRUE,0,PROJECTILE_PATH_TYPE_DEFAULT,TRUE));
    DelayCommand(25.00,DoSpell(5,OBJECT_SELF,OBJECT_SELF));
    DelayCommand(30.00,ToggleRitualMode(OBJECT_SELF));
    DelayCommand(31.00,ProcessPossibleRitual(OBJECT_SELF,"Bird of Flame"));
    DelayCommand(33.00,ProcessPossibleRitual(OBJECT_SELF,"Phoenix Take Flight"));
    DelayCommand(35.00,ProcessPossibleRitual(OBJECT_SELF,"We Summon your Grace"));
    DelayCommand(37.00,ProcessPossibleRitual(OBJECT_SELF,"To win the fight"));
    DelayCommand(38.00,SpeakString("Come forth Dark Phoenix!!"));
    DelayCommand(48.00,SpeakString("How about a little mind control?"));
    DelayCommand(49.00,DoSpell(5,OBJECT_SELF,OBJECT_SELF));
    DelayCommand(50.00,ToggleRitualMode(OBJECT_SELF));
    DelayCommand(52.00,ProcessPossibleRitual(OBJECT_SELF,"Hear me slaves"));
    DelayCommand(54.00,ProcessPossibleRitual(OBJECT_SELF,"do my will "));
    DelayCommand(56.00,ProcessPossibleRitual(OBJECT_SELF,"hear my voice "));
    DelayCommand(58.00,ProcessPossibleRitual(OBJECT_SELF,"see the world with new eyes"));
    effect eImmob = EffectCutsceneImmobilize();
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eImmob,OBJECT_SELF,15.00);
    DelayCommand(69.00,DoSpell(5,OBJECT_SELF,OBJECT_SELF));
}


void CreateDopplegangers(object oDamager)
{
 object oFac = GetFirstFactionMember(oDamager);
 int i = 1;
 while(oFac != OBJECT_INVALID)
 {
    if(GetArea(oFac) == GetArea(oDamager))
      {

                    effect eVisual = EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_3);
                    ApplyEffectToObject(DURATION_TYPE_INSTANT,eVisual,oFac);


                    object oClone = CopyObject(oFac,GetLocation(oFac));
                    if(GetLevelByclass(class_TYPE_SORCERER,oFac)>=20)
                    {
                        AssignCommand(oClone,WakfuFun(oFac));
                    }else if(GetLevelByclass(class_TYPE_FIGHTER,oFac)>=20)
                    {
                        AssignCommand(oClone,WakfuFun2(oFac));
                    }
                    if(GetStringLowerCase(GetSubRace(oFac))=="vampire" ||GetStringLowerCase(GetSubRace(oFac))=="wraith" || GetStringLowerCase(GetSubRace(oFac))=="lich")
                        {
                            NWNXFuncs_SetRace(oClone,RACIAL_TYPE_UNDEAD);
                        }
                    SetPlotFlag(oClone,TRUE);
                    object oItem = GetFirstItemInInventory(oClone);
                    while(oItem != OBJECT_INVALID)
                        {
                            SetPlotFlag(oItem,FALSE);
                            DestroyObject(oItem,0.01);
                            oItem = GetNextItemInInventory(oClone);
                        }
                    int iFaction = NWNXFuncs_GetFactionID(OBJECT_SELF);
                    NWNXFuncs_SetFactionID(oClone,iFaction);
                    SetIsTemporaryEnemy(oFac,oClone,FALSE);
                    SetLootable(oClone,FALSE);
                    SetName(oClone,GetName(oFac)+"'s Shadow");
                    int i;
                    for(i = 0;i<=12;i++)
                        {
                            string sScript = NWNXFuncs_GetEventScript(OBJECT_SELF,i);
                            NWNXFuncs_SetEventScript(oClone,sScript,i);
                        }
                        int nSlot;
                    for (nSlot=0; nSlot<NUM_INVENTORY_SLOTS; nSlot++)
                           {
                                 oItem=GetItemInSlot(nSlot, OBJECT_SELF);
                                if(oItem != OBJECT_INVALID)
                                    {
                                        //SetPlotFlag(oItem,FALSE);
                                        //DestroyObject(oItem,0.01);
                                        SetPickpocketableFlag(oItem,FALSE);
                                        SetDroppableFlag( oItem,FALSE);
                                    }
                            }
                     int iGold = GetGold(oClone);
                     TakeGoldFromCreature(iGold,oClone,TRUE);
                     SetPlotFlag(oClone,FALSE);
                    NWNXFuncs_SetEventScript(oClone,"dopple_gdeath",10);
                    SetLocalInt(oClone,"DIVINITY_C_POINTS",20);
                    AssignCommand(oClone,ActionAttack(oFac));
                    effect eVis = SupernaturalEffect(EffectVisualEffect(VFX_DUR_PROT_SHADOW_ARMOR));
                    ApplyEffectToObject(DURATION_TYPE_PERMANENT,eVis,oClone);
                    SetLocalObject(OBJECT_SELF,"SHADOW_COPY_"+IntToString(i),oClone);
       i++;
      }
     oFac = GetNextFactionMember(oDamager);
 }


}

void SendMessageToParty(object oDamager, string sText)
{
        object oFac = GetFirstFactionMember(oDamager);
        while(oFac != OBJECT_INVALID)
        {
            SendMessageToPC(oFac,sText);
            oFac = GetNextFactionMember(oDamager);
        }

}

void ApplyEffectToParty(object oDamager, effect eEffect, float fDur)
{
        object oFac = GetFirstFactionMember(oDamager);
        while(oFac != OBJECT_INVALID)
        {
                if(GetArea(oFac) == GetArea(oDamager))
                    {
                        ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eEffect,oFac,fDur);

                    }
                    oFac = GetNextFactionMember(oDamager);
        }
}

int iRandomSpell()
{
 int i = d6(1);
 switch(i)
 {
  case 1: return SPELL_ISAACS_GREATER_MISSILE_STORM; break;
  case 2: return SPELL_WORD_OF_FAITH; break;
  case 3: return SPELL_WOUNDING_WHISPERS; break;
  case 4: return SPELL_WAIL_OF_THE_BANSHEE; break;
  case 5: return SPELL_ENERGY_DRAIN; break;
  case 6: return SPELL_BIGBYS_FORCEFUL_HAND; break;
 }
 return 0;
}



void CastSpellAgainstParty(object oDamager)
{
        object oFac = GetFirstFactionMember(oDamager);
        SetPlotFlag(OBJECT_SELF,TRUE);
        while(oFac != OBJECT_INVALID)
        {
                if(GetArea(oFac) == GetArea(oDamager))
                    {
                        AssignCommand(OBJECT_SELF,ActionCastSpellAtObject(iRandomSpell(),oFac,TRUE,40,PROJECTILE_PATH_TYPE_DEFAULT,TRUE));
                    }
                     oFac = GetNextFactionMember(oDamager);
        }
        SetPlotFlag(OBJECT_SELF,FALSE);
}


void main()
{
    object oBoss = OBJECT_SELF;
    object oDamager = GetLastDamager();
    int iCurrentHealth = GetCurrentHitPoints(oBoss);
    int iMax = GetMaxHitPoints(oBoss);
    int iRegen = GetLocalInt(OBJECT_SELF,"REGEN_");
    int iImmune = GetLocalInt(OBJECT_SELF,"IMMS_DONE");
    float fPercent = (IntToFloat(iCurrentHealth)/IntToFloat(iMax))*100.00;

    if(GetAClone() != OBJECT_INVALID)
    {
            effect eHeal2 = EffectHeal(150);
            effect eVisHeal2 = EffectVisualEffect(VFX_IMP_EVIL_HELP);
            effect eRegen = EffectRegenerate(50,2.00);
            //effect eLink2 = EffectLinkEffects(eVisHeal2,eHeal2);
            ApplyEffectToObject(DURATION_TYPE_INSTANT,eHeal2,OBJECT_SELF);
            ApplyEffectToObject(DURATION_TYPE_INSTANT,eVisHeal2,OBJECT_SELF);
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eRegen,OBJECT_SELF,15.00);

    }
    if(!iImmune)
    {
        effect e = EffectImmunity(IMMUNITY_TYPE_PARALYSIS);
        ApplyEffectToObject(DURATION_TYPE_PERMANENT,e,OBJECT_SELF);
        e = EffectImmunity(IMMUNITY_TYPE_CRITICAL_HIT);
        ApplyEffectToObject(DURATION_TYPE_PERMANENT,e,OBJECT_SELF);
        SetLocalInt(OBJECT_SELF,"IMMS_DONE",1);
    }
    if(iRegen)
    {
        int i = GetDamageDealtByType(DAMAGE_TYPE_MAGICAL);
        i = i + GetDamageDealtByType(DAMAGE_TYPE_NEGATIVE);
        i = (d6(2)* 3)+i;
        if(i >= 1)
        {
            effect eHeal = EffectHeal(i*2);
            effect eVisHeal = EffectVisualEffect(VFX_IMP_EVIL_HELP);
            effect eLink = EffectLinkEffects(eVisHeal,eHeal);
            ApplyEffectToObject(DURATION_TYPE_INSTANT,eLink,OBJECT_SELF);
            FloatingTextStringOnCreature("Healed:"+IntToString(i),OBJECT_SELF);
            DoCrystalHealing(i);
        }
    }
     if(fPercent >= 1.00 && fPercent <= 8.00)
        {
            int HasDone0103 = GetLocalInt(oBoss,"HASDONE0103");
            if(!HasDone0103)
                {

                    SpeakString("Please.... Nooooo......");
                    SetLocalInt(oBoss,"HASDONE0103",1);
                    CastSpellAgainstParty(oDamager);
                    effect eRegen2 = SupernaturalEffect(EffectRegenerate(75,3.00));
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eRegen2,oBoss,60.00);
                    return;
                }
        }
    if(fPercent >= 10.00 && fPercent <= 15.00)
        {
            int HasDone1015 = GetLocalInt(oBoss,"HASDONE1015");
            if(!HasDone1015)
                {
                    SetAILevel(OBJECT_SELF,AI_LEVEL_HIGH);
                    //SpeakString("This... Cannot Be!!!");
                    PlayNosgothSound(OBJECT_SELF,"diablo_t2","Not even death will save you from me!!",0.75);
                    SetLocalInt(oBoss,"HASDONE1015",1);
                        effect eDarkness = SupernaturalEffect(EffectBlindness());
                        effect eSilence = SupernaturalEffect(EffectSilence());
                        effect eDazed = SupernaturalEffect(EffectDazed());
                        effect eVuln = SupernaturalEffect(EffectDamageImmunityDecrease(DAMAGE_TYPE_NEGATIVE,90));
                        ApplyEffectToParty(oDamager,eDarkness,60.00);
                        ApplyEffectToParty(oDamager,eSilence,60.00);
                        ApplyEffectToParty(oDamager,eVuln,60.00);
                        ApplyEffectToParty(oDamager,eDazed,10.00);
                        effect eDamage = SupernaturalEffect(EffectDamageIncrease(DAMAGE_BONUS_20,DAMAGE_TYPE_NEGATIVE));
                        ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eDamage,OBJECT_SELF,240.00);
                    SendMessageToParty(oDamager,"The Master of the Void is making his last stand...");
                    AssignCommand(GetModule(),SpeakString("The Master of  the Void is making his final Stand.",TALKVOLUME_SHOUT));
                    return;
                }
        }
     if(fPercent >= 20.00 && fPercent <= 25.00)
        {
            int HasDone2025 = GetLocalInt(oBoss,"HASDONE2025");
            if(!HasDone2025)
                {
                    SpeakString("The Shadows themselves renew me!! Hahahaaaa");
                    SetLocalInt(oBoss,"HASDONE2025",1);
                    effect eRegen = SupernaturalEffect(EffectRegenerate(50,2.00));
                    effect eResist1 = SupernaturalEffect(EffectDamageImmunityIncrease(DAMAGE_TYPE_SLASHING,25));
                    effect eResist2 = SupernaturalEffect(EffectDamageImmunityIncrease(DAMAGE_TYPE_PIERCING,25));
                    effect eResist3 = SupernaturalEffect(EffectDamageImmunityIncrease(DAMAGE_TYPE_BLUDGEONING,25));
                    effect eResist4 = SupernaturalEffect(EffectDamageImmunityIncrease(DAMAGE_TYPE_BASE_WEAPON,75));
                    effect eResist5 = SupernaturalEffect(EffectDamageImmunityIncrease(DAMAGE_TYPE_FIRE,25));
                    effect eResist6 = SupernaturalEffect(EffectDamageImmunityIncrease(DAMAGE_TYPE_NEGATIVE,100));
                    effect eResist7 = SupernaturalEffect(EffectDamageImmunityIncrease(DAMAGE_TYPE_SONIC,25));
                    effect eResist8 = SupernaturalEffect(EffectDamageImmunityIncrease(DAMAGE_TYPE_ELECTRICAL,25));
                    effect eResist9 = SupernaturalEffect(EffectDamageImmunityIncrease(DAMAGE_TYPE_ACID,25));
                    effect eResist10 = SupernaturalEffect(EffectDamageImmunityIncrease(DAMAGE_TYPE_COLD,25));
                    effect eResist11 = SupernaturalEffect(EffectDamageImmunityIncrease(DAMAGE_TYPE_MAGICAL,25));
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eResist1,oBoss,120.00);
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eResist2,oBoss,120.00);
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eResist3,oBoss,120.00);
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eResist4,oBoss,120.00);
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eResist5,oBoss,120.00);
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eResist6,oBoss,120.00);
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eResist7,oBoss,120.00);
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eResist8,oBoss,120.00);
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eResist9,oBoss,120.00);
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eResist10,oBoss,120.00);
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eResist11,oBoss,120.00);
                    ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eRegen,oBoss,120.00);

                    SetLocalInt(OBJECT_SELF,"REGEN_",1);
                    DelayCommand(120.00,SetLocalInt(OBJECT_SELF,"REGEN_",0));
                    SendMessageToParty(oDamager,"The Master of the Void has entered a Regeneration Phase.");
                    AssignCommand(GetModule(),SpeakString("The Master of the Void has entered a Regeneration Phase. Magic and Negative Energy will heal him for the next 2 minutes.",TALKVOLUME_SHOUT));
                    return;
                }
        }
        if(fPercent >= 30.00 && fPercent <= 40.00)
        {
            int HasDone3040 = GetLocalInt(oBoss,"HASDONE3040");
            if(!HasDone3040)
                {
                    SpeakString("You will not destroy us....Destroy yourselves instead....");
                    SetLocalInt(oBoss,"HASDONE3040",1);
                    CreateDopplegangers(oDamager);
                    return;
                }
        }


    if(fPercent >= 50.00 && fPercent <= 65.00)
        {
            int HasDone5065 = GetLocalInt(oBoss,"HASDONE5065");
            if(!HasDone5065)
                {
                    //SpeakString("We shall not be stopped by the likes of you!!!");
                    PlayNosgothSound(OBJECT_SELF,"diablo_t1","Baaaah... the smell of life surrounds me!!",0.75);
                    SetLocalInt(oBoss,"HASDONE5065",1);
                    effect eKnockDownImmunity = EffectImmunity(IMMUNITY_TYPE_KNOCKDOWN);
                    effect s = EffectDamageImmunityIncrease(DAMAGE_TYPE_SLASHING,60);
                    ApplyEffectToObject(DURATION_TYPE_PERMANENT,s,OBJECT_SELF);
                    ApplyEffectToObject(DURATION_TYPE_PERMANENT,eKnockDownImmunity,OBJECT_SELF);
                    SetBaseAttackBonus(6,oBoss);
                    return;
                }
        }





}


It allows me to enable certain things at certain points during the bosses battle.
Eg- When close to death ... say certain things,
or when at certain points of health, spawn shadow clones of the players.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
GetMaxHitPoints() as a float?
« Reply #10 on: July 28, 2012, 02:58:23 am »


               Why not use an integer instead of a float?  You aren't checking beyond the decimal point anyway.

This
float fPercent = (IntToFloat(iCurrentHealth)/IntToFloat(iMax))*100.00;

would work better as
int  nPercent = (iCurrentHealth * 100) / iMax
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
GetMaxHitPoints() as a float?
« Reply #11 on: July 30, 2012, 01:01:35 am »


               

Knight_Shield wrote...

I like this ,especially for a boss with lots of HP.Can you post your working script?


Here is one way I would do it. 

void main()
{
   int nCur = 19 - 20*GetCurrentHitPoints()/GetMaxHitPoints();
   int nStep = GetLocalInt(OBJECT_SELF,"step");

   if (nCur > nStep)
   {
     switch (nStep +1)
     {
       case 1:
          // Code for 5% damaged
          if (nCur == 1) break;
       case 2:
          // Code for 10% damaged
          if (nCur == 2) break;
       case 3:
          // Code for 15% damaged
          if (nCur == 3) break;
       case 4:
          // Code for 20% damaged
          if (nCur == 4) break;
       case 5:
          // Code for 25% damaged
          if (nCur == 5) break;
       case 6:
          // Code for 30% damaged
          if (nCur == 6) break;
       case 7:
          // Code for 35% damaged
          if (nCur == 7) break;
       case 8:
          // Code for 40% damaged
          if (nCur == 8) break;
       case 9:
          // Code for 45% damaged
          if (nCur == 9) break;
       case 10:
          // Code for 50% damaged
          if (nCur == 10) break;
       case 11:
          // Code for 55% damaged
          if (nCur == 11) break;
       case 12:
          // Code for 60% damaged
          if (nCur == 12) break;
       case 13:
          // Code for 65% damaged
          if (nCur == 13) break;
       case 14:
          // Code for 70% damaged
          if (nCur == 14) break;
       case 15:
          // Code for 75% damaged
          if (nCur == 15) break;
       case 16:
          // Code for 80% damaged
          if (nCur == 16) break;
       case 17:
          // Code for 85% damaged
          if (nCur == 17) break;
       case 18:
          // Code for 90% damaged
          if (nCur == 18) break;
       case 19:
          // Code for 95% damaged
          if (nCur == 19) break;
       case 20:
          // Code for 100% damaged

     }
     SetLocalInt(OBJECT_SELF,"step",nCur);
   }
}
               
               

               


                     Modifié par Lightfoot8, 30 juillet 2012 - 12:03 .