Author Topic: Scaling Mummy Dust & Dragon Knight  (Read 1953 times)

Legacy_Nic Mercy

  • Full Member
  • ***
  • Posts: 154
  • Karma: +0/-0
Scaling Mummy Dust & Dragon Knight
« on: April 12, 2015, 07:49:22 pm »


               

I have a modified/renamed version of the epic spell Mummy Dust for my module. It spawns an undead for most casters but for druids it spawns a treant. This works just fine. What I'd like to do however, is make it scale with the caster's level a bit.


 


Here's the script currently:



#include "x2_inc_spellhook"
#include "inc_epicspells"
void main()
{
    if (!X2PreSpellCastCode())
    {
        return;
    }
    if (GetCanCastSpell(OBJECT_SELF, MUMDUST_DC, MUMDUST_S, MUMDUST_XP))
    {
    //Declare major variables
    int nDuration = 24;
    //effect eVis = EffectVisualEffect(VFX_FNF_SUMMON_UNDEAD);
    effect eSummon;
    //NC:EDIT
    // Add check for druid for different summon

   int nDruid = GetLevelByClass(CLASS_TYPE_DRUID, OBJECT_SELF);
   string sSummon;

    if (nDruid >=20)
        {
        sSummon = "s_treant_001";
        }
    else
        {
        sSummon = "s_morglord_001";
        }

   //NC:EDIT

    //Summon the appropriate creature based on the summoner level
    //Warrior Mummy
    //NC:EDIT
    //Treant Druid only
    eSummon = EffectSummonCreature(sSummon,496,1.0f);
    //NC:EDIT

    eSummon = ExtraordinaryEffect(eSummon);
    //Apply the summon visual and summon the undead.
    //ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eVis, GetSpellTargetLocation());
    ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eSummon, GetSpellTargetLocation(), HoursToSeconds(nDuration));
}


}

I'd like the spell to summon stronger minions every 5 levels. So the one we have in the script are the base versions. Basically at 25, 30, 35, and 40 the spell summons a stronger version of the minion. I also want to do the same with my modified Dragon Knight spell. How can I edit the scripts to do that?



#include "x2_inc_toollib"
#include "inc_epicspells"
#include "x2_inc_spellhook"
void main()
{
    if (!X2PreSpellCastCode())
    {
        return;
    }
    if (GetCanCastSpell(OBJECT_SELF, DRG_KNI_DC, DRG_KNI_S, DRG_KNI_XP))
    {
        //Declare major variables
        int nDuration = 20;
        effect eSummon;
        effect eVis = EffectVisualEffect(460);
        eSummon = EffectSummonCreature("s_drake_001",481,0.0f,TRUE);

        // * make it so dragon cannot be dispelled
        eSummon = ExtraordinaryEffect(eSummon);
        //Apply the summon visual and summon the dragon.
        ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eSummon,GetSpellTargetLocation(), RoundsToSeconds(nDuration));
        DelayCommand(1.0f,ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eVis,GetSpellTargetLocation()));
    }
}




               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Scaling Mummy Dust & Dragon Knight
« Reply #1 on: April 13, 2015, 01:14:38 am »


               

Use switch command. In pseudo code (ie can't remember exact way of determining class)


int index = (level - 20) / 5
 
int IsDruid = // test if pc is a druid
 
if IsDruid
 
switch(index)
{
case 0: summon base monster
            break;
case 1: summon next monster up
             break;
//cut
 
case 4: summon toughest monster
}
else
//repeat above switch case substituting non druidic creature summons

 


TR



               
               

               
            

Legacy_Nic Mercy

  • Full Member
  • ***
  • Posts: 154
  • Karma: +0/-0
Scaling Mummy Dust & Dragon Knight
« Reply #2 on: April 13, 2015, 02:03:25 am »


               

For my scaling needs it seems that since these are epic spells (which usually have fixed values) the game has a difficult time finding the caster's level for purposes of scaling.


 


I was able to figure out a script on my own that works but it seems... well... inelegant. But it DOES work so I can't complain.


 


Here's the scripts in case anyone wants to do something similar with the epic summons (though I imagine it could be done much better than I did). DO bear in mind I am using Boneshank's Epic Spell System so the script calls on his include.



#include "x2_inc_spellhook"
#include "inc_epicspells"
void main()
{
    if (!X2PreSpellCastCode())
    {
        return;
    }
    if (GetCanCastSpell(OBJECT_SELF, MUMDUST_DC, MUMDUST_S, MUMDUST_XP))
    {
    //Declare major variables
    int nDuration = 24;
    //effect eVis = EffectVisualEffect(VFX_FNF_SUMMON_UNDEAD);
    effect eSummon;
    //NC:EDIT
    // Add check for druid for different summon
    //KA: EDIT
    // Add summon scaling every five levels

   int nDruid = GetLevelByClass(CLASS_TYPE_DRUID, OBJECT_SELF);
   int nWizard = GetLevelByClass(CLASS_TYPE_WIZARD, OBJECT_SELF);
   int nSorcerer = GetLevelByClass(CLASS_TYPE_SORCERER, OBJECT_SELF);
   int nCleric = GetLevelByClass(CLASS_TYPE_CLERIC, OBJECT_SELF);
   string sSummon;

    if ((nDruid > 19) && (nDruid <=24))
         {
          sSummon = "s_treant_001";
         }
          else if ((nDruid >= 25) && (nDruid <= 29))
         {
          sSummon = "s_treant_002";
          }
          else if ((nDruid >= 30) && (nDruid <= 34))
         {
          sSummon = "s_treant_003";
         }
          else if ((nDruid >= 35) && (nDruid <= 39))
         {
          sSummon = "s_treant_004";
         }
          else if ((nDruid == 40))
         {
          sSummon = "s_treant_005";
         }
    else
          if ((nWizard > 19) && (nWizard <=24))
         {
          sSummon = "s_morglord_001";
         }
          else if ((nWizard >= 25) && (nWizard <= 29))
         {
          sSummon = "s_morglord_002";
          }
          else if ((nWizard >= 30) && (nWizard <= 34))
         {
          sSummon = "s_morglord_003";
         }
          else if ((nWizard >= 35) && (nWizard <= 39))
         {
          sSummon = "s_morglord_004";
         }
          else if ((nWizard == 40))
         {
          sSummon = "s_morglord_005";
         }
    else
          if ((nSorcerer > 19) && (nSorcerer <=24))
         {
          sSummon = "s_morglord_001";
         }
          else if ((nSorcerer >= 25) && (nSorcerer <= 29))
         {
          sSummon = "s_morglord_002";
          }
          else if ((nSorcerer >= 30) && (nSorcerer <= 34))
         {
          sSummon = "s_morglord_003";
         }
          else if ((nSorcerer >= 35) && (nSorcerer <= 39))
         {
          sSummon = "s_morglord_004";
         }
          else if ((nSorcerer == 40))
         {
          sSummon = "s_morglord_005";
         }
    else
          if ((nCleric > 19) && (nCleric <=24))
         {
          sSummon = "s_morglord_001";
         }
          else if ((nCleric >= 25) && (nCleric <= 29))
         {
          sSummon = "s_morglord_002";
          }
          else if ((nCleric >= 30) && (nCleric <= 34))
         {
          sSummon = "s_morglord_003";
         }
          else if ((nCleric >= 35) && (nCleric <= 39))
         {
          sSummon = "s_morglord_004";
         }
          else if ((nCleric == 40))
         {
          sSummon = "s_morglord_005";
         }

   //NC:EDIT

    //Summon the appropriate creature based on the summoner level
    //Warrior Mummy
    //NC:EDIT
    //Treant Druid only
    eSummon = EffectSummonCreature(sSummon,496,1.0f);
    //NC:EDIT

    eSummon = ExtraordinaryEffect(eSummon);
    //Apply the summon visual and summon the undead.
    //ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eVis, GetSpellTargetLocation());
    ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eSummon, GetSpellTargetLocation(), HoursToSeconds(nDuration));
}


}


I did basically the same thing with Dragon Knight for each class.



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Scaling Mummy Dust & Dragon Knight
« Reply #3 on: April 13, 2015, 02:04:26 am »


               

In fact for code clarity and maintenance it might pay to make the 2 switch statements and associated code, into 2 small functions.


 


TR



               
               

               
            

Legacy_Nic Mercy

  • Full Member
  • ***
  • Posts: 154
  • Karma: +0/-0
Scaling Mummy Dust & Dragon Knight
« Reply #4 on: April 13, 2015, 02:16:24 am »


               


In fact for code clarity and maintenance it might pay to make the 2 switch statements and associated code, into 2 small functions.


 


TR




 


>_>  unfortunately I have no idea what that means... my scripting skills (ha! skills! as if!) are extremely limited.


               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Scaling Mummy Dust & Dragon Knight
« Reply #5 on: April 13, 2015, 06:01:09 am »


               


>_>  unfortunately I have no idea what that means... my scripting skills (ha! skills! as if!) are extremely limited.




you can write


switch(iLevel)


{


case 20:


case 21


case 22:


case 23:


case 24:


case 25:


something;


case 26:


case.......


}


 


absolutely best is what Tarot posted you, this is a something between his and yours version, easier to understand



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Scaling Mummy Dust & Dragon Knight
« Reply #6 on: April 13, 2015, 11:57:58 am »


               
OK (huh nearly said orange juice - J & K are next to each other on keyboard so I had to correct OJ to OK). I have gone through your routine posted above. Checking the function prototype for GetLevelByClass there is a default parameter which means that you don't need to include OBJECT_SELF, which changes

 



GetLevelByClass(CLASS_TYPE_DRUID, OBJECT_SELF);


to



GetLevelByClass(CLASS_TYPE_DRUID);


 

Apart from that I have reworked your code and came to a realisation. There is one case that hasn't been considered before by either of us. That is what happens when you have a level 20 druid who is also a level 20 other type of spellcaster? Which version of the spell is to be cast? I didn't really handle it in the code that follows, just exited the routine. I also noticed that for the three other classes they all summoned the same creature at the same level, so I combined them into 1 routine.

 

Given that

#include "inc_epicspells"

and

GetCanCastSpell(OBJECT_SELF, MUMDUST_DC, MUMDUST_S, MUMDUST_XP)

are (AFAIK) not part of standard 1.69 code, I have not actually tested the code that follows because I don't seem to have access to those bits. What I can say is that it should work, just I am not going to guarantee it. Should this code work then it should work for all cases where the PC has between 20 and 39 levels overall. When you get to level 40 there is the case mentioned in the preceding paragraph.

 



#include "x2_inc_spellhook"
#include "inc_epicspells"
 
string GetDruidCreature(int iCreature)
 
// determines which creature a druid will summon
 
{
    string sCreatureName;
    switch(iCreature)
    {
        case 0:
               sCreatureName = "s_treant_001";
               break;
        case 1:
               sCreatureName = "s_treant_002";
               break;
        case 2:
               sCreatureName = "s_treant_003";
               break;
        case 3:
               sCreatureName = "s_treant_004";
               break;
        Case default:
               sCreatureName = "s_treant_005";
               break;
    }
    return sCreatureName;
}
 
string GetNonDruidCreature(int iCreature)
 
// determines which creature a non-druid will summon
 
{
    string sCreatureName;
    switch(index)
    {
        case 0:
               sCreatureName = "s_morglord_001";
               break;
        case 1:
               sCreatureName = "s_morglord_002";
               break;
        case 2:
               sCreatureName = "s_morglord_003";
               break;
        case 3:
               sCreatureName = "s_morglord_004";
               break;
        Case default:
               sCreatureName = "s_morglord_005";
               break;
    }
    return sCreatureName;
}
 
void main()
{
    if (!X2PreSpellCastCode())
        return;
 
    if (GetCanCastSpell(OBJECT_SELF, MUMDUST_DC, MUMDUST_S, MUMDUST_XP))
    {
        //Declare major variables
 
        int nDuration = 24;
 
        //effect eVis = EffectVisualEffect(VFX_FNF_SUMMON_UNDEAD);
 
        effect eSummon;
 
        //NC:EDIT
        // Add check for druid for different summon
        //KA: EDIT
        // Add summon scaling every five levels
 
        int iClassCount = 0; //just making sure that the variable is zero probably unnecessary
        int iIndex;
        int nDruid = GetLevelByClass(CLASS_TYPE_DRUID);
        int nWizard = GetLevelByClass(CLASS_TYPE_WIZARD);
        int nSorcerer = GetLevelByClass(CLASS_TYPE_SORCERER);
        int nCleric = GetLevelByClass(CLASS_TYPE_CLERIC);
 
// This section of code counts the number of classes the PC has that qualify to be able to cast the spell
// Because I am lazy I also made it so that iIndex is configured for the switch statements
 
        if(nDruid >= 20)
        {
            iClassCount++;
            iIndex = (nDruid - 20) / 5;
        }
        if(nWizard >= 20)
        {
            iClassCount++;
            iIndex = (nWizard - 20) / 5;
        }
        if(nSorcerer >= 20)
        {
            iClassCount++;
            iIndex = (nSorcerer - 20) / 5;
        }
        if(nCleric >= 20)
        {
            iClassCount++;
            iIndex = (nCleric - 20) / 5;
        }
 
//The next 2 lines make sure that the PC has 1 and only 1 qualifying class
 
        if(iClassCount != 1)
            return;
 
        string sSummon;
 
//if PC is a druid get druidic creature name otherwise get other name
 
        if(nDruid>=20)
            sSummon = GetDruidCreature(iIndex);
        else
            sSummon = GetNonDruidCreature(iIndex);
 
        //NC:EDIT
 
        //Summon the appropriate creature based on the summoner level
        //Warrior Mummy
        //NC:EDIT
        //Treant Druid only
 
        eSummon = EffectSummonCreature(sSummon,496,1.0f);
 
        //NC:EDIT
 
        eSummon = ExtraordinaryEffect(eSummon);
 
        //Apply the summon visual and summon the undead.
        //ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eVis, GetSpellTargetLocation());
 
        ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eSummon, GetSpellTargetLocation(), HoursToSeconds(nDuration));
    }
}


 

Hope this makes things clearer.

 

TR


               
               

               
            

Legacy_Nic Mercy

  • Full Member
  • ***
  • Posts: 154
  • Karma: +0/-0
Scaling Mummy Dust & Dragon Knight
« Reply #7 on: April 13, 2015, 01:59:12 pm »


               

I wont deny my eyes crossed a bit while looking at the code you posted but I did understand a bit of what its doing. Thank you for taking the time to show me an example! I'll definitely keep this handy for reference.


 


Just to note, trying to compile the above script spits out the following error:


 


Error: NSC1040: Syntax error at "default"

 



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Scaling Mummy Dust & Dragon Knight
« Reply #8 on: April 13, 2015, 02:11:46 pm »


               

Try making the uppercase "Case" lowercase '<img'>



               
               

               
            

Legacy_Nic Mercy

  • Full Member
  • ***
  • Posts: 154
  • Karma: +0/-0
Scaling Mummy Dust & Dragon Knight
« Reply #9 on: April 13, 2015, 02:15:51 pm »


               


Try making the uppercase "Case" lowercase '<img'>




 


I actually DID try that! But no effect '<img'>


               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Scaling Mummy Dust & Dragon Knight
« Reply #10 on: April 13, 2015, 02:49:54 pm »


               

Take out the "case" there. I should have read it more closely... default is the keyword by itself, no case.



               
               

               
            

Legacy_Nic Mercy

  • Full Member
  • ***
  • Posts: 154
  • Karma: +0/-0
Scaling Mummy Dust & Dragon Knight
« Reply #11 on: April 13, 2015, 03:26:36 pm »


               

cool i'll give it a shot!


 


EDIT: In regards to     switch(index)     it spits out:


 


Error: NSC1020: Undeclared identifier "index"

Compilation aborted with errors.



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Scaling Mummy Dust & Dragon Knight
« Reply #12 on: April 13, 2015, 06:55:51 pm »


               

Oooops little syntax error. In the second function change switch(index) to switch(iCreature). Should fix. Don't hesitate to report any other errors. (I did mention it was untested).


 


One other thing, look at this thread and follow the first link.


 


TR



               
               

               
            

Legacy_Nic Mercy

  • Full Member
  • ***
  • Posts: 154
  • Karma: +0/-0
Scaling Mummy Dust & Dragon Knight
« Reply #13 on: April 13, 2015, 07:15:50 pm »


               

he he  thank's Tarot! I'll give it a test and let you know the results!



               
               

               
            

Legacy_Nic Mercy

  • Full Member
  • ***
  • Posts: 154
  • Karma: +0/-0
Scaling Mummy Dust & Dragon Knight
« Reply #14 on: April 13, 2015, 07:48:30 pm »


               

After testing, it works exactly as it should! Now here's a question... My mod allows half of a palemaster's levels to add to his casting level. So if you have 30 palemaster levels (and assuming 10 levels of wizard or sorcerer) your spells go off as a level 25 caster. How would I take that into consideration for this script? If I also wanted to have a version that counted ALL of palemaster's levels as part of his casting level for this spell what would that look like as well? I'd like to see both just so I can see (and hopefully understand) how its done for future works.


 


EDIT: also to note. Thanks to what you showed me with Mummy Dust, I was able to adapt your script to the Dragon Knight spell as well and it works perfectly!