Aller au contenu

Photo

SetItemCharges when zero?


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

#1
DragonTayl

DragonTayl
  • Members
  • 34 messages
 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...

#2
WhiZard

WhiZard
  • Members
  • 1 204 messages

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.

#3
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
Cool, That is good to know. I had been destroying the items and recreating them in order to get the charges back. lol...

#4
Shadooow

Shadooow
  • Members
  • 4 474 messages

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.

#5
WhiZard

WhiZard
  • Members
  • 1 204 messages

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 .


#6
Shadooow

Shadooow
  • Members
  • 4 474 messages

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 .


#7
WhiZard

WhiZard
  • Members
  • 1 204 messages

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.

#8
Shadooow

Shadooow
  • Members
  • 4 474 messages
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 .