darky

Member
ServUO Version
Publish 57
Ultima Expansion
Endless Journey
this script here , is setup to give player new rank displayed under his name when he kills a certain number of creatures into the world witch pet kills should also count , and its not doing so or displaying message to the player or even counting the pet kill , or even adding the status it should , i was about to aask if someone could help here to see if i made any mistake , i am not a programmer , just an entusiast , if someone is able to help , i apreciate !
Thanks in advance!
 

Attachments

  • ~playersrank.cs
    4.9 KB · Views: 6
Your script had many issues, I took the liberty to rewrite it!


C#:
using System;
using System.Collections.Generic;
using Server;
using Server.Mobiles;

namespace CustomScripts
{
    public class RankSystem
    {
        private static Dictionary<Serial, int> PlayerRankList;
        public static void Configure()
        {
            EventSink.WorldSave += e => Persistence.Serialize(@"Saves\\Ranks\\Profiles.bin", Save);
            EventSink.WorldLoad += () => Persistence.Deserialize(@"Saves\\Ranks\\Profiles.bin", Load);
        }

        public static void Save(GenericWriter writer)
        {
            writer.Write(0); // version

            writer.Write(PlayerRankList.Count);

            foreach (var profile in PlayerRankList)
            {
                writer.Write(profile.Key);
                writer.Write(profile.Value);
            }
        }

        public static void Load(GenericReader reader)
        {
            reader.ReadInt(); // version

            var count = reader.ReadInt();

            if (PlayerRankList == null)
            {
                PlayerRankList = new Dictionary<Serial, int>();
            }

            while (--count >= 0)
            {
                PlayerRankList.Add(reader.ReadInt(), reader.ReadInt());
            }
        }

        private static readonly (int threshold, string title, int bonus)[] _BonusInfo =
        {
            (100, "Solder", 10),
            (200, "Major", 20),
            (500, "Baron", 30),
            (1000, "King", 40),
            (2000, "Demi God", 50),
            (5000, "God", 60),
            (10000, "World Ruler", 70)
        };

        public static void Initialize()
        {
            if (PlayerRankList == null)
            {
                PlayerRankList = new Dictionary<Serial, int>();
            }

            EventSink.PlayerDeath += EventSink_PlayerDeath;

            EventSink.CreatureDeath += EventSink_CreatureDeath;
        }

        private static void EventSink_PlayerDeath(PlayerDeathEventArgs e)
        {
            if (e.Mobile.LastKiller != null)
            {
                CheckAndUpdateRank(e.Mobile.LastKiller);
            }
        }

        private static void EventSink_CreatureDeath(CreatureDeathEventArgs e)
        {
            if (e.Killer != null)
            {
                CheckAndUpdateRank(e.Killer);
            }
        }

        private static void CheckAndUpdateRank(Mobile killer)
        {
            if (killer is PlayerMobile pm)
            {
                UpdateRank(pm);
            }
            else if (killer is BaseCreature creature && creature.Controlled && creature.ControlMaster is PlayerMobile master)
            {
                UpdateRank(master);
            }
        }

        private static void UpdateRank(PlayerMobile pm)
        {
            if (PlayerRankList.ContainsKey(pm.Serial))
            {
                PlayerRankList[pm.Serial]++;
            }
            else
            {
                PlayerRankList.Add(pm.Serial, 1);
            }

            TryApplyRankBonus(pm);
        }

        private static void TryApplyRankBonus(PlayerMobile pm)
        {
            foreach (var info in _BonusInfo)
            {
                if (info.threshold == PlayerRankList[pm.Serial])
                {
                    pm.SendMessage(53, $"Congratulations! You have been promoted to {info.title}.");

                    Console.WriteLine($"Player {pm.Name} has been promoted to {info.title}.");

                    pm.Title = $"the {info.title}";

                    pm.RawStr += info.bonus;
                    pm.RawInt += info.bonus;
                    pm.RawDex += info.bonus;
                }
            }
        }
    }
}
 

Active Shards

Donations

Total amount
$50.00
Goal
$1,000.00
Back