Author Topic: RE: Any Way to Stop Spell Replenishment When Resting?  (Read 458 times)

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
RE: Any Way to Stop Spell Replenishment When Resting?
« Reply #15 on: August 16, 2011, 01:08:12 pm »


               A more efficient method would be to use nwnx_funcs - but of course, that prob wont serve your needs if this is single player.


nwnx_funcs allows you to retrieve a ¬ delimitated string, containing the spell numbers of the spells the player currently possesses.
Meaning instead of looping 560+ times for all the spells in the game, you only loop about 40 or so, depending on how many spells the player actually has.

eg - At level 1, the loops would be maybe 3-6 for the cantrip spells.

Then nwnx_funcs also allows you to get the remaining uses of the spells, and even set them.

I would store the spell uses on Rest as a local int on the player

SPELL_USES_#### (#### = The spell id)

and then at the end of rest - when it is finished, we set the spell uses back to the value attached to the local ints.


for (nSpell = 0; nSpell < 599; nSpell ++)

Why???
Inefficiency incarnate.


Only seeing now, that Greyfort  has posted the nwnx_funcs stuff already.
               
               

               


                     Modifié par Baaleos, 16 août 2011 - 12:11 .
                     
                  


            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
RE: Any Way to Stop Spell Replenishment When Resting?
« Reply #16 on: August 16, 2011, 01:21:26 pm »


               


#include "x0_i0_stringlib"

string sSpellsKnown = NWNXFuncs_GetKnownSpells(oPC, 9, 0, "¬");

string sSpell = "a Spell"; // Just to kick of the initial loop

int iPos = 0;

while(sSpell != "")

      {

       sSpell = GetTokenByPosition(sSpellsKnown,"¬"iPos);

         //Do whatever you want to do to sSpell between here



        // And here

        iPos++;

      }




               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
RE: Any Way to Stop Spell Replenishment When Resting?
« Reply #17 on: August 17, 2011, 04:46:38 am »


               

Baaleos wrote...



#include "x0_i0_stringlib"
string sSpellsKnown = NWNXFuncs_GetKnownSpells(oPC, 9, 0, "¬");
string sSpell = "a Spell"; // Just to kick of the initial loop
int iPos = 0;
while(sSpell != "")
{
sSpell = GetTokenByPosition(sSpellsKnown,"¬"iPos);
//Do whatever you want to do to sSpell between here

// And here
iPos++;
}


That in itself is a little ineffecent.  Where GetTokenByPosition is great (At leas in My book, I know The Krit cringed every time I used it.) for getting a single token from a string.  To use it in a loop is highly ineffecent.  The loop through all the 500+ spells is possiable more effecent then using this function in a loop.   it would be better to use the base functions from that libary instead of the By position one.  

#include "x0_i0_stringlib"
void main()
{
   struct sStringTokenizer sSpellsKnown =
      GetStringTokenizer(NWNXFuncs_GetKnownSpells(oPC, 9, 0, "¬"), "¬");

    string sSpell;
 
   while(HasMoreTokens(sSpellsKnown))
   {
      AdvanceToNextToken(sSpellsKnown);
      sSpell = GetNextToken(sSpellsKnown); // Or  sSpell = sSpellsKnown.sLastTok;
     
      //Do whatever you want to do to sSpell between here


     // And here
   }
}


Still even with that using StringParse from x3_inc_string would prabable be even more effecent.
               
               

               


                     Modifié par Lightfoot8, 17 août 2011 - 03:47 .
                     
                  


            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
RE: Any Way to Stop Spell Replenishment When Resting?
« Reply #18 on: August 17, 2011, 09:43:51 am »


               Still, I just think its better to loop through the spells we know we have, rather than the 500+ that we dont have.

Iterating through 500 rows can cause a slight freeze in server performance, and if multiple players were doing it, it would be really noticable.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
RE: Any Way to Stop Spell Replenishment When Resting?
« Reply #19 on: August 17, 2011, 04:30:47 pm »


               

Baaleos wrote...

Still, I just think its better to loop through the spells we know we have, rather than the 500+ that we dont have.

Iterating through 500 rows can cause a slight freeze in server performance, and if multiple players were doing it, it would be really noticable.


Agreed.
               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
RE: Any Way to Stop Spell Replenishment When Resting?
« Reply #20 on: August 17, 2011, 04:37:05 pm »


               Only have five players on the Server, only one is a wizard (which is the only class this fires for) - so "inefficiency" isn't really an issue; its as efficient as I need it to be.