I'm making a storage box for granite and I've added a button to drop 10 pieces of granite out of the box in one click. I thought
m_From.AddToBackpack( new DullCopperGranite(10) );
would do it, but since granite's not stackable it just doesn't add anything to my pack.
I do have it working but I was wondering what the "proper" way to do it is, because I'm sure THIS isn't it... (searching on RunUO totally didn't help and I can't think of any example scripts that already do this if the item's not stackable :/)
...
CODE |
if ( info.ButtonID == 12 ) { if ( m_Box.DullCopper > 9 ) { m_Box.DullCopper = ( m_Box.DullCopper - 10 ); m_From.AddToBackpack( new DullCopperGranite() ); m_From.AddToBackpack( new DullCopperGranite() ); m_From.AddToBackpack( new DullCopperGranite() ); m_From.AddToBackpack( new DullCopperGranite() ); m_From.AddToBackpack( new DullCopperGranite() ); m_From.AddToBackpack( new DullCopperGranite() ); m_From.AddToBackpack( new DullCopperGranite() ); m_From.AddToBackpack( new DullCopperGranite() ); m_From.AddToBackpack( new DullCopperGranite() ); m_From.AddToBackpack( new DullCopperGranite() ); m_From.SendGump( new GraniteBoxGump( m_From, m_Box ) ); }
|
...
*grins*
Thanks Arte, that looks rather better! It's all the algebra stuff that sometimes puts me off a bit, I'm not at all mathsy... guess I should start trying to get my head around it all.
Cheers
that loop will simultaneously count out 10 things, and will decrement your DullCopper counter, and will stop when it gets to zero if there are fewer than 10 items to be handed out.
Thanks again Arte - just tested and it works even better than I thought. If I've got less than 10 bits of granite in there and click the drop 10 button it just goes till there aren't any left instead of dropping all 10. (Obviously, but I didn't think of that till I saw it, hehe.). So you've busted a real issue for me there as well as just satisfying my obsessive compulsiveness. Thanks
right. That's what this combined test does
i< 10 && m_Box.DullCopper > 0
It says, keep going as long as the counter hasnt reached 10 yet and there is still copper in the box.