This is a code snippet in distro accounthandler.cs, it is called after a toon is deleted, and creates another toon in its place. Works great, however when an owner level account deletes a toon, it does work however the toon is not owner level, its player level.

I tried creating a reference to check for account level however i'm having a hard time, this is the code I currently have trying to reference account level and its failing. Error Posted below.

Code:
        private static Mobile CreateMobile(int i)
        {
            Mobile from;
            Account acct = from.Account as Account;
            Mobile newChar = new PlayerMobile();
            newChar.Name = "New Character "+i.ToString();
            newChar.Player = true;
          
            var levelaccess = acct.AccessLevel.Owner;
          
            if (newChar == levelaccess)
            {
                newChar.AccessLevel = AccessLevel.Owner;
            }
            else
                newChar.AccessLevel = AccessLevel.Player;
          
            newChar.Female = false;
            newChar.Race = Race.Ivory;
            newChar.Hue = 1002;
            newChar.Hunger = 20;
            newChar.HairItemID = 0x203B;
            newChar.HairHue = 1102;
            newChar.FacialHairItemID = 0;
            newChar.FacialHairHue = 1102;
            newChar.Skills.Cap = 100000;
            newChar.StatCap = 950;
         
            newChar.LogoutMap = Map.Alfheim;
            newChar.LogoutLocation = new Point3D(5399, 2770, 25);
         
            newChar.Location = new Point3D(0,0,0);
            newChar.Map = Map.Internal;
         
            AddBackpack( newChar );
           //currently this makes owner and gm to normal player access levels.
           bool young = false;
           if (newChar is PlayerMobile)
           {
               PlayerMobile pm = (PlayerMobile)newChar;
               pm.ToLevell = 150;
               young = pm.Young = false;
           }
            return newChar;
        }


Code:
Errors:
+ Accounting/AccountHandler.cs:
    CS0176: Line 506: Member 'Server.AccessLevel.Owner' cannot be accessed with an instance reference; qualify it with a type name instead
    CS0019: Line 508: Operator '==' cannot be applied to operands of type 'Server.Mobile' and 'Server.AccessLevel'
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.

I'm likely over thinking this...
 
I am not sure where "from" comes from, but AccessLevel is AccessLevel so, this should work:

Code:
newChar.AccessLevel = from.Account.AccessLevel;

I would rewrite it like this:

Code:
        private static Mobile CreateMobile(int i)
        {
            PlayerMobile newChar = new PlayerMobile();
            newChar.Name = "New Character "+i.ToString();
            newChar.Player = true;
            newChar.Female = false;
            newChar.Race = Race.Ivory;
            newChar.Hue = 1002;
            newChar.Hunger = 20;
            newChar.HairItemID = 0x203B;
            newChar.HairHue = 1102;
            newChar.FacialHairItemID = 0;
            newChar.FacialHairHue = 1102;
            newChar.Skills.Cap = 100000;
            newChar.StatCap = 950;
            newChar.LogoutMap = Map.Alfheim;
            newChar.LogoutLocation = new Point3D(5399, 2770, 25);
            newChar.Location = new Point3D(5399, 2770, 25);
            newChar.Map = Map.Internal;
          
            newChar.AccessLevel = from.Account.AccessLevel;
            newChar.Young = false;
            pm.ToLevell = 150;
          
            AddBackpack( newChar );
          
            return (Mobile)newChar;
        }
 
That works, like i said over thinking it. LOL. the 'from' was a reference earlier in the script.
 
The only real issue left is that this wouldn't invoke the CharacterCreated event, so some other critical features may not be invoked when the new character is created.

Also, what happens if the account itself is deleted? Would it get stuck in a loop deleting/creating characters?
 
Wow.. That is a valid point.. I guess there would need to be additional arguments to ignore the character creation event if was result of account being deleted. Or just not delete accounts.
[doublepost=1502319281][/doublepost]I suspect adding in a null check here would help that problem, to see if the account is null or not. Compiled fine, I will test later to see if it causes a crash.

Code:
        public static void CreateMobiles( Account a )
        {
            if ( a.Count >= a.Limit )
                return ;
            if (a == null)
                return;

            for ( int i = 0; i < a.Length; ++i )
            {
                if ( a[i] == null )
                {
                    a[i] = CreateMobile(i);
                }
            }
        }
[doublepost=1502394215][/doublepost]So that did fix that potential issue however you are absolutely correct regarding problems coming not invoking the charactercreated event. I will have to re think how this can be implimented correctly. I looked over the code for 'default character' script more closely and that seems to invoke the charactercreated event, so i think I will try to call that script inside EventSink_DeleteRequest.

https://www.servuo.com/threads/default-character-on-account-creation.3577/
 
Last edited:
Back