Aller au contenu

Photo

Problem With Recharging Staves


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

#1
Sadira of Tyr

Sadira of Tyr
  • Members
  • 172 messages
I made some magical staves, and I gave them each a unique power, to help make caster classes better. Because the staves are rather pricy, I wanted to be sure they would not disappear when they ran out of charges. I set the charges to 49, and put the unique power at 2 charges per use. The problem is that when the staves are recharged with an item using the magical electrifier spell, the charges go back up to 50. Thus the staff could disappear when reaching zero charges.

Is there a way to prevent the charges from going above 49? Would setting the staves to plot fix this? I did not set the staves to plot, so that I could have them sold at a shop. However I could have the merchant set the staff to plot after purchase, or perhaps an on acquire script.

#2
Pearls

Pearls
  • Members
  • 106 messages
afaik you can use SetIsDestroyable on it or give it an activation that requires 0 charges

#3
Shadooow

Shadooow
  • Members
  • 4 465 messages

Sadira of Tyr wrote...

I made some magical staves, and I gave them each a unique power, to help make caster classes better. Because the staves are rather pricy, I wanted to be sure they would not disappear when they ran out of charges. I set the charges to 49, and put the unique power at 2 charges per use. The problem is that when the staves are recharged with an item using the magical electrifier spell, the charges go back up to 50. Thus the staff could disappear when reaching zero charges.

Is there a way to prevent the charges from going above 49? Would setting the staves to plot fix this? I did not set the staves to plot, so that I could have them sold at a shop. However I could have the merchant set the staff to plot after purchase, or perhaps an on acquire script.

Except plot flag, you can download either my unfficial patch or The Kit's improved magical electrifier or adjust it on your own to check for variable determining maximum charges the item can have.

In CP the variable is called ELECTRIFIER_CHARGE_MAX, type of integer, so simply set it to 49 and the item will be recharged to 49 at max.

#4
Sadira of Tyr

Sadira of Tyr
  • Members
  • 172 messages
I will try the variable. That is easy enough for me to do. I can also give the staves a light spell for zero charges.

Thank you very much for helping me.  Posted Image

#5
Sadira of Tyr

Sadira of Tyr
  • Members
  • 172 messages
Well, I tried the variable on the staff, but the charges still went up to 50. I then tried it on the electrifier item with the same result.

#6
Shadooow

Shadooow
  • Members
  • 4 465 messages
This variable will work only with community patch and will modify the electrifier so recharging will be limited to value in this variable. Also forget to mention that this feature was added in one of the beta versions, its not in 1.70 initial release...
So you either dont have community patch 1.71beta or there is a bug in the code that prevent this to work.

as mentioned already, alternatively you can download The Krit's magic electrifier script on vault it has same feature though name of the variable differs.

or I can post you electrifier script from CP1.71b, then you need only to open the original scrip in toolset, paste and compile. Lmk if you want to try this approach.

#7
Sadira of Tyr

Sadira of Tyr
  • Members
  • 172 messages
Yeah, I misunderstood your post. Now that I read it again, it is more clear to me. I am not the server host, so adding the patch is not really an option for me. I have downloaded the Krits electrifier from the Vault, and I will try that. It has some features that make it much better.

Thanks for helping.  Posted Image

#8
Sadira of Tyr

Sadira of Tyr
  • Members
  • 172 messages
Well, I found a bug in the Krit's magical electrifier script. According to the script, the electrifier should not destroy plot or cursed items. However when I tested the script, my recharger item would post a message "failure invalid target", and then it would destroy the item anyways.

I fixed the problem by changing line 118 to 'else if' instead of just 'if'. Now the script works fine.

#9
Sadira of Tyr

Sadira of Tyr
  • Members
  • 172 messages
More strange bugs. I added the variable ELECTRIFIER_CHARGE_MAX to the staves, and set the integer to 49. When my character picks up a staff off the ground, the script works fine, and the charge does not go over 49. However when I buy the same staff from a shop, the charge goes up to 50. Either the staves are losing the variable, or the electrifier script is not reading them correctly.

The same problem happens when I save my character. She picked up a staff off the ground, and used a few charges. After using the recharger item, the staff went back up to 49 charges. So far everything is working fine. However when I save the character, and start a new game with the same character, the staff charghes up to 50. The recharger item also loses any charges it has after saving as well.

I'm not sure if the problem is with the electrifier script no longer seeing the variables, or are the items losing the variables. Does the script from the community patch fix these bugs, or is it the same as the Krit's script?

#10
Shadooow

Shadooow
  • Members
  • 4 465 messages

Sadira of Tyr wrote...

More strange bugs. I added the variable ELECTRIFIER_CHARGE_MAX to the staves, and set the integer to 49. When my character picks up a staff off the ground, the script works fine, and the charge does not go over 49. However when I buy the same staff from a shop, the charge goes up to 50. Either the staves are losing the variable, or the electrifier script is not reading them correctly.

The same problem happens when I save my character. She picked up a staff off the ground, and used a few charges. After using the recharger item, the staff went back up to 49 charges. So far everything is working fine. However when I save the character, and start a new game with the same character, the staff charghes up to 50. The recharger item also loses any charges it has after saving as well.

I'm not sure if the problem is with the electrifier script no longer seeing the variables, or are the items losing the variables. Does the script from the community patch fix these bugs, or is it the same as the Krit's script?

In case the item in the store is marked as infinity, such item loses any variables when bought

thats why the The Krit's script doesn't work, neither the one in CP will solve this as it also rely on variables on items

seems the second case is also causing lost of variables, so thats it

it could be possible to fix it using a part of the item tag...

#11
Sadira of Tyr

Sadira of Tyr
  • Members
  • 172 messages
Oh well, I guess I will just set the staves to 50 charges, and have the unique power take 3 charges per use. It will mean 8 less charges, but there will not be a risk of losing the staff. I will still use the Krit's script though, since I like the features it has. 

Sorry, for the trouble guys, and thank you for helping. Posted Image

#12
Shadooow

Shadooow
  • Members
  • 4 465 messages
I don't exactly know what you need, but if the main intent is not to lose the staff, then you can set the staff to be plot.

Either directly, or using special script when you first use the staff. Of course if you would like to be able to sell it later than this isn't very good solution.

Other way around this is to give into this staff an unlimited uses spell such as light, problem is this isn't reliable, you might need to swap "position" of this property aka, if adding this property wont prevent item being destroyed, then try remove all cast properties except the unlimited and add them back again, then it should work.

#13
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

Pearls wrote...

afaik you can use SetIsDestroyable on it or give it an activation that requires 0 charges


As Pearls said,  SetIsDestroyable is a better option if you want to be able to sell the staff.  

#14
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

Sadira of Tyr wrote...

I made some magical staves, and I gave them each a unique power, to help make caster classes better. Because the staves are rather pricy, I wanted to be sure they would not disappear when they ran out of charges. I set the charges to 49, and put the unique power at 2 charges per use. The problem is that when the staves are recharged with an item using the magical electrifier spell, the charges go back up to 50. Thus the staff could disappear when reaching zero charges.

Is there a way to prevent the charges from going above 49? Would setting the staves to plot fix this? I did not set the staves to plot, so that I could have them sold at a shop. However I could have the merchant set the staff to plot after purchase, or perhaps an on acquire script.


Lets look at this from the other side.   Since you gave your Staves a "unique power"  I will assume that the Item runs a custom script when used.   So would it not be eaiser to just modify that script then modifing the magical electrifier script that effects more items then just the staves?  

Just place some code into your "unique power" script that will make sure that the charges are always odd.   Something like. 

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

#15
Sadira of Tyr

Sadira of Tyr
  • Members
  • 172 messages

Lightfoot8 wrote...

Lets look at this from the other side.   Since you gave your Staves a "unique power"  I will assume that the Item runs a custom script when used.   So would it not be eaiser to just modify that script then modifing the magical electrifier script that effects more items then just the staves?  

Just place some code into your "unique power" script that will make sure that the charges are always odd.   Something like. 

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


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 Image

#16
Melkior_King

Melkior_King
  • Members
  • 135 messages
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. ;)

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


#17
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

Melkior_King wrote...
I hate unsolved problems. ;)


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 Image



#18
WhiZard

WhiZard
  • Members
  • 1 204 messages
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).

#19
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
ok,  Then use:

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

#20
Sadira of Tyr

Sadira of Tyr
  • Members
  • 172 messages
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 Image

#21
WhiZard

WhiZard
  • Members
  • 1 204 messages

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 .


#22
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

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 .


#23
WhiZard

WhiZard
  • Members
  • 1 204 messages

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.

#24
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

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.

#25
WhiZard

WhiZard
  • Members
  • 1 204 messages
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 .