Aller au contenu

Photo

DecrementRemainingSpellUses for Sorcerers


  • Veuillez vous connecter pour répondre
7 réponses à ce sujet

#1
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages
Hi All,

I have a script that removes spells remaining for the PC's.

I set it to remove from the standard classes:

if(GetLevelByclass(class_TYPE_BARD, oPC) > 0
  || GetLevelByclass(class_TYPE_WIZARD, oPC) > 0
  || GetLevelByclass(class_TYPE_SORCERER, oPC) > 0
  || GetLevelByclass(class_TYPE_CLERIC, oPC) > 0
  || GetLevelByclass(class_TYPE_DRUID, oPC) > 0
  || GetLevelByclass(class_TYPE_PALADIN, oPC) > 0
  || GetLevelByclass(class_TYPE_RANGER, oPC) > 0) 
  {Penalise = 1;}  


The above code has the word "class" altered when pasted into this forum for some reason, but is not incorrect in the toolset.

HOWEVER, for some reason, the Sorcerer does not have their spells removed. I have not checked every class yet, but clerics, druids, wizards and bards do have them removed OK. I will check the others, but if I do not come back, assume the problem is just with the sorcerers.

Any reason why I cannot use the DecrementRemainingSpellUses for Sorcerers?

DEBUG says they are removed, but they are not when looking at the spells afterwards.

Thanks.

Lance.

Modifié par Lance Botelle, 06 janvier 2011 - 11:56 .


#2
MasterChanger

MasterChanger
  • Members
  • 686 messages
I would have thought that the issue would be related to non-memorizing casters, where spells of the same level share uses. If it works for Bards, though, that can't be the case.

Even if you're not ultimately planning to use it for Spirit Shamen and Favored Souls, maybe try it out with them and see how it works? (You mentioned "standard classes" only).

#3
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages

MasterChanger wrote...

I would have thought that the issue would be related to non-memorizing casters, where spells of the same level share uses. If it works for Bards, though, that can't be the case.

Even if you're not ultimately planning to use it for Spirit Shamen and Favored Souls, maybe try it out with them and see how it works? (You mentioned "standard classes" only).


Hi MasterChanger,

EDIT: OK, I think I know my problem. It was a stupid one ... doh! If the PC had more than one spell "memorised", the loop only removes one "copy" of it. Therefore, this issue is more noticeable with classes that "share" their spells. When I tested with the same classes memorising more than one copy of the spell, then I started to see similar results. There were one or two anomolies, which I cannot explain, but that may be down to other issues just to get through the test.

What is really annoying, is that I even have commented my own code to tell me as much!


OK, I have looked into this a little more, testing those other classes as well, and here are the results when trying to remove all spells they have learned via a loop:-

Favoured Soul: Starts: 9. Removed: 7. Remain: 2
Sorcerer: Starts: 9. Removed: 6. Remain: 3
Spirit Shamen: Starts: 9. Removed: 8. Remain: 1

Bard: Starts: 2. Removed: 2. Remain: 0. (Control test)

I was mistaken in that the function *does* remove *some* spells from the sorcerer, but like the Favoured Soul and Spirit Shamen, not every spell is removed from a sorcerer, where it does for the bard (and other classes). Therefore, the debug figure of the number of spells removed is correct. The problem is that not *every* spell is removed.

Maybe there is something in this "shared spell uses" that you mention then?

Basically, for some reason, I am unable to remove all the spells. My method involves using a loop of the spells.2da and comparing spells memorized and decrementing on a find. It should be straight forward and works fine on most classes with "normal" spell arrangements.

Is there a way around the problem?

Many thanks for looking.

Lance.

Modifié par Lance Botelle, 07 janvier 2011 - 02:28 .


#4
BartjeD

BartjeD
  • Members
  • 249 messages
what happens if you decrement them by a very large number, say 99. Does that do anything different?

#5
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages

BartjeD wrote...

what happens if you decrement them by a very large number, say 99. Does that do anything different?


Hi Bjarne,

The function does not allow you to decrement by more than one at a time. You could do this by using a while loop, but I think I decdied against this to allow players some spells if they went to the trouble of learning the same spell more than once.
Of course, I may change this at a later time. Image IPB

By the way, in case you missed my edit, I did resolve the problem. Image IPB

Lance.

#6
BartjeD

BartjeD
  • Members
  • 249 messages
Ah yes I did! Good to hear!

#7
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
This is proven code below, use nSet to be above 0 if you want that number to remain. 0 removes all usage, while 1 removes it if more than 1 is memorized. This was used a long time ago when folks could log out and come back in and get all their spells memorized, this basically would remove them again manually.


void ReduceSpellUses(object oPC, int iSpellId, int nSet=0) {
   int nUses = GetHasSpell(iSpellId, oPC);
   int nLast = -1;
   while (nUses>nSet) {
      DecrementRemainingSpellUses(oPC, iSpellId);
	  nUses = GetHasSpell(iSpellId, oPC);
	  if (nLast==nUses) return;
	  nLast=nUses;
   }
}

void ReduceFeatUses(object oPC, int nFeatID, int nSet=0) {
   int nUses = GetHasFeat(nFeatID, oPC);
   int nLast = -1;
   while (nUses>nSet) {
      DecrementRemainingFeatUses(oPC, nFeatID);
	  nUses = GetHasFeat(nFeatID, oPC);
	  if (nLast==nUses) return;
	  nLast=nUses;
   }
}

This is in it's entirety found in the Common Script Library, in the inside of _SCInclude_Saveuses.nss

Modifié par painofdungeoneternal, 07 janvier 2011 - 10:18 .


#8
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages
Hi Pain...

I only just noticed this response (did not receive a reminder) ....

Many thanks for these functions. They are similar to what I had in mind . :) 

The main reason I have currently not used a loop to do this is because I am already looping through the entire spells.2da. It may be too much to handle. (i.e. while looping every spell.) I have something similar in another area of the module, and I have had to split the process to allow the game to cope. However, I may look at this again.

By the way, why not just the following (in either case) .... Doesn't the function "return" afterwards anyway?

void ReduceFeatUses(object oPC, int nFeatID, int nSet=0)
{
int nUses = GetHasFeat(nFeatID, oPC);

while (nUses>nSet)
{
DecrementRemainingFeatUses(oPC, nFeatID);
nUses = GetHasFeat(nFeatID, oPC);
}

}


I will take a look at them and make good use of them where needed.

Lance.

Modifié par Lance Botelle, 14 janvier 2011 - 01:15 .