|
||
|
|||||||
| Script Support Get support for modifying RunUO Scripts, or writing your own! |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Join Date: Apr 2005
Location: Illinois
Age: 31
Posts: 167
|
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();
}
}
}
Thanks |
|
|
|
|
|
#2 (permalink) |
|
Master of the Internet
Join Date: Aug 2003
Posts: 5,688
|
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 |
|
|
|
|
|
#3 (permalink) |
|
Join Date: Apr 2005
Location: Illinois
Age: 31
Posts: 167
|
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.
|
|
|
|
|
|
#4 (permalink) |
|
Master of the Internet
Join Date: Aug 2003
Posts: 5,688
|
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 |
|
|
|
|
|
#6 (permalink) |
|
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 |
|
|
|
|
|
|
#8 (permalink) |
|
Join Date: Apr 2005
Location: Illinois
Age: 31
Posts: 167
|
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* |
|
|
|
|
|
#9 (permalink) |
|
Join Date: Apr 2005
Location: Illinois
Age: 31
Posts: 167
|
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. |
|
|
|
|
|
#10 (permalink) |
|
Master of the Internet
Join Date: Aug 2003
Posts: 5,688
|
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...." );
}
}
__________________
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 |
|
|
|
|
|
#11 (permalink) |
|
Join Date: Apr 2005
Location: Illinois
Age: 31
Posts: 167
|
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
![]() |
|
|
|
|
|
#12 (permalink) |
|
Master of the Internet
Join Date: Aug 2003
Posts: 5,688
|
sorry,it should have read
Code:
for(int i=0;i<10;i++) a[i].Delete(); 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();
__________________
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 |
|
|
|
|
|
#14 (permalink) |
|
Forum Expert
|
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? |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|