Go Back   RunUO - Ultima Online Emulation > RunUO > Script Support

Script Support Get support for modifying RunUO Scripts, or writing your own!

Reply
 
Thread Tools Display Modes
Old 04-07-2005, 04:58 AM   #1 (permalink)
 
Join Date: Apr 2005
Location: Illinois
Age: 31
Posts: 167
Default Need help with amount of item.....

I am making a noob quest for my shard and I would like them to kill monsters to get worms. I want them to have to gather 10 worms to put in a jar and bring to the fisherman npc. The npc gives them a jar in which to gather the worms, I made the jar so that if you double-click on it, it deletes the worms and you have a full jar of worms. My problem is I can only get the code to work with one worm, how do I write in that they need 10 worms to be deleted to get the full jar? Here is my code:
Code:
using System;
using Server;
using Server.Gumps;
using Server.Network;
using System.Collections;
using Server.Multis;
using Server.Mobiles;


namespace Server.Items
{

	public class WormJarEmpty : Item
	{
		[Constructable]
		public WormJarEmpty() : this( null )
		{
		}

		[Constructable]
		public WormJarEmpty ( string name ) : base ( 0x1005 )
		{
			Name = "Bait Jar (It's Empty)";
			Hue = 1113;
		}

		public WormJarEmpty ( Serial serial ) : base ( serial )
		{
		}

      		
		public override void OnDoubleClick( Mobile m )

		{
			Item a = m.Backpack.FindItemByType( typeof( Worm ) );
			if ( a != null )
			{
				m.AddToBackpack( new WormJarFull() );
				a.Delete();
				this.Delete();
			}
			else
			{
				m.SendMessage( "You need more worms..." );
		}
		}
		
		
		
		public override void Serialize ( GenericWriter writer)
		{
			base.Serialize ( writer );

			writer.Write ( (int) 0);
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize ( reader );

			int version = reader.ReadInt();
		}
	}
}
I would appreciate any help I can get on this. I do not take full credit for this code...it is a modified version of the jewelry box from Arriana's Heirloom Quest.

Thanks
blue77 is offline   Reply With Quote
Old 04-07-2005, 05:09 AM   #2 (permalink)
Master of the Internet
 
Join Date: Aug 2003
Posts: 5,688
Default

you need to add an integer variable to your WormJarEmpty class that will keep track of the number of worms. Then whenever you double click and find the item, increment the variable. When the value reaches 10, do your full jar thing. You will also need to Serialize and Deserialize your new variable so that it is saved across server restarts.
__________________
The first line of the first rule in the forum rules and guidelines "Be respectful of others. "

For questions, information, and support for XmlSpawner and its addons, visit the
XmlSpawner Support Forum
ArteGordon is offline   Reply With Quote
Old 04-07-2005, 05:20 AM   #3 (permalink)
 
Join Date: Apr 2005
Location: Illinois
Age: 31
Posts: 167
Default

Well, I am a noob scriptor and I love your idea more than my own but I'm not even sure I would know where to begin with that. I thought it would be easier to make it so the player has to have 10 worms in their bag for the jar to work? Is that not possible? or can you direct me to a script in RunUO that does the variable thing? I would love that! My brain is fried! In the mean time, I will keep searching. Thank you so much for your quick reply.
blue77 is offline   Reply With Quote
Old 04-07-2005, 05:34 AM   #4 (permalink)
Master of the Internet
 
Join Date: Aug 2003
Posts: 5,688
Default

you could require them to have 10 worms in their pack by just changing the search from FindItemByType to FindItemsByType which returns an Item array (look in the docs for details), then you can just test the length of the array instead of testing for a != null

Item [] a = m.Backpack.FindItemsByType( typeof( Worm ) );

if(a != null && a.Length >= 10)

(edit)

note, that you will have to loop through the array to delete all of the individual worms.

For a simple example of adding an integer property and serializing/deserializing it take a look at something like scripts/misc/bankcheck.cs.
__________________
The first line of the first rule in the forum rules and guidelines "Be respectful of others. "

For questions, information, and support for XmlSpawner and its addons, visit the
XmlSpawner Support Forum
ArteGordon is offline   Reply With Quote
Old 04-07-2005, 05:44 AM   #5 (permalink)
 
Join Date: Apr 2005
Location: Illinois
Age: 31
Posts: 167
Default

Thanks alot! Will do! Of course I will post again if I have problems 8( Hopefully this solves it. Thanks again!
blue77 is offline   Reply With Quote
Old 04-07-2005, 06:03 AM   #6 (permalink)
 
Join Date: Dec 2003
Location: Ohio
Posts: 561
Send a message via AIM to Rift Send a message via MSN to Rift Send a message via Yahoo to Rift
Default

okay my question is this is the worms in the pack stackable if they are on doubleclick of the jar it may be possible to find item in pack check see if amount = 10 create fulljar delete worms delete old jar if not (else) not enough worms
if not stackable then have do basically an arraylist of items in pack then do count of worm entries in arraylist if 10 then do your new jar del old jar then delete each worm in pack (this is just idea not code) but be easier to do a varible to jar if not stackable that increases on doubleclick but I think drag and drop be little better
Rift is offline   Reply With Quote
Old 04-07-2005, 11:08 AM   #7 (permalink)
Forum Expert
 
Join Date: Nov 2004
Posts: 1,656
Send a message via ICQ to Murzin Send a message via AIM to Murzin Send a message via MSN to Murzin
Default

post the script for the npc that will accept the worms and ill help you out.

otherwise its much harder and much more effort to show you how to do it without a point of reference
Murzin is offline   Reply With Quote
Old 04-07-2005, 02:52 PM   #8 (permalink)
 
Join Date: Apr 2005
Location: Illinois
Age: 31
Posts: 167
Default

the npc accepts the full jar, not the worms. The script to make the jar is at the top of the post. It starts as an empty jar and supposed to be a full jar on double click providing the player has 10 worms in their pack. It got late last night so I am still trying out ArteGordon's suggestion with the bank check. The worms are made from a brown hued silver necklace and no they are not stackable.

I really don't know what to do with this, this kills me because this is supposed to be a noob quest. It is a simple quest. I made a really long drawn out quest with an npc that kills you at the end of it and I can't seem to make a noob need 10 worms HAHAHA! *frustration sets in*
blue77 is offline   Reply With Quote
Old 04-08-2005, 03:29 PM   #9 (permalink)
 
Join Date: Apr 2005
Location: Illinois
Age: 31
Posts: 167
Default

Can someone tell me if I am at least on the right track here? I have been working on these damn worms for almost 2 days now

Code:
using System;
using Server;
using Server.Gumps;
using Server.Network;
using System.Collections;
using Server.Multis;
using Server.Mobiles;


namespace Server.Items
{

	public class WormJarEmpty : Item
	{
		[Constructable]
		public WormJarEmpty() : this( null )
		{
		}

		[Constructable]
		public WormJarEmpty ( string name ) : base ( 0x1005 )
		{
			Name = "Bait Jar (It's Empty)";
			Hue = 1113;
		}

		public WormJarEmpty ( Serial serial ) : base ( serial )
		{
		}

      		
		public override void OnDoubleClick( Mobile m )

		{
			Item [] a = m.Backpack.FindItemsByType( typeof( Worm ) );
				if ( Worm.Amount >= 10 )
				{
								

						Worm.Amount -= 10;

						if ( Worm.Amount == 0 )
						{
						Worm.Delete();
						m.AddToBackpack( new WormJarFull() );
									
						}
						else
						{
						return false;
						}
						}
						else
						{
						m.SendMessage( "This jar looks like it can fit 10 worms...." ); 
						return false;
		}
		}
		
		
		public override void Serialize ( GenericWriter writer)
		{
			base.Serialize ( writer );

			writer.Write ( (int) 0);
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize ( reader );

			int version = reader.ReadInt();
		}
	}
}
Any help would be appreciated.
blue77 is offline   Reply With Quote
Old 04-08-2005, 05:54 PM   #10 (permalink)
Master of the Internet
 
Join Date: Aug 2003
Posts: 5,688
Default

probably want something more like this

Code:
		public override void OnDoubleClick( Mobile m )

		{
			Item [] a = m.Backpack.FindItemsByType( typeof( Worm ) );

			// are there at least 10 elements in the returned array?
			if ( a!= null && a.Length >= 10)
			{
				// delete the first 10 of them
				for(i=0;i<10;i++) a[i].Delete();

				// and add the full jar of worms
				m.AddToBackpack( new WormJarFull() );
									
			}
			else
			{
				m.SendMessage( "This jar looks like it can fit 10 worms...." ); 
			}
		}
note, there are no return values because the method is a "void" type. Also, the results of the item search is returned in the "a" array. So that is what you test the length of, and that is what you go through to delete the worm items themselves (that are returned as elements of the array).
__________________
The first line of the first rule in the forum rules and guidelines "Be respectful of others. "

For questions, information, and support for XmlSpawner and its addons, visit the
XmlSpawner Support Forum
ArteGordon is offline   Reply With Quote
Old 04-08-2005, 07:15 PM   #11 (permalink)
 
Join Date: Apr 2005
Location: Illinois
Age: 31
Posts: 167
Default

ok, I have been messing with the code that you supplied for me, I am having a problem defining i in the code. Like I said I am new at this, items and things are easy but this I am having a hard time with because I have no C# background at all. I was hoping to complete this quest so that I could submit it to the boards to share with other shards. My other quests are custom to the shard so they would be useless to other shards. Do I define i in worm.cs or do I define it here? in this script? and how do I define it? I feel like such a moron
blue77 is offline   Reply With Quote
Old 04-08-2005, 08:39 PM   #12 (permalink)
Master of the Internet
 
Join Date: Aug 2003
Posts: 5,688
Default

sorry,it should have read

Code:
for(int i=0;i<10;i++) a[i].Delete();
(edit)

you could have defined i anywhere, but it is just convenient to do it within the for loop statement since it is only used within the scope of the loop.

for instance, this would have worked as well

Code:
int i;
for(i=0;i<10;i++) a[i].Delete();
but now you would have had an i variable that could be accessed outside of the for loop. A slight difference, that wouldnt matter in this context, but in general it is good practice to keep your variables limited to the scope in which they are going to be used.
__________________
The first line of the first rule in the forum rules and guidelines "Be respectful of others. "

For questions, information, and support for XmlSpawner and its addons, visit the
XmlSpawner Support Forum
ArteGordon is offline   Reply With Quote
Old 04-08-2005, 11:14 PM   #13 (permalink)
 
Join Date: Apr 2005
Location: Illinois
Age: 31
Posts: 167
Default

You are terrific! Thank you soooooo much! It works now and I am adding a few things and polishing it up! Thanks again for all your help and your patience!
blue77 is offline   Reply With Quote
Old 04-09-2005, 01:10 AM   #14 (permalink)
Forum Expert
 
Join Date: Nov 2004
Posts: 1,656
Send a message via ICQ to Murzin Send a message via AIM to Murzin Send a message via MSN to Murzin
Default

i wouldnt have put a limit on the number of worms.. i would have done it this way...

1) you have the empty jar.. set its name to like "a jar for worms" and add a property tag that shows the count.

2) on double click of the jar bring up a targeting cursor, and if the target is of type worm, delete the target, and increase the count on the jar by 1.

3) when you drop the jar on the npc, have it check the count flag on the jar, if its under 10, have it say there isnt enough worms on the jar, if it was 10 or more, subtract 10 from the count on the jar and give the reward.

would that have been an easier way?
Murzin is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5