Tailean

Member
Okay, so my New Sorcery spell book must remain open for my players to cast the new spells. When they logout or die the spellbook closes automatically. Is there a way to either:

  • Make the spell-book so that it never closes unless the player double clicks it.
  • or, Make the spell-book re-open upon death and login if its in their pack.
I am looking for the simplest answer possible due to my limited knowledge of C#.

{*The below code was not coded by me only edited by me.}

Code:
using System;
using Server.Items;
using System.Collections.Generic;
using Server;
using Server.Commands;
using Server.Engines.Craft;
using Server.Network;
using Server.Spells;
using Server.Targeting;

namespace Server.ACC.CSS.Systems.Druid
{
    public class DruidSpellbook : CSpellbook
    {
        public override School School{ get{ return School.Druid; } }

        [Constructable]
        public DruidSpellbook() : this( (ulong)0, CSSettings.FullSpellbooks )
        {
            Hue = 1917;
        }

        [Constructable]
        public DruidSpellbook( bool full ) : this( (ulong)0, full )
        {
            Hue = 1917;
        }

        [Constructable]
        public DruidSpellbook( ulong content, bool full ) : base( content, 0xEFA, full )
        {
            Hue = 1917;
            Name = "Manual of Sorcery";
           
        }

        public override void OnDoubleClick( Mobile from )
        {
            if ( from.AccessLevel == AccessLevel.Player )
            {
                Container pack = from.Backpack;
                if( !(Parent == from || (pack != null && Parent == pack)) )
                {
                    from.SendMessage( "The spellbook must be in your backpack [and not in a container within] to open." );
                    return;
                }
                else if( SpellRestrictions.UseRestrictions && !SpellRestrictions.CheckRestrictions( from, this.School ) )
                {
                    return;
                }
            }

            //from.CloseGump( typeof( DruidSpellbookGump ) );
            from.SendGump( new DruidSpellbookGump( this ) );
        }

        public DruidSpellbook( 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();
        }
    }
}
 
You could:
  1. Handle the "opened the gump".
  2. Handle the "closed the gump".
  3. Store the spellbook opened/closed states in a List<PlayerMobile>.
  4. Breaking point: if the gump close is called when the player dies and is handled like the player closed it himself, not sure if you can do that.
  5. When resurrected, if the player is in the list we stored, open the gump.
 
I want to say that the client itself closes all gumps and containers when it gets the "death" packet, much like it closes containers when you change facets. You might avoid that by having Razor filter "death" but it would be required of all players. That still leaves you with the other hurdles that Po0ka mentioned.

Most alternate (like druid) spell systems offer text equivalents for each spell so the book doesn't have to be open. It still checks for the spell within the book before casting. They can just type [spellnamehere to cast and it works just like you clicked the spell in the book.
 
You'll need to add a "helper" script that adds that functionality to your spell system. It's pretty easy to modify this file to your needs.

• Change the names of the commands to the spells you are using.
• Edit each line like "if (HasSpell(from, 301))" so that the spell number matches the numbers from your system.
• Edit the rest of each entry to reflect the right description and to cast the proper spell.
 

Attachments

  • DruidCommandList.cs
    14.6 KB · Views: 6
I don't think that is possible so I merely provided an alternative method to cast the spells. Nothing you do server-side will keep the client from doing what it wants!
 
Don't prevent the book from closing, force it to reopen if it was opened before dying.

You could create a custom script file, with a static List<PlayerMobile>, having an insert method & check contains returning a bool if the player is in.

Once that is done, simply find the appropriate place to put the code to handle the insertion and check.
If you don't know how to start, search in PlayerMobile.cs, possibly OnDeath and OnRessurrect or something like that.

https://stackoverflow.com/questions/4124102/whats-a-static-method-in-c#4124118

Extra: you don't need to make it save between server restarts, but if you do want that, do it at the very end, it won't impact anything in the meantime.

Also, please, if you use RunUO, be sure to state the version you are using next time.
Refer to this: https://www.servuo.com/threads/please-state-if-server-is-servuo-or-runuo-for-help.9550/
 
TY for responding, I am running Runuo 2.6..sadly the above is beyond my understanding. I did a valid view and even an attempt at it but I lack in understanding.
 
See the file in attachment.

-In PlayerMobile.cs, find the following:
Code:
public override void Resurrect()
{
   	bool wasAlive = this.Alive;

   	base.Resurrect();
}

-Change it to that:
Code:
public override void Resurrect()
{
   	bool wasAlive = this.Alive;

   	base.Resurrect();

   	if (wasAlive || Backpack == null)
     		return;

   	if (!SpellbookMarker.CheckOpened(this))
     		return;

   	DruidSpellbook book = Backpack.FindItemByType(typeof(DruidSpellbook)) as DruidSpellbook;
   	if (book == null)
     		return;

   	// Force the double click action from here so we don't duplicate the conditions.
   	book.OnDoubleClick(this);
}

EDIT: Forgot an important part.
In the gump of your spellbook, find this method:

public override void OnResponse( NetState state, RelayInfo info )

in the case 0, edit as such:

Code:
case 0:
{
	PlayerMobile pm = from as PlayerMobile;
	if (pm != null)
		SpellMarker.Remove(pm);

	break;
}

You might want to add a dedicated "close" button for this, or add your own "stay opened" toggle button, as i think it will reset when a player dies, calling the case 0 anyways, rendering all that useless.

As for the opening, add a new check in the OnDoubleClick of the book script.
Code:
PlayerMobile pm = m as PlayerMobile;
if (pm != null)
	SpellMarker.Add(pm);

-------

NOTE: Nothing is tested, you might have to do adjustments, tell me if you get any erorr or unwanted results.
I also need something like that for my server as well.

I used PlayerMobile, but i should have used Mobile to make things simpler, i can change it if you wish.
 

Attachments

  • SpellbookMarker.cs
    687 bytes · Views: 2
Last edited:

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back