Full Version : AddToBackpack question
xmlspawner >>Scripting Support >>AddToBackpack question
<< Prev | Next >>
Zyle- 01-31-2006
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*
ArteGordon- 01-31-2006
you could just loop it

CODE
if ( info.ButtonID == 12 ) { for(int i = 0; i< 10 && m_Box.DullCopper > 0; i++, m_Box.DullCopper--) { m_From.AddToBackpack( new DullCopperGranite() );
}
m_From.SendGump( new GraniteBoxGump( m_From, m_Box ) );

Zyle- 01-31-2006
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
ArteGordon- 01-31-2006
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.
Zyle- 01-31-2006
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
ArteGordon- 01-31-2006
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.
Zyle- 01-31-2006