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 07-09-2008, 12:50 PM   #1 (permalink)
Account Terminated
 
Join Date: Jul 2008
Age: 20
Posts: 26
Default Checking if items in backpack...

I want to check if the player has some items and enough gold to become a vampire (after double-clicking the vampire class stone) i have looked everywhere, searched the RunUO docs folder, searched in BaseVendor.cs script browsed on the forums and still i cannot find a way to check if a player has some items in his backpack, so if anyone would help it would be greatly appreciated!
madmadmax is offline   Reply With Quote
Old 07-09-2008, 12:59 PM   #2 (permalink)
Forum Novice
 
Soteric's Avatar
 
Join Date: Aug 2006
Location: Russia, Rostov-on-Don
Posts: 772
Send a message via ICQ to Soteric
Default

Look for FindItemByType method of Container class
Soteric is offline   Reply With Quote
Old 07-09-2008, 01:30 PM   #3 (permalink)
Forum Master
 
Lord_Greywolf's Avatar
 
Join Date: Dec 2005
Posts: 6,777
Send a message via Yahoo to Lord_Greywolf
Default

can also use the consume method
this shows a bank box method, but can be converted to back pack

BankBox box = from.BankBox;
if ( (box == null || !box.ConsumeTotal(typeof(Gold), 100)) )
from.SendMessage("you need 100 gold in your bank to use this");
else - do what you want

and if you look in on the clockwork assembly for golem making, it shows how to do it for multiple items
__________________
http://www.AoAUO.com

:) ..... Come for the Customs, Play for the Fun. Return to see your new Friends ..... :)
Lord_Greywolf is offline   Reply With Quote
Old 07-09-2008, 01:40 PM   #4 (permalink)
Account Terminated
 
Join Date: Jul 2008
Age: 20
Posts: 26
Default

Quote:
Originally Posted by Soteric View Post
Look for FindItemByType method of Container class
Hmmm... I'm a noob, how do i use it? Just store it as a variable, and when i want to delete it, delete the variable?? I mean something like:
Code:
HeadOfPaladin item = ( from.Backpack == null ? null : m.Backpack.FindItemByType( typeof( PaladinsHead ) ) as HeadOfPaladin );
if (HeadOfPaladin!=0)
{
//Delete the items?                          
m.Criminal=true;
m.IsVampire=true;
m.ExpireCriminalTimer=TimeSpan.FromMonths( 500.0 );
m.SendLocalizedMessage( 1063491, "", 0x22 ); //You are now a vampire
}
EDIT: Thanks for the good replay Greywolf! Now i get the following error:
Code:
CS0122: Line 60: 'Server.Mobile.ExpireCriminalTimer' is inaccessible due to
its protection level
I have no idea of how to fix this, if someone would help me it would be great.

Last edited by madmadmax; 07-09-2008 at 02:17 PM.
madmadmax is offline   Reply With Quote
Old 07-09-2008, 03:42 PM   #5 (permalink)
Newbie
 
Sixkillers's Avatar
 
Join Date: May 2006
Location: Czech Republic
Posts: 78
Default

1) Class Item has got public method Delete(). For example:

Code:
Item helm = new Helm();
helm.Delete();
2) If you want to make player criminal you have to do something like this:

Code:
m.ExpireCriminalDelay = TimeSpan.FromMinutes( 200.0 ); //changing default criminal status delay
m.CriminalAction(false); //set true if you want to send localized message: "You've committed a criminal act!!"

Last edited by Sixkillers; 07-09-2008 at 03:48 PM.
Sixkillers is offline   Reply With Quote
Old 07-09-2008, 04:29 PM   #6 (permalink)
Account Terminated
 
Join Date: Jul 2008
Age: 20
Posts: 26
Default

Quote:
Originally Posted by Sixkillers View Post
1) Class Item has got public method Delete(). For example:

Code:
Item helm = new Helm();
helm.Delete();
2) If you want to make player criminal you have to do something like this:

Code:
m.ExpireCriminalDelay = TimeSpan.FromMinutes( 200.0 ); //changing default criminal status delay
m.CriminalAction(false); //set true if you want to send localized message: "You've committed a criminal act!!"
I get his error when i try to change m.ExpireCriminalDelay
Code:
 CS0176: Line 60: Static member 'Server.Mobile.ExpireCriminalDelay.get' canno
t be accessed with an instance reference; qualify it with a type name instead
madmadmax is offline   Reply With Quote
Old 07-09-2008, 05:18 PM   #7 (permalink)
Newbie
 
Sixkillers's Avatar
 
Join Date: May 2006
Location: Czech Republic
Posts: 78
Default

Sorry my fault it is static member. Here is the fix:

Code:
Server.Mobile.ExpireCriminalDelay = TimeSpan.FromMinutes( 200.0 );
However this will change ExpireCriminalDelay for all players (I guess you dont want this effect).

So you can change your code:

Code:
TimeSpan oldValue = Server.Mobile.ExpireCriminalDelay;
Server.Mobile.ExpireCriminalDelay  = TimeSpan.FromMinutes( 200.0 ); 
m.CriminalAction(false); 
Server.Mobile.ExpireCriminalDelay = oldValue;
Maybe you find clean way to solve this problem.
Sixkillers is offline   Reply With Quote
Old 07-09-2008, 05:29 PM   #8 (permalink)
Account Terminated
 
Join Date: Jul 2008
Age: 20
Posts: 26
Default

Quote:
Originally Posted by Sixkillers View Post
Sorry my fault it is static member. Here is the fix:

Code:
Server.Mobile.ExpireCriminalDelay = TimeSpan.FromMinutes( 200.0 );
However this will change ExpireCriminalDelay for all players (I guess you dont want this effect).

So you can change your code:

Code:
TimeSpan oldValue = Server.Mobile.ExpireCriminalDelay;
Server.Mobile.ExpireCriminalDelay  = TimeSpan.FromMinutes( 200.0 ); 
m.CriminalAction(false); 
Server.Mobile.ExpireCriminalDelay = oldValue;
Maybe you find clean way to solve this problem.
Ok everything worked out, but when i click on the VampireClassStone the server crashes, i really can't see the reason for this crash:
Server Crash Report
===================

RunUO Version 2.0, Build 2959.20979
Operating System: Microsoft Windows NT 6.0.6001 Service Pack 1
.NET Framework: 2.0.50727.1434
Time: 7/9/2008 11:23:40 PM
Mobiles: 7803
Items: 116681
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at Server.Items.VampireClassStone.JoinClass(Mobile m)
at Server.Items.VampireClassStone.OnDoubleClick(Mobil e from)
at Server.Mobile.Use(Item item)
at Server.Network.PacketHandlers.UseReq(NetState state, PacketReader pvSrc)
at Server.Network.MessagePump.HandleReceive(NetState ns)
at Server.Network.MessagePump.Slice()
at Server.Core.Main(String[] args)

Clients:
- Count: 2
+ 127.0.0.1: (account = VampireTest) (mobile = 0x6CC 'VampireTest')
+ 127.0.0.1: (account = Pepolshet) (mobile = 0x22 'Admin Pepolshet')
madmadmax is offline   Reply With Quote
Old 07-09-2008, 05:54 PM   #9 (permalink)
Newbie
 
Join Date: Aug 2003
Location: Pennsylvania
Posts: 75
Send a message via AIM to valarnin Send a message via Yahoo to valarnin
Default

Add a function to PlayerMobile that accepts a Timespan in and sets the player's criminal status from within the PlayerMobile script. This will avoid the "protected" problem.
__________________
Chances are I'm bored, so I'll probably help you. If I'm really bored I might do a few scripts on request, but contact me by messenger if you want that.
valarnin is offline   Reply With Quote
Old 07-09-2008, 06:30 PM   #10 (permalink)
Newbie
 
Sixkillers's Avatar
 
Join Date: May 2006
Location: Czech Republic
Posts: 78
Default

Post here your JoinClass method from VampireClassStone.
Sixkillers is offline   Reply With Quote
Old 07-10-2008, 08:22 AM   #11 (permalink)
Account Terminated
 
Join Date: Jul 2008
Age: 20
Posts: 26
Default

Code:
		public bool JoinClass( Mobile m )
		{
                        PlayerMobile from = m as PlayerMobile;
                        PlayerMobile combatant = from.Combatant as PlayerMobile;
			if ( combatant.IsVampire )
			{
				m.SendLocalizedMessage( 1063490, "", 0x22 ); // You already joined the vampire class
				return false;
			}
			else if ( combatant.IsPaladin )
			{
				m.SendLocalizedMessage( 1063492, "", 0x22 ); // You already joined the paladin class and cannot become a vampire!
				return false;
			}
			else if ( m.Spell != null )
			{
				m.SendLocalizedMessage( 1049616 ); // You are too busy to do that at the moment.
				return false;
			}
                        else if (m.Backpack.ConsumeTotal(typeof(PaladinsHead), 1, true) && m.Backpack.ConsumeTotal(typeof(BoneOfVampire), 1, true) && m.Backpack.ConsumeTotal(typeof(Gold), 150000, true) )
                        {
                               combatant.Criminal=true;
                               combatant.IsVampire=true;
                               combatant.Kills += 20;
                               m.Title = "The Vampire";
                               m.Hue = 0;
                               m.CriminalAction(true); //set true if you want to send localized message: "You've committed a criminal act!!"
                               m.SendLocalizedMessage( 1063491, "", 0x22 ); //You are now a vampire
			       return true;
                        }
			else
			{
				m.CloseGump( typeof( VampireClassGump ) );
				m.SendGump( new VampireClassGump() ); //This is just a gump that shows what you need to join the vampire class
                                m.SendLocalizedMessage( 500191, "", 0x22 ); //Not enough cash :P
                                
				return false;
			}
		}
madmadmax is offline   Reply With Quote
Old 07-10-2008, 08:29 AM   #12 (permalink)
Forum Novice
 
Soteric's Avatar
 
Join Date: Aug 2006
Location: Russia, Rostov-on-Don
Posts: 772
Send a message via ICQ to Soteric
Default

Do you fight when trying to use a Vampire stone?.. Anyway
Code:
if ( combatant == null ) return false;
this check will be useful there...

Last edited by Soteric; 07-10-2008 at 08:33 AM.
Soteric is offline   Reply With Quote
Old 07-10-2008, 08:43 AM   #13 (permalink)
Account Terminated
 
Join Date: Jul 2008
Age: 20
Posts: 26
Default

Quote:
Originally Posted by Soteric View Post
Do you fight when trying to use a Vampire stone?.. Anyway
Code:
if ( combatant == null ) return false;
this check will be useful there...
Yeah, now it doesn't crash but it still doesn't work....
madmadmax is offline   Reply With Quote
Old 07-10-2008, 09:46 AM   #14 (permalink)
Newbie
 
Sixkillers's Avatar
 
Join Date: May 2006
Location: Czech Republic
Posts: 78
Default

Why are you using combatant? Use only Mobile m. I suppose you are double clicking on the Vamipire stone.
Sixkillers is offline   Reply With Quote
Old 07-10-2008, 10:20 AM   #15 (permalink)
Account Terminated
 
Join Date: Jul 2008
Age: 20
Posts: 26
Default

Quote:
Originally Posted by Sixkillers View Post
Why are you using combatant? Use only Mobile m. I suppose you are double clicking on the Vamipire stone.
Yes, why? .
madmadmax is offline   Reply With Quote
Old 07-10-2008, 10:44 AM   #16 (permalink)
Newbie
 
Sixkillers's Avatar
 
Join Date: May 2006
Location: Czech Republic
Posts: 78
Default

I cant understand why you are using:

Code:
PlayerMobile combatant = from.Combatant as PlayerMobile;
That is all
Sixkillers is offline   Reply With Quote
Old 07-10-2008, 11:29 AM   #17 (permalink)
Account Terminated
 
Join Date: Jul 2008
Age: 20
Posts: 26
Default

Quote:
Originally Posted by Sixkillers View Post
I cant understand why you are using:

Code:
PlayerMobile combatant = from.Combatant as PlayerMobile;
That is all
Yeah, i didn't know how to access PlayerMobile variables so i ripped this off another script.

EDIT: If i use "m" i get errors on IsVampire variables because they were created in PlayerMobile.

Last edited by madmadmax; 07-10-2008 at 11:34 AM.
madmadmax is offline   Reply With Quote
Old 07-10-2008, 11:50 AM   #18 (permalink)
Newbie
 
Sixkillers's Avatar
 
Join Date: May 2006
Location: Czech Republic
Posts: 78
Default

Sorry my fault again You have to use:
Code:
PlayerMobile from = m as PlayerMobile;
Use variable 'from' because you have defined IsVampire property there.

Last edited by Sixkillers; 07-10-2008 at 11:54 AM.
Sixkillers is offline   Reply With Quote
Old 07-10-2008, 11:50 AM   #19 (permalink)
Account Terminated
 
Join Date: Jul 2008
Age: 20
Posts: 26
Default

Quote:
Originally Posted by Sixkillers View Post
Sorry my fault again You have to use:
Code:
 PlayerMobile from = m as PlayerMobile;
Use variable 'from' because you have defined IsVampire property there.
Thanks! I think it works now!

EDIT: YEY! It works perfectly! I just got 2 little tiny questions left:
A). What part do i need to change in Gold.cs to make the gold pile able to get an amount higher then 64k? (so players will have say 300k in one gold pile)
B). How can i make a weapon that when a player which isn't a vampire equipt it, it will fall back to the backpack?

Last edited by madmadmax; 07-10-2008 at 11:59 AM.
madmadmax is offline   Reply With Quote
Old 07-10-2008, 01:01 PM   #20 (permalink)
Newbie
 
Sixkillers's Avatar
 
Join Date: May 2006
Location: Czech Republic
Posts: 78
Default

1) I think you cant change it, because for amount are reserved 2 bytes (ushort) in packet.

2) You will have to override method CanEquip in your weapon script. For example:

Code:
  public override bool CanEquip( Mobile from )
               {

            if (m.Player && !((PlayerMobile)m).IsVampire)
            {
                from.SendMessage("You are not vampire!!");
                return false;
            }

            return base.CanEquip(from);
          }
Sixkillers is offline   Reply With Quote
Old 07-10-2008, 08:01 PM   #21 (permalink)
Account Terminated
 
Join Date: Jul 2008
Age: 20
Posts: 26
Default

Quote:
Originally Posted by Sixkillers View Post
1) I think you cant change it, because for amount are reserved 2 bytes (ushort) in packet.

2) You will have to override method CanEquip in your weapon script. For example:

Code:
  public override bool CanEquip( Mobile from )
               {

            if (m.Player && !((PlayerMobile)m).IsVampire)
            {
                from.SendMessage("You are not vampire!!");
                return false;
            }

            return base.CanEquip(from);
          }
Thanks Very Much!! ++ Do you think that if ill change ushort for ulong (or maybe just long, it got 9,223,372,036,854,775,807 numbers anyway ) it will slow down the server a lot?
madmadmax is offline   Reply With Quote
Old 07-10-2008, 08:38 PM   #22 (permalink)
Forum Master
 
Lord_Greywolf's Avatar
 
Join Date: Dec 2005
Posts: 6,777
Send a message via Yahoo to Lord_Greywolf
Default

i believe it would take a core mode to change it for that, and it will effect all items that stack
__________________
http://www.AoAUO.com

:) ..... Come for the Customs, Play for the Fun. Return to see your new Friends ..... :)
Lord_Greywolf is offline   Reply With Quote
Old 07-10-2008, 09:05 PM   #23 (permalink)
Account Terminated
 
Join Date: Jul 2008
Age: 20
Posts: 26
Default

Quote:
Originally Posted by Lord_Greywolf View Post
i believe it would take a core mode to change it for that, and it will effect all items that stack
You maybe mean core mod and not "core mode"? You mean i need to recompile the source code on the site? How will it affect my game?
madmadmax is offline   Reply With Quote
Old 07-11-2008, 04:55 AM   #24 (permalink)
Newbie
 
Sixkillers's Avatar
 
Join Date: May 2006
Location: Czech Republic
Posts: 78
Default

Yes, you can edit core (edit & compile) as you wish, but client you cant change (or very hardly). Client is using two bytes variable for amount. So when you send him longer variable he probably crashes.

Last edited by Sixkillers; 07-11-2008 at 05:52 AM.
Sixkillers is offline   Reply With Quote
Old 07-11-2008, 10:13 AM   #25 (permalink)
Account Terminated
 
Join Date: Jul 2008
Age: 20
Posts: 26
Default

Quote:
Originally Posted by Sixkillers View Post
Yes, you can edit core (edit & compile) as you wish, but client you cant change (or very hardly). Client is using two bytes variable for amount. So when you send him longer variable he probably crashes.
Ok thanks for the help! Now my 2 last questions:
I made 3 custom flags in PlayerMobile.cs (IsVampire, IsPaladin and ProPack)
Code:
namespace Server.Mobiles
{
	#region Enums
	[Flags]
	public enum PlayerFlag // First 16 bits are reserved for default-distro use, start custom flags at 0x00010000
	{
		None			= 0x00000000,
		Glassblowing		= 0x00000001,
		Masonry			= 0x00000002,
		SandMining		= 0x00000004,
		StoneMining		= 0x00000008,
		ToggleMiningStone	= 0x00000010,
		KarmaLocked		= 0x00000020,
		AutoRenewInsurance	= 0x00000040,
		UseOwnFilter		= 0x00000080,
		PublicMyRunUO		= 0x00000100,
		PagingSquelched		= 0x00000200,
		Young			= 0x00000400,
		AcceptGuildInvites	= 0x00000800,
		DisplayChampionTitle    = 0x00001000,
		ProPack                 = 0x00010200,
		IsVampire               = 0x00010400,
		IsPaladin               = 0x00010600
	}
I have also added:
Code:
		[CommandProperty( AccessLevel.GameMaster )]
		public bool IsPaladin
		{
			get{ return GetFlag( PlayerFlag.IsPaladin ); }
			set{ SetFlag( PlayerFlag.IsPaladin, value ); }
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public bool IsVampire
		{
			get{ return GetFlag( PlayerFlag.IsVampire ); }
			set{ SetFlag( PlayerFlag.IsVampire, value ); }
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public bool ProPack
		{
			get{ return GetFlag( PlayerFlag.ProPack ); }
			set{ SetFlag( PlayerFlag.ProPack, value ); }
		}
so i will be able to switch them, but for some super really odd reason when i change IsVampire or IsPaladin to another value the other class variable becomes the same value! for example i set IsVampire=true, IsPaladin becomes true too! (and nothing happens to ProPack) i've also tried to fix that bug:
Code:
            if ( IsVampire && Karma>0 )
                        {
                        Criminal=true;
                        Karma=-1000;
                        }
                        if ( IsVampire && IsPaladin )
                        {
                        IsVampire=false;
                        IsPaladin=false;
                        }
I've added the code above to the line 3058 in to the fast walk class it seems that it doesn't help? And i would also want to know how can i disable the elf class?
madmadmax is offline   Reply With Quote
Reply

Bookmarks