Hello
I need advice on extending the functionality of public moongate.
My server work with active siege ruleset, but we have launched the New Haven startup area - only for new players (with less than 40 hours of gameplay). Now we would like to change the public moongate script - still with active siege - to allow players with less than 40 hours of gaming only (or account with less than 40 hours) - to travel from and to Haven via public moongate . I mean New Haven as a destination - it was displayed (in gump) only for characters with less than 40 hours of gameplay (or accounts with that game time).
Normally this is achieved under the young system, but on siege young system does not work, so a new players do not see the Trammel destinations in the public moongate gump.
We try to push ourselves forward, but we came across some trouble. What have we done

First - we already commited a list of destinations on Trammel (line 250+) for New Haven only.

Code:
public static readonly PMList Trammel =
            new PMList(1012000, 1012012, Map.Trammel, new PMEntry[]
            {
                //new PMEntry(new Point3D(4467, 1283, 5), 1012003), // Moonglow
                //new PMEntry(new Point3D(1336, 1997, 5), 1012004), // Britain
                //new PMEntry(new Point3D(1499, 3771, 5), 1012005), // Jhelom
                //new PMEntry(new Point3D(771, 752, 5), 1012006), // Yew
                //new PMEntry(new Point3D(2701, 692, 5), 1012007), // Minoc
                //new PMEntry(new Point3D(1828, 2948,-20), 1012008), // Trinsic
                //new PMEntry(new Point3D(643, 2067, 5), 1012009), // Skara Brae
                /* Dynamic Z for Magincia to support both old and new maps. */
                //new PMEntry(new Point3D(3563, 2139, Map.Trammel.GetAverageZ(3563, 2139)), 1012010), // (New) Magincia
                new PMEntry(new Point3D(3450, 2677, 25), 1078098)// New Haven
            });


Next, to achieve the intended goal we partly comment line 58-60 to disable Trammel display locking - as a destinaton point in gump (for servers with active siege ruleset):

Code:
//if (!Siege.SiegeShard)
//{
count + = MoonGen (PMList.Trammel);
//}

Next we have added another part of code in PM Checklist section (line 420+) -

Code:
 else if (mobile.GameTime >= TimeSpan.FromHours(40.0))
  {
   checkLists = PMList.SALists;
  }

and allso we modified gump checklist section (line 490)+

Code:
                //if (Siege.SiegeShard && checkLists[i].Number == 1012000) // Trammel
                //   continue;
                if (Siege.SiegeShard && mobile.GameTime >= TimeSpan.FromHours(40.0) && checkLists[i].Number == 1012000) // Trammel
                continue;

This should result in a full list of continents (with Trammel/New Haven destination ) but only for characters with less than 40 hours of gameplay

At last, we wrote a new lines in ListEntries sector (line 550+)

Code:
else if (m_Mobile.Player && m_Mobile.GameTime >= TimeSpan.FromHours(40.0) && list.Map == Map.Trammel)
{
m_Mobile.SendLocalizedMessage(1019004); // You are not allowed to travel there.
return;
}

what should cause older characters to receive a message about being unable to move to Trammel (New Haven area)

Unfortunately - after modifications - our test server stop during startup with these error:
Scripts: Compiling C# scripts...Failed with: 1 errors, 0 warnings
Errors:
+ Items/Functional/PublicMoongate.cs:
CS1061: Line 419: 'Server.Mobile' does not contain a definition for 'GameTime' and no extension method 'GameTime' accepting a first argument of type 'Server.Mobile' could be found (are you missing a using directive or an assembly reference?)
CS1061: Line 494: 'Server.Mobile' does not contain a definition for 'GameTime' and no extension method 'GameTime' accepting a first argument of type 'Server.Mobile' could be found (are you missing a using directive or an assembly reference?)
CS1061: Line 563: 'Server.Mobile' does not contain a definition for 'GameTime' and no extension method 'GameTime' accepting a first argument of type 'Server.Mobile' could be found (are you missing a using directive or an assembly reference?)
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.

Error indicates that the public moongate script does not properly describe the GameTime parameter.
Could I ask for your help in this regard please?

I attach our modified file.
 

Attachments

  • PublicMoongate.cs
    20.9 KB · Views: 1
Last edited:
The error is saying that Server/Mobile doesn't have a GameTime property, which is true.
What you need to do is this

PlayerMobile pm = (PlayerMobile)from; // "from" referring to Mobile, this is called Casting - Mobile to PlayerMobile

or, I believe you could do this which sometimes makes things a little cleaner if you need the Casting for a few lines without messing up any other lines

((PlayerMobile)from).GameTime
 
Direct casting is handy, but you better make sure it can never return null. Indirect casting is often needed so you can follow up with a null check:

PlayerMobile pm = from as PlayerMobile;

If (pm != null)
Do something()

With a direct cast, you need to make sure the condition will always exist.

((PlayerMobile)from).GameTime // direct cast, no null check. You will get a null crash if this code runs against something that is not a PlayerMobile.
 
Direct casting is handy, but you better make sure it can never return null. Indirect casting is often needed so you can follow up with a null check:

PlayerMobile pm = from as PlayerMobile;

If (pm != null)
Do something()

With a direct cast, you need to make sure the condition will always exist.

((PlayerMobile)from).GameTime // direct cast, no null check. You will get a null crash if this code runs against something that is not a PlayerMobile.
Hadn't considered that, Ty.
 
Back