Author Topic: Problem With Recharging Staves  (Read 1195 times)

Legacy_Melkior_King

  • Full Member
  • ***
  • Posts: 234
  • Karma: +0/-0
Problem With Recharging Staves
« Reply #15 on: January 06, 2013, 07:58:48 am »


               I presume there is a script which runs OnAcquireItem to add charges to the item?  And/or a script which runs from the recharger?  If so, what's the problem with changing the script so that it checks the item to ensure it's the staff, checks the current item charges and then ensures that the staff is never recharged over 49?

I'd presume that the problem with the variable ELECTRIFIER_CHARGE_MAX would be because you only added it to the blueprint and didn't update the item in the shop.  Try deleting the item from the shop and then adding it again from the blueprint.  If that doesn't work, perhaps using OnAcquireItem to add the variable would work?

Another possible solution: you may be able to fiddle with the OnUnacquireItem script so that it gives the player a no-charges placeholder version of the staff after the last charge is used and the staff is destroyed.  You'd also have to change OnAcquireItem to delete the placeholder item and give the player a charged item when they perform the appropriate "charge staff" action.

I hate unsolved problems. '<img'>
               
               

               


                     Modifié par Melkior_King, 06 janvier 2013 - 08:03 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Problem With Recharging Staves
« Reply #16 on: January 06, 2013, 09:14:26 am »


               

Melkior_King wrote...
I hate unsolved problems. '<img'>


Unsolved??


Sadira of Tyr wrote...

I tried adding this to my scripts, and it works great. I added the light spell too, just in case, lol.

Thanks guys! You are the greatest! 'Posted


               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Problem With Recharging Staves
« Reply #17 on: January 07, 2013, 03:59:38 am »


               Using an odd number of charges and an even number of charges/per use does nothing.  If the item does not bear the plot flag (or is not destroyable) then the only way to guarantee the item will be spared from charge loss destruction is to put an infinite use per day (or a zero charge per use) property listed after all the other charge consuming properties.  An item that has 3 charges and a 2 charge per use property will be destroyed when the charges would be brought down to one (unless it is protected by one of the aforementioned ways).
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Problem With Recharging Staves
« Reply #18 on: January 07, 2013, 04:48:48 am »


               ok,  Then use:

   object oStaff = GetItemActivated();
   if (~GetItemCharges(oStaff) & 1 ) SetItemCharges(oStaff,GetItemCharges(oStaff)+1);
   AssignCommand(oStaff,SetIsDestroyable(FALSE));
               
               

               
            

Legacy_Sadira of Tyr

  • Sr. Member
  • ****
  • Posts: 299
  • Karma: +0/-0
Problem With Recharging Staves
« Reply #19 on: January 07, 2013, 10:40:33 am »


               Well, I did add the zero charges light spell to each of the staves, and I am pretty sure it is listed after the unique power. If not then I would have to change the staves of each player who has already bought one.

I prefer the option to add that last line to the script. Much easier, and no need to change the staves at all.

Thank you. 'Posted
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Problem With Recharging Staves
« Reply #20 on: January 07, 2013, 09:56:26 pm »


               

Lightfoot8 wrote...

ok,  Then use:

   object oStaff = GetItemActivated();
   if (~GetItemCharges(oStaff) & 1 ) SetItemCharges(oStaff,GetItemCharges(oStaff)+1);
   AssignCommand(oStaff,SetIsDestroyable(FALSE));


I am still not sure if that solves any issues.  If the rod had 3 charges remaining and a 2 charge per use property was used, then the number of charges returned by the if check would be either 3 or 1 depending on when the charges were decremented.  Destruction will still occur, though, so ensuring an odd number does not  prevent destruction.

EDIT: Doing a quick test I found that SetItemCharges() is too late in preventing destruction if used in the final use spell script.
               
               

               


                     Modifié par WhiZard, 07 janvier 2013 - 10:09 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Problem With Recharging Staves
« Reply #21 on: January 08, 2013, 03:40:48 am »


               

WhiZard wrote...

Lightfoot8 wrote...

ok,  Then use:

   object oStaff = GetItemActivated();
   if (~GetItemCharges(oStaff) & 1 ) SetItemCharges(oStaff,GetItemCharges(oStaff)+1);
   AssignCommand(oStaff,SetIsDestroyable(FALSE)); 


I am still not sure if that solves any issues.  If the rod had 3 charges remaining and a 2 charge per use property was used, then the number of charges returned by the if check would be either 3 or 1 depending on when the charges were decremented.  Destruction will still occur, though, so ensuring an odd number does not  prevent destruction.

EDIT: Doing a quick test I found that SetItemCharges() is too late in preventing destruction if used in the final use spell script.

 AssignCommand(oStaff,SetIsDestroyable(FALSE));     Will stop the staff from being destroyed.  


if (~GetItemCharges(oStaff) & 1 ) SetItemCharges(oStaff,GetItemCharges(oStaff)+1); will stop the staff from losing all charges and keep him from having to go through the process of delayed iProp removal and re addition to get the staff to have charges again. 

It does hinge on the assumption that the staff started with more then three charges though.   If the Item started with only 2 or three charges the SetIsDestroyable(FALSE));   would not happen in time to save the staff.   If I was 100%  on him using TBS I would have added the OnAquite  section to the script fragment.    But with out him posting his script or *cough*  asking for more information, I just posted the fast solution.   Since the staff is starting with (assumption) more then three charges.  
               
               

               


                     Modifié par Lightfoot8, 08 janvier 2013 - 03:54 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Problem With Recharging Staves
« Reply #22 on: January 08, 2013, 04:51:14 am »


               

Lightfoot8 wrote...

WhiZard wrote...

Lightfoot8 wrote...

ok,  Then use:

   object oStaff = GetItemActivated();
   if (~GetItemCharges(oStaff) & 1 ) SetItemCharges(oStaff,GetItemCharges(oStaff)+1);
   AssignCommand(oStaff,SetIsDestroyable(FALSE)); 


I am still not sure if that solves any issues.  If the rod had 3 charges remaining and a 2 charge per use property was used, then the number of charges returned by the if check would be either 3 or 1 depending on when the charges were decremented.  Destruction will still occur, though, so ensuring an odd number does not  prevent destruction.

EDIT: Doing a quick test I found that SetItemCharges() is too late in preventing destruction if used in the final use spell script.

 AssignCommand(oStaff,SetIsDestroyable(FALSE));     Will stop the staff from being destroyed.  


if (~GetItemCharges(oStaff) & 1 ) SetItemCharges(oStaff,GetItemCharges(oStaff)+1); will stop the staff from losing all charges and keep him from having to go through the process of delayed iProp removal and re addition to get the staff to have charges again. 

It does hinge on the assumption that the staff started with more then three charges though.   If the Item started with only 2 or three charges the SetIsDestroyable(FALSE));   would not happen in time to save the staff.   If I was 100%  on him using TBS I would have added the OnAquite  section to the script fragment.    But with out him posting his script or *cough*  asking for more information, I just posted the fast solution.   Since the staff is starting with (assumption) more then three charges.  


I am really hesistant at recommending the SetIsDestroyable() flag to be used.  It will solve the destruction even when the charges are low, because it blocks the actual destruction.  But it also blocks DestroyObject() which can cause a whole host of problems as the game is not set up to check this flag when it performs many of its copying functions.  For instance, a staff that is not destroyable will be replicated many times in one's inventory when using craft weapon to modify the appearance.

As for ensuring the charges are always at least 1, you could change your if statement to only check for when the charges reach zero as they are depleted before the script fires.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Problem With Recharging Staves
« Reply #23 on: January 08, 2013, 05:25:09 am »


               

WhiZard wrote...

 I am really hesistant at recommending the SetIsDestroyable() flag to be used....     But it also blocks DestroyObject() ...

   
Hmm,  Now that could cause problems. 


  As for ensuring the charges are always at least 1, you could change your if statement to only check for when the charges reach zero as they are depleted before the script fires.

\\
no,  That brings up another host of problems.  When an item drops to 0 charges, it can no longer be charged, leading to another batch of workarounds.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Problem With Recharging Staves
« Reply #24 on: January 08, 2013, 05:28:42 am »


               Here is a modification of Lightfoot's that should get around leaving a Destroyable flag indefinitely.

void main()
{
object oStaff = GetItemActivated();
int nCharges = GetItemCharges(oStaff);
int nChargePerUse = 2;
if (nCharges < nChargePerUse)
  {
  AssignCommand(oStaff,SetIsDestroyable(FALSE));
  DelayCommand(0.5, AssignCommand(oStaff, SetIsDestroyable(TRUE)));
  if(!nCharges) SetItemCharges(oStaff, 1);
  }

EDIT added the ! so the check would be for zero charges
               
               

               


                     Modifié par WhiZard, 08 janvier 2013 - 05:36 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Problem With Recharging Staves
« Reply #25 on: January 08, 2013, 05:34:10 am »


               

Lightfoot8 wrote...

no,  That brings up another host of problems.  When an item drops to 0 charges, it can no longer be charged, leading to another batch of workarounds.


They can be charged in the script. You just need to rest to take advantage of the charges.

EDIT: Did you also realize that depleting from 3 to 1 would run into the exact same issue?  There is no problem with setting charges, it is that when the game detects no more uses for a cast spell property it disables the GUI selection until a rest is completed.
               
               

               


                     Modifié par WhiZard, 08 janvier 2013 - 05:48 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Problem With Recharging Staves
« Reply #26 on: January 08, 2013, 06:18:32 am »


               ok, I guess I have been out of the game to long, So what is your solution for the OP?

EDIT:  I guess you have already given it above..
               
               

               


                     Modifié par Lightfoot8, 08 janvier 2013 - 06:20 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Problem With Recharging Staves
« Reply #27 on: January 08, 2013, 06:22:20 am »


               I posted it at the end of the first page.

WhiZard wrote...

Here is a modification of Lightfoot's that should get around leaving a Destroyable flag indefinitely.

void main()
{
object oStaff = GetItemActivated();
int nCharges = GetItemCharges(oStaff);
int nChargePerUse = 2;
if (nCharges < nChargePerUse)
  {
  AssignCommand(oStaff,SetIsDestroyable(FALSE));
  DelayCommand(0.5, AssignCommand(oStaff, SetIsDestroyable(TRUE)));
  if(!nCharges) SetItemCharges(oStaff, 1);
  }


               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Problem With Recharging Staves
« Reply #28 on: January 08, 2013, 06:50:17 am »


               

WhiZard wrote...

I posted it at the end of the first page.

WhiZard wrote...

Here is a modification of Lightfoot's that should get around leaving a Destroyable flag indefinitely.

void main()
{
object oStaff = GetItemActivated();
int nCharges = GetItemCharges(oStaff);
int nChargePerUse = 2;
if (nCharges < nChargePerUse)
{
AssignCommand(oStaff,SetIsDestroyable(FALSE));
DelayCommand(0.5, AssignCommand(oStaff, SetIsDestroyable(TRUE)));
if(!nCharges) SetItemCharges(oStaff, 1);
}


I already tried that.  The Item is still destroyed.     It get destroyed before the assigned command can take effect.   Or at least it did in my test.

Make sure you are testing on an item that does not already have the flag set.



In Retesting you version worked where mine with a shorter delay did not.   So I wonder if there my be problems in modules that have more scripts firing with the Flag getting removed before the Destruction event occures.
               
               

               


                     Modifié par Lightfoot8, 08 janvier 2013 - 07:00 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Problem With Recharging Staves
« Reply #29 on: January 08, 2013, 07:08:03 am »


               Does this look better?  Removes two uses and does not require resting, nor chances the indestructible flag.

void main()
{
object oStaff = GetItemActivated();
int nCharges = GetItemCharges(oStaff);
int nChargePerUse = 2;
if (nCharges < 2 * nChargePerUse)
  {
SetItemCharges(oStaff, nCharges + nChargePerUse);
  SendMessageToPC(GetItemActivator(), "You need at least thrice the number of charges to use this ability.");
return;
}

EDIT: script works fine and is at minimum for preventing destruction, just it sacrifices two uses rather than just one.
               
               

               


                     Modifié par WhiZard, 08 janvier 2013 - 07:30 .