RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Spawn Items in a SubPack?

D

Dupre

Guest
Spawn Items in a SubPack?

does anyone know how to do this?

I have a main Backpack, and in that is a bag called TokenBag.

i can make things spawn in the main backpack

m.AddToBackpack(new Tokens (500,60000));

but dont know how to get them into a subpack.

m is the reference to a player.
 

Nykovious

Wanderer
You can use something like:[code:1]foreach(Item item in Backpack.Items)
{
if(item is TokenBag)
{
item.AddItem( new Tokens(500,60000) );
}
}[/code:1]
And you'll need to make sure that they only have one TokenBag in there pack or that only one set of tokens is added, so that a player dosen't run around with 10 TokenBags and getting 10 times his due.
 
D

Dupre

Guest
i replaced my line with that function, as far as i can see, it doesnt reference a player.

Scripts: Compiling C# scripts...failed (1 errors, 1 warnings)
- Warning: Scripts\Engines\AI\Creature\BaseCreature.cs: CS0184: (line 3238, col
umn 7) The given expression is never of the provided ('Server.Mobiles.PlayerMobi
le') type
- Error: Scripts\Engines\AI\Creature\BaseCreature.cs: CS0120: (line 3458, colum
n 22) An object reference is required for the nonstatic field, method, or proper
ty 'Server.Mobile.Backpack'
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.
 

Nykovious

Wanderer
Ooops...typo... :?
Try:[code:1]foreach(Item item in m.Backpack.Items)
{
if(item is TokenBag)
{
item.AddItem( new Tokens(500,60000) );
}
}[/code:1]
 

juani

Wanderer
im just a nubi scripter and this is just an idea... but who knows :)

this is how they put stuff in your bank (CharacterCreation.sc), they do it in containers too... maybe reading this u can get an idea on how to do it:




[code:1]
private static void FillBankAOS( Mobile m )
{
BankBox bank = m.BankBox;

if ( bank == null )
return;

// The new AOS bankboxes don't have powerscrolls, they are automatically 'applied':

for ( int i = 0; i < PowerScroll.Skills.Length; ++i )
m.Skills[PowerScroll.Skills].Cap = 120.0;

m.StatCap = 250;


Container cont;


// Begin box of money
cont = new WoodenBox();
cont.ItemID = 0xE7D;
cont.Hue = 0x489;

PlaceItemIn( cont, 16, 51, new BankCheck( 500000 ) );
PlaceItemIn( cont, 28, 51, new BankCheck( 250000 ) );
PlaceItemIn( cont, 40, 51, new BankCheck( 100000 ) );
PlaceItemIn( cont, 52, 51, new BankCheck( 100000 ) );
PlaceItemIn( cont, 64, 51, new BankCheck( 50000 ) );

PlaceItemIn( cont, 34, 115, MakeNewbie( new Gold( 60000 ) ) );

PlaceItemIn( bank, 18, 169, cont );
// End box of money


// Begin bag of potion kegs
cont = new Backpack();
cont.Name = "Various Potion Kegs";

PlaceItemIn( cont, 45, 149, MakePotionKeg( PotionEffect.CureGreater, 0x2D ) );
PlaceItemIn( cont, 69, 149, MakePotionKeg( PotionEffect.HealGreater, 0x499 ) );
PlaceItemIn( cont, 93, 149, MakePotionKeg( PotionEffect.PoisonDeadly, 0x46 ) );
PlaceItemIn( cont, 117, 149, MakePotionKeg( PotionEffect.RefreshTotal, 0x21 ) );
PlaceItemIn( cont, 141, 149, MakePotionKeg( PotionEffect.ExplosionGreater, 0x74 ) );

PlaceItemIn( cont, 93, 82, MakeNewbie( new Bottle( 1000 ) ) );

PlaceItemIn( bank, 53, 169, cont );
// End bag of potion kegs


// Begin bag of tools
cont = new Bag();
cont.Name = "Tool Bag";

PlaceItemIn( cont, 30, 35, MakeNewbie( new TinkerTools( 1000 ) ) );
PlaceItemIn( cont, 60, 35, new HousePlacementTool() );
PlaceItemIn( cont, 90, 35, MakeNewbie( new DovetailSaw( 1000 ) ) );
PlaceItemIn( cont, 30, 68, MakeNewbie( new Scissors() ) );
PlaceItemIn( cont, 45, 68, MakeNewbie( new MortarPestle( 1000 ) ) );
PlaceItemIn( cont, 75, 68, MakeNewbie( new ScribesPen( 1000 ) ) );
PlaceItemIn( cont, 90, 68, MakeNewbie( new SmithHammer( 1000 ) ) );
PlaceItemIn( cont, 30, 118, MakeNewbie( new TwoHandedAxe() ) );
PlaceItemIn( cont, 60, 118, MakeNewbie( new FletcherTools( 1000 ) ) );
PlaceItemIn( cont, 90, 118, MakeNewbie( new SewingKit( 1000 ) ) );

PlaceItemIn( bank, 118, 169, cont );
// End bag of tools


// Begin bag of archery ammo
cont = new Bag();
cont.Name = "Bag Of Archery Ammo";

PlaceItemIn( cont, 48, 76, MakeNewbie( new Arrow( 5000 ) ) );
PlaceItemIn( cont, 72, 76, MakeNewbie( new Bolt( 5000 ) ) );

PlaceItemIn( bank, 118, 124, cont );
// End bag of archery ammo


// Begin bag of treasure maps
cont = new Bag();
cont.Name = "Bag Of Treasure Maps";

PlaceItemIn( cont, 30, 35, MakeNewbie( new TreasureMap( 1, Map.Trammel ) ) );
PlaceItemIn( cont, 45, 35, MakeNewbie( new TreasureMap( 2, Map.Trammel ) ) );
PlaceItemIn( cont, 60, 35, MakeNewbie( new TreasureMap( 3, Map.Trammel ) ) );
PlaceItemIn( cont, 75, 35, MakeNewbie( new TreasureMap( 4, Map.Trammel ) ) );
PlaceItemIn( cont, 90, 35, MakeNewbie( new TreasureMap( 5, Map.Trammel ) ) );

PlaceItemIn( cont, 30, 50, MakeNewbie( new TreasureMap( 1, Map.Trammel ) ) );
PlaceItemIn( cont, 45, 50, MakeNewbie( new TreasureMap( 2, Map.Trammel ) ) );
PlaceItemIn( cont, 60, 50, MakeNewbie( new TreasureMap( 3, Map.Trammel ) ) );
PlaceItemIn( cont, 75, 50, MakeNewbie( new TreasureMap( 4, Map.Trammel ) ) );
PlaceItemIn( cont, 90, 50, MakeNewbie( new TreasureMap( 5, Map.Trammel ) ) );

PlaceItemIn( cont, 55, 100, MakeNewbie( new Lockpick( 30 ) ) );
PlaceItemIn( cont, 60, 100, MakeNewbie( new Pickaxe() ) );

PlaceItemIn( bank, 98, 124, cont );
// End bag of treasure maps


// Begin bag of raw materials
cont = new Bag();
cont.Hue = 0x835;
cont.Name = "Raw Materials Bag";

PlaceItemIn( cont, 92, 60, MakeNewbie( new BarbedLeather( 5000 ) ) );
PlaceItemIn( cont, 92, 68, MakeNewbie( new HornedLeather( 5000 ) ) );
PlaceItemIn( cont, 92, 76, MakeNewbie( new SpinedLeather( 5000 ) ) );
PlaceItemIn( cont, 92, 84, MakeNewbie( new Leather( 5000 ) ) );

PlaceItemIn( cont, 30, 118, MakeNewbie( new Cloth( 5000 ) ) );
PlaceItemIn( cont, 30, 84, MakeNewbie( new Board( 5000 ) ) );
PlaceItemIn( cont, 57, 80, MakeNewbie( new BlankScroll( 500 ) ) );

PlaceItemIn( cont, 30, 35, MakeNewbie( new DullCopperIngot( 5000 ) ) );
PlaceItemIn( cont, 37, 35, MakeNewbie( new ShadowIronIngot( 5000 ) ) );
PlaceItemIn( cont, 44, 35, MakeNewbie( new CopperIngot( 5000 ) ) );
PlaceItemIn( cont, 51, 35, MakeNewbie( new BronzeIngot( 5000 ) ) );
PlaceItemIn( cont, 58, 35, MakeNewbie( new GoldIngot( 5000 ) ) );
PlaceItemIn( cont, 65, 35, MakeNewbie( new AgapiteIngot( 5000 ) ) );
PlaceItemIn( cont, 72, 35, MakeNewbie( new VeriteIngot( 5000 ) ) );
PlaceItemIn( cont, 79, 35, MakeNewbie( new ValoriteIngot( 5000 ) ) );
PlaceItemIn( cont, 86, 35, MakeNewbie( new IronIngot( 5000 ) ) );

PlaceItemIn( cont, 30, 59, MakeNewbie( new RedScales( 5000 ) ) );
PlaceItemIn( cont, 36, 59, MakeNewbie( new YellowScales( 5000 ) ) );
PlaceItemIn( cont, 42, 59, MakeNewbie( new BlackScales( 5000 ) ) );
PlaceItemIn( cont, 48, 59, MakeNewbie( new GreenScales( 5000 ) ) );
PlaceItemIn( cont, 54, 59, MakeNewbie( new WhiteScales( 5000 ) ) );
PlaceItemIn( cont, 60, 59, MakeNewbie( new BlueScales( 5000 ) ) );

PlaceItemIn( bank, 98, 169, cont );
// End bag of raw materials


// Begin bag of spell casting stuff
cont = new Backpack();
cont.Hue = 0x480;
cont.Name = "Spell Casting Stuff";

PlaceItemIn( cont, 45, 105, new Spellbook( UInt64.MaxValue ) );
PlaceItemIn( cont, 65, 105, new NecromancerSpellbook( (UInt64)0xFFFF ) );
PlaceItemIn( cont, 85, 105, new BookOfChivalry( (UInt64)0x3FF ) );

Runebook runebook = new Runebook( 10 );
runebook.CurCharges = runebook.MaxCharges;
PlaceItemIn( cont, 105, 105, runebook );

Item toHue = new BagOfReagents( 150 );
toHue.Hue = 0x2D;
PlaceItemIn( cont, 45, 150, toHue );

toHue = new BagOfNecroReagents( 150 );
toHue.Hue = 0x488;
PlaceItemIn( cont, 65, 150, toHue );

PlaceItemIn( cont, 140, 150, new BagOfAllReagents( 500 ) );

for ( int i = 0; i < 9; ++i )
PlaceItemIn( cont, 45 + (i * 10), 75, MakeNewbie( new RecallRune() ) );

PlaceItemIn( bank, 78, 169, cont );
// End bag of spell casting stuff
}
[/code:1]
 
D

Dupre

Guest
I did look through that script because of the subpack options, but it doesnt work in the same way as a pre-made bag, the newcharacter script works by creating a bag, then populating it in the same function.
 

juani

Wanderer
oh! i understand, u want to add tokens to a token bag players already have in their pack, a sort of auto-sorting for tokens!

sorry, i thought u just wanted to create subpacks :)
 
D

Dupre

Guest
i got that down pretty early :-D But found it hard to get stuff to appear in a subpack that already existed. Now i got it down to a T, thanks to Nykovious.

Because tokens can spawn from 0 to 60k piles, it ends up clogging up backpacks.
 

Kamron

Knight
[code:1]Container pack = m.Backpack; //reference backpack

Container bag = pack.FindItemByType( typeof(Container), true ) as Container; //Try to find a container, the first one found, set it to the variable bag.

if (bag != null) // We found a bag
{
bag.DropItem( new Tokens(500,60000) ); // drop some tokens in the bag we found
}[/code:1]
 
Just a real quick mod which will add a TokenBag if they don't already have one:

[code:1]Container pack = m.Backpack;

TokenBag bag = pack.FindItemByType( typeof( TokenBag ), true ) as TokenBag;

if (bag == null)
{
bag = new TokenBag;
pack.DropItem( bag );
}

bag.DropItem( new Tokens( 500, 60000 ) );[/code:1]

Cheers,
Ignacio
 
Top