|
||
|
|||||||
| Script Support Get support for modifying RunUO Scripts, or writing your own! |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Forum Expert
Join Date: Dec 2006
Posts: 456
|
Hey - how can I ask in an "if" statement whether a particular player is deleted or not.
I want to add all players that click a button on a gump to a list. so other players can check this list of all the players who have clicked this button. However, when the player clicks the "resign" button, or deletes their character, they must be removed from the list... any ideas ? regards
__________________
legendsofkaine.page.tl
|
|
|
|
|
|
#2 (permalink) |
|
Forum Expert
|
you would do something like this:
Code:
if ( from == null || from.Deleted ) m_List.Remove( from ); You are going to want to cycle through the list and perform this task on each mobile stored in the list before sending it to the gump so that the information displayed on the gump is correct. You would do that with something simular to the following: Code:
public override void OnDoubleClick( Mobile from )
{
CleanList();
from.SendGump(new ListGump( m_List ));
}
public void CleanList()
{
for ( int i = 0; i < m_List.Count; ++i )
{
Mobile from = m_List[i];
if ( from == null || from.Deleted )
m_List.Remove( from );
}
}
![]()
__________________
Father Time Life's journey is not to arrive at the grave safely in a well preserved body, but rather to skid in sideways, totally worn out, shouting "Holy Hell......What a ride!!!" Server: UO: Extinction ICQ: 146563794 FatherTime@UOExtinction.com UO: Extinction homepage UO: Extinction forum Last edited by vermillion2083; 08-06-2008 at 01:29 PM. |
|
|
|
|
|
#3 (permalink) |
|
Forum Expert
Join Date: Dec 2006
Posts: 456
|
Thanks man - you have been a great help as usual...
Let me explain my situation a bit more (I thought I could do this alone, but I tried, and it looks like I need a lot more help than I thought. I will get there some day) Thieves on my shard need to be in a guild I made (its not made with the standard guild system). when they dbl click a custom item (Guild Stone), a gump appears, and it has two buttons. Join Button: Code:
case 1:
{
if ( pm.ProfessionNumber == 10 )
{
pm.Umbarian = 1;
pm.SendMessage( 68, "You have joined the Umbarian Shadows Thief Guild.");
pm.Backpack.DropItem( new UmbarianShadowsRobe() );
pm.AcceptGuildInvites = false;
}
:Code:
case 2:
{
int x = 1;
Container pack = pm.Backpack;
if (pack != null)
{
if (pack.ConsumeTotal(typeof(UmbarianShadowsRobe), x))
{
pm.SendMessage(68, "You have Resigned From The Umbarian Shadows Thief Guild.");
pm.AcceptGuildInvites = true;
pm.Umbarian = 0;
}
Can you perhaps give me some pointers on how to accomplish this, my scripting abilities have improved a lot since I joined the community, but I have never dealt with a project like this before ![]() Thanks for the help thus far m8 Regards
__________________
legendsofkaine.page.tl
Last edited by typhoonbot; 08-06-2008 at 02:01 PM. Reason: Spelling mistake |
|
|
|
|
|
#4 (permalink) |
|
Forum Expert
|
I would love to assist you in your project. The first thing I would suggest is storing this information in the “guild stone” itself. What I personally would do is inside the guild stone script add and serialize a List<Mobile>. This will be your “rooster” and help you organize the members of the guild.
Then what I would do is make it so when you double click the guild stone that it sends itself as a variable to the gump: Code:
From.SendGump(new TheivesGuildGump(this)); Code:
private TheivesGuildStone m_Stone; // change "TheivesGuildStone" to the name of the stone class
public TheivesGuildStoneGump( TheivesGuildStone Stone ) : base( 0, 0 )
{
m_Stone = Stone;
So, now we have the gump that is aware of the item that called it (being the guild stone) what we will want to do is in the guild stone make a method that will deal with new members joining. When making this method it is important to check to see if this person is already a member (since some people may accidentally double click the join button). So we will want to make a method that looks like this: Code:
public void AddMember( Mobile from )
{
if( m_List.Contains( from ) )
{
from.SendMessage("you are alreaady a member");
return;
}
if ( pm.ProfessionNumber == 10 )
{
m_List.Add( from );
pm.Umbarian = 1;
pm.SendMessage( 68, "You have joined the Umbarian Shadows Thief Guild.");
pm.Backpack.DropItem( new UmbarianShadowsRobe() );
pm.AcceptGuildInvites = false;
}
}
Code:
case 1:
{
m_Stone.AddMember( pm );
}
So now you have the join method working you need a resign method. It’s very similar to the method provided above, only in reverse. You want to make sure that the list contains the thief still, and if it does then resign them (by the way, your remove method is bad coding. I’m not trying to be judgmental at all, but it has several big issues, such as if the person doesn’t have their shroud it won’t allow them to quit the guild; which you may have done intentionally). make sure to place this in the stone: Code:
public void RemoveMember( Mobile from )
{
if( m_List.Contains( from ) )
{
m_List.Remove( from );
pm.SendMessage(68, "You have Resigned From The Umbarian Shadows Thief Guild.");
pm.AcceptGuildInvites = true;
pm.Umbarian = 0;
}
else
from.SendMessage("You are not a member");
}
So, now all you need to do is make a gump that can list pages of members (like list 10 members, and if the list gets larger then you click the “next page” button to see the next ten. To learn how to do this I would suggest looking at gumps like the AdminGump.cs, this demonstrates this technique several times. Once you have learned this process all you need to do is cycle through the stones list and declare each entry as a mobile: Code:
Mobile m = m_Stone.List[i]; Code:
this.AddLabel( X , Y, HUE, m.RawName.ToString() ); Hopefully this is enough to get you started. Once you have this much going let me know if you run into more problems and I will be more than happy to assist you. p.s. I wrote this to accommodate what you already have, but if you are interested in starting over (which won’t take much effort at all) you can make this a completely independent script that requires no distribution edits, making for a easier, cleaner system. I personally always prefer doing this, so that if some day I decide I want to remove the system I just delete the core and it’s as if it never existed, as appose to having to go in an remove serializations from the playermobile, and editing other misc distros that were altered in the project. Also, Sorry if this was worded a little confusing and not 100% clear, I am at work and had to write this fast and off the top of my head, so I may have overlooked little tid bits of information, but if you come across something confusing we will clear it up for you! good luck with your project, its an ambitious one, the type I like best!!! ![]()
__________________
Father Time Life's journey is not to arrive at the grave safely in a well preserved body, but rather to skid in sideways, totally worn out, shouting "Holy Hell......What a ride!!!" Server: UO: Extinction ICQ: 146563794 FatherTime@UOExtinction.com UO: Extinction homepage UO: Extinction forum Last edited by vermillion2083; 08-06-2008 at 03:16 PM. |
|
|
|
|
|
#5 (permalink) |
|
Forum Expert
Join Date: Dec 2006
Posts: 456
|
Jeez - thank you so much, you have really put a lot of effort into this. its currently 21:20 over here, and I just have to quickly do summin in rl for about 10 mins. Then I will get started on my project. I really apprecate the help you have given me, I will post any stumbles I run into along the way
![]() regards
__________________
legendsofkaine.page.tl
|
|
|
|
|
|
#6 (permalink) | |
|
Forum Expert
|
Quote:
if you get hung up along the way just post your issue and I or someone else will help you as soon as possible.Again good luck with your project, I'm sure the end result will be a worthwhile one! ![]()
__________________
Father Time Life's journey is not to arrive at the grave safely in a well preserved body, but rather to skid in sideways, totally worn out, shouting "Holy Hell......What a ride!!!" Server: UO: Extinction ICQ: 146563794 FatherTime@UOExtinction.com UO: Extinction homepage UO: Extinction forum |
|
|
|
|
|
|
#7 (permalink) | |
|
Forum Expert
Join Date: Dec 2006
Posts: 456
|
Great. One thing I wasn't entirely sure what you mean was the List<Mobile> part.
I have looked at other scripts, and have tried this: Quote:
![]()
__________________
legendsofkaine.page.tl
|
|
|
|
|
|
|
#8 (permalink) |
|
Forum Expert
Join Date: Dec 2006
Posts: 456
|
Was just reading on in your earlier post, and you queried about the guild robe situation. That was done intentionally. the robe is a custom item, and blessed. It must be removed from them upon resigning the guild, otherwise they must not be allowed to resign
![]()
__________________
legendsofkaine.page.tl
|
|
|
|
|
|
#9 (permalink) |
|
Forum Expert
Join Date: Dec 2006
Posts: 456
|
Okay, no intention of bumping here, I have just updated the scripts, and I need you to show me what I'm doing wrong thus far.
this is how my UmbarianStone.cs looks: Code:
using Server;
using System;
using Server.Gumps;
using Server.Network;
using Server.Items;
using Server.Mobiles;
using Server.Accounting;
namespace Server.Items
{
public class UmbarianStone : Item
{
m_List = new List<Mobile>();
[Constructable]
public UmbarianStone()
: base(3796)
{
Movable = false;
Name = "Umbarian Shadows Stone";
}
public void AddMember( Mobile from )
{
if( m_List.Contains( from ) )
{
from.SendMessage(37, "You are already a member of the guild.");
return;
}
if ( pm.ProfessionNumber == 10 )
{
m_List.Add( from );
pm.Umbarian = 1;
pm.SendMessage( 68, "You have joined the Umbarian Shadows Thief Guild.");
pm.Backpack.DropItem( new UmbarianShadowsRobe() );
pm.AcceptGuildInvites = false;
}
}
public void RemoveMember( Mobile from )
{
if( m_List.Contains( from ) )
{
int x = 1;
Container pack = pm.Backpack;
if (pack != null)
{
if (pack.ConsumeTotal(typeof(UmbarianShadowsRobe), x))
{
m_List.Remove( from );
pm.SendMessage(68, "You have Resigned From The Umbarian Shadows Thief Guild.");
pm.AcceptGuildInvites = true;
pm.Umbarian = 0;
}
else
{
pm.SendMessage( 38, "Please place your Umbarian Shadows Guild Robe in your backpack, and try again.");
}
}
}
else
{
from.SendMessage("You are not a member");
}
}
public override void OnDoubleClick(Mobile from)
{
from.SendMessage( 1172, "Select your Choice...");
if (from.InRange(GetWorldLocation(), 3))
from.SendGump(new UmbarianGuildGump(this));
else
from.SendLocalizedMessage(500446); // That is too far away.
}
public UmbarianStone(Serial serial)
: base(serial)
{
}
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
}
}
}
Code:
using Server;
using System;
using Server.Gumps;
using Server.Commands;
using Server.Network;
using Server.Items;
using Server.Mobiles;
//
namespace Server.Gumps
{
public class UmbarianGuildGump : Gump
{
//New Edit
private UmbarianStone m_Stone;
//End
public UmbarianGuildGump()
: base(347, 216)
{
//New Edit
m_Stone = stone;
//End
this.Closable = true;
this.Disposable = false;
this.Dragable = true;
this.Resizable = false;
this.AddPage(0);
//
//BackGrounds
this.AddBackground(0, 0, 315, 150, 9250);
//Labels
this.AddLabel(94, 9, 3, @"Umbarian Shadows");
this.AddLabel(30, 63, 1168, @"Join Umbarian Shadows");
this.AddLabel(30, 108, 1168, @"Resign from Umbarian Shadows");
//Buttons
this.AddButton(230, 63, 247, 248, 1, GumpButtonType.Reply, 0);
this.AddButton(230, 108, 247, 248, 2, GumpButtonType.Reply, 0);
}
public override void OnResponse(NetState sender, RelayInfo info)
{
Mobile m = sender.Mobile;
PlayerMobile pm = (PlayerMobile)m;
switch (info.ButtonID)
{
case 0:
{
pm.SendMessage( 68, "You choose not to join the Umbarian Shadows");
return;
}
case 1:
{
m_Stone.AddMember( pm );
break;
}
case 2:
{
m_Stone.RemoveMember( pm );
break;
}
}
}
}
}
Compiling those two scripts gives the following errors (mainly because of the List<Mobile>: Errors: + Custom/Umbarian Shadows System/UmbarianStone.cs: CS1519: Line 14: Invalid token '=' in class, struct, or interface member dec laration CS1519: Line 14: Invalid token '(' in class, struct, or interface member dec laration
__________________
legendsofkaine.page.tl
|
|
|
|
|
|
#12 (permalink) |
|
Forum Expert
Join Date: Dec 2006
Posts: 456
|
Thank you Joeku
![]() Okay, now another small problem, it tells me I'm missing a using directive for List, but I have never worked with Lists before - I have no idea which directive I'm missing ![]() Code:
using Server;
using System;
using Server.Gumps;
using Server.Network;
using Server.Items;
using Server.Mobiles;
using Server.Accounting;
namespace Server.Items
{
public class UmbarianStone : Item
{
List<Mobile> m_List = new List<Mobile>();
[Constructable]
public UmbarianStone()
: base(3796)
{
Movable = false;
Name = "Umbarian Shadows Stone";
}
Errors: + Custom/Umbarian Shadows System/UmbarianStone.cs: CS0246: Line 14: The type or namespace name 'List' could not be found (are y ou missing a using directive or an assembly reference?) Sorry, I'm usually not this noob with scripting at all, but this list thing is really all new to me ![]() Regards
__________________
legendsofkaine.page.tl
|
|
|
|
|
|
#15 (permalink) |
|
Forum Expert
|
i did something similar to this with my egate script...
what i ended up doing was creating a new data type that encased the name of the location, the map, and the coords into 1 data type. and the gump has a dynamically generated list of the locations with page checking and cycling when drawing the gump. probably be a good place to look. also, this new fad with all these small scripts all having tons of scripts and people rar/zip them is annoying to me. you can look at my system how i did it all inside 1 file and duplicate that for simplicity. |
|
|
|
|
|
#16 (permalink) | |
|
Forum Expert
|
Quote:
Hmm, although I see your ultimate goal here, I personally would go about this in a different way. I potentially see problems here. (for instance what if someone accidentally drops the robe to the ground and a griefer snatches it, they are stuck in the guild forever?) What I would do is use a dictionary instead of a list. I would use a dictionary like this: Code:
public static Dictionary<Mobile, Item> m_UmbarianRooster = new Dictionary<Mobile, Item>(); The reason I suggest doing it this way is when a person is deleted or resigns from the guild you can alter the RemovePlayer method to look for that person in the dictionary, and if they are a guild member look at the item stored in their key, if that item exist (wasn't deleted) delete the item, then remove the player. Thsi way it doesn't matter where that robe is (locked in their house, stolen by a griefer, blasted into space for angry monkies to find as relics 3000 years in the future) it will get deleted as soon as the person leaves the guild. It may sound intimidating but dictionaries are easy to work with once you get an understanding of them (which I can help you obtain). I will give you an example of how to serialize / deserialize this type of dictionary, as well as how to add a guild member and their robe to the dictionary. I will write something up now and post it in a few minutes. p.s. I haven't had a chance to review your stone yet, I will do that in a few seconds, But Im happy to see you working away at it! ![]()
__________________
Father Time Life's journey is not to arrive at the grave safely in a well preserved body, but rather to skid in sideways, totally worn out, shouting "Holy Hell......What a ride!!!" Server: UO: Extinction ICQ: 146563794 FatherTime@UOExtinction.com UO: Extinction homepage UO: Extinction forum |
|
|
|
|
|
|
#17 (permalink) |
|
Forum Expert
|
This create the dictionary itself. This dictionary stores a Mobile (the guild member) as the key, and an item (their robe) as the value.
Code:
public static Dictionary<Mobile, Item> m_UmbarianRooster = new Dictionary<Mobile, Item>(); Code:
public void AddGuildMember( Mobile from )
{
if( m_UmbarianRooster.ContainsKey( from ) )
{
from.SendMessage("you are alreaady a member");
return;
}
else
{
SpecialRobe robe = new SpecialRobe();
from.AddToPack( robe );
m_UmbarianRooster.Add( from, robe );
}
}
Code:
public void RemoveGuildMember( Mobile from )
{
if( m_UmbarianRooster.ContainsKey( from ) )
{
SpecialRobe robe = m_UmbarianRooster[from];
if( robe != null )
robe.Delete();
m_UmbarianRooster.Remove( from );
}
else
{
from.SendMessage("you are not currently a member");
return;
}
}
Code:
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 );
if( m_UmbarianRooster != null )
{
writer.Write( true );
writer.Write( m_UmbarianRooster.Count );
foreach( KeyValuePair<Mobile, Item> kvp in m_UmbarianRooster )
{
writer.Write( kvp.Key );
writer.Write( kvp.Value );
}
}
else
{
writer.Write( false );
}
}
Code:
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
switch( version )
{
case 0:
{
bool notNull = reader.ReadBool();
if( notNull )
{
int tableSize = reader.ReadInt();
for( int i = 0; i < tableSize; i++ )
{
Mobile m = reader.ReadMobile();
Item item = reader.ReadItem(); // This might be wrong, can't remember how to deserialize an item *grins* mental block!
m_UmbarianRooster.Add( m, item );
}
}
}
}
}
![]()
__________________
Father Time Life's journey is not to arrive at the grave safely in a well preserved body, but rather to skid in sideways, totally worn out, shouting "Holy Hell......What a ride!!!" Server: UO: Extinction ICQ: 146563794 FatherTime@UOExtinction.com UO: Extinction homepage UO: Extinction forum |
|
|
|
|
|
#18 (permalink) |
|
Forum Expert
|
There is only one thing I noticed about your code that personally I would change, but it's nothing major, just Aesthetic. I would change this:
Code:
public override void OnDoubleClick(Mobile from)
{
from.SendMessage( 1172, "Select your Choice...");
if (from.InRange(GetWorldLocation(), 3))
from.SendGump(new UmbarianGuildGump(this));
else
from.SendLocalizedMessage(500446); // That is too far away.
}
Code:
public override void OnDoubleClick(Mobile from)
{
if (from.InRange(GetWorldLocation(), 3))
{
from.SendMessage( 1172, "Select your Choice...");
from.SendGump(new UmbarianGuildGump(this));
}
else
from.SendLocalizedMessage(500446); // That is too far away.
}
![]()
__________________
Father Time Life's journey is not to arrive at the grave safely in a well preserved body, but rather to skid in sideways, totally worn out, shouting "Holy Hell......What a ride!!!" Server: UO: Extinction ICQ: 146563794 FatherTime@UOExtinction.com UO: Extinction homepage UO: Extinction forum |
|
|
|
|
|
#20 (permalink) |
|
Forum Expert
Join Date: Dec 2006
Posts: 456
|
Okay, I have read through all 3 posts.
First off, ello vermillion, I'm great - thanks for asking ![]() Secondly...Thanks so much for your replies, and effort. I think the dictionary will be really great to use in this context. Also I'm glad to have the oportunity to play around with dictionaries, as this is the first time I have ever heard of that term with regards to C#, and I LOVE learning new things O_0. Now down to business. I am about to go get another cup of coffee, and implement all the changes you have posted, in order to get this dictionary working. Also I am very glad you went through it in so much detail (explaining everything) because this is a very useful tool to use in many, many other projects I have been thinking about creating. I will let ya know how it goes, and post any problems I run into... Regards
__________________ |