Author Topic: SetItemCharges when zero?  (Read 391 times)

Legacy_DragonTayl

  • Newbie
  • *
  • Posts: 40
  • Karma: +0/-0
SetItemCharges when zero?
« on: December 12, 2011, 12:23:30 am »


                Back again, thanks for such amazing, rapid help the other day. My question this time is if I am attempting to set charges on-the-fly, it appears when an item has reached zero charges, you cannot increase the charges to 1? How do you recharge an item that has reached zero? 

Maybe I'm doing it wrong? I ran an item down to zero charges and while the recharge seemed to work before it got to zero, now it doesn't? 

I suppose I could set it to "unlimited charges" and script it's charges, but it's so darned *convenient* for the players to see the number of charges on the item in their quickbar...
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
SetItemCharges when zero?
« Reply #1 on: December 12, 2011, 12:28:49 am »


               

DragonTayl wrote...

 Back again, thanks for such amazing, rapid help the other day. My question this time is if I am attempting to set charges on-the-fly, it appears when an item has reached zero charges, you cannot increase the charges to 1? How do you recharge an item that has reached zero? 

Maybe I'm doing it wrong? I ran an item down to zero charges and while the recharge seemed to work before it got to zero, now it doesn't? 

I suppose I could set it to "unlimited charges" and script it's charges, but it's so darned *convenient* for the players to see the number of charges on the item in their quickbar...


You can set charges when at 0, you just can't use them until you rest.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
SetItemCharges when zero?
« Reply #2 on: December 12, 2011, 01:46:09 am »


               Cool,  That is good to know.  I had been destroying the items and recreating them in order to get the charges back.   lol...
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
SetItemCharges when zero?
« Reply #3 on: December 12, 2011, 05:58:48 am »


               

Lightfoot8 wrote...

Cool,  That is good to know.  I had been destroying the items and recreating them in order to get the charges back.   lol...

Re-adding the itemproperty with cast spell/charge does work much better than resting.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
SetItemCharges when zero?
« Reply #4 on: December 12, 2011, 06:44:47 am »


               

ShaDoOoW wrote...

Lightfoot8 wrote...

Cool,  That is good to know.  I had been destroying the items and recreating them in order to get the charges back.   lol...

Re-adding the itemproperty with cast spell/charge does work much better than resting.


Perhaps, but it can mess up the item property order which if the object is non-plot could cause its later destruction.  Also in-game, you can rest, but  you won't necessarily have access to scripts to reset the charges for you if there is a bug.  But yes, you can get a working model by stripping all item properties and adding them back sequentially.
               
               

               


                     Modifié par WhiZard, 12 décembre 2011 - 06:45 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
SetItemCharges when zero?
« Reply #5 on: December 12, 2011, 08:12:23 am »


               

WhiZard wrote...

ShaDoOoW wrote...

Lightfoot8 wrote...

Cool,  That is good to know.  I had been destroying the items and recreating them in order to get the charges back.   lol...

Re-adding the itemproperty with cast spell/charge does work much better than resting.


Perhaps, but it can mess up the item property order which if the object is non-plot could cause its later destruction.  Also in-game, you can rest, but  you won't necessarily have access to scripts to reset the charges for you if there is a bug.  But yes, you can get a working model by stripping all item properties and adding them back sequentially.

this isnt general but scripting forum, none of your points is valid in scripting terms, not mention that player might not have to be able to rest in some scenarios - anyway what player might or might not is not relevant in scripting forum - scripter can make it work via script without any issues - thats imo better than relying on player resting
               
               

               


                     Modifié par ShaDoOoW, 12 décembre 2011 - 08:14 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
SetItemCharges when zero?
« Reply #6 on: December 12, 2011, 08:55:29 pm »


               

ShaDoOoW wrote...
this isnt general but scripting forum, none of your points is valid in scripting terms, not mention that player might not have to be able to rest in some scenarios - anyway what player might or might not is not relevant in scripting forum - scripter can make it work via script without any issues - thats imo better than relying on player resting


I assume that you didn't understand a thing I said by this response.  Order for cast spell properties on a non-plot item matter when it comes to item destruction.  Take the staff of the magi for example  when you use up the charges on it the staff will not be destroyed.   Let's say I then set the charges to fifty and remove and regive the lightning bolt, invisibility, and ice storm cast spell properties.  Now the item functionally acts the same as before, but when I use up the charges again the item is destroyed.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
SetItemCharges when zero?
« Reply #7 on: December 13, 2011, 08:04:14 am »


               Jezuz man, talking with you is sometimes very hard, please dont be so bound to whats written on wiki and use more an imagination. I really sometimes don't know what are you trying to prove.

-> Yes I understood what you meant, afterall I read your research on wiki about cast spell order and item destruction and you are correct in that engine behavior and btw good job.

But as a scripter you have a full control over itemproperties. You not only can re-add them to fix the 0 charges issue, you can even controll their order. Now that thanks to you we know about this issue we can workaround it.

This function update item charges on item without need to player to rest to update cast spell itemproperties and without changing the cast spell item properties order.

void UpdateItemCharges(object oItem, int nCharges)
{
int charges = GetItemCharges(oItem);
SetItemCharges(oItem,nCharges);
 if(charges > 0)
 return;
itemproperty ip = GetFirstItemProperty(oItem);
float fDelay = 0.0;
 while(GetIsItemPropertyValid(ip))
 {
  if(GetItemPropertyType(ip) == ITEM_PROPERTY_CAST_SPELL)
  {
  RemoveItemProperty(oItem,ip);
  DelayCommand(fDelay,AddItemProperty(DURATION_TYPE_PERMANENT,ip,oItem));
  fDelay+=0.01;
  }
 ip = GetNextItemProperty(oItem);
 }
}

Easy and friendly on users end.
               
               

               


                     Modifié par ShaDoOoW, 13 décembre 2011 - 11:07 .