So heres the scenario

399 out of 400 exp to level

kill a skeleton and boom you level..

systems creates new exp required to level and sets it fine... BUT!!

It should then reset the players exp to 0 but it doesnt. Anyone know why it is not doing as it should?
Code:
public static void DoLevel(Mobile m, Setup set)
        {
            double TimesLeveled = 0;
            PlayerMobile pm = m as PlayerMobile;

            pm.PlaySound(0x20F);
            pm.FixedParticles(0x376A, 1, 31, 9961, 1160, 0, EffectLayer.Waist);
            pm.FixedParticles(0x37C4, 1, 31, 9502, 43, 2, EffectLayer.Waist);

            if (set.StatRefillOnLevel)
            {
                if (pm.Hits < pm.HitsMax)
                    pm.Hits = pm.HitsMax;

                if (pm.Mana < pm.ManaMax)
                    pm.Mana = pm.ManaMax;

                if (pm.Stam < pm.StamMax)
                    pm.Stam = pm.StamMax;
            }


            /*
            while (pm.Exp >= pm.LevelAt && pm.Level != pm.LevelCap)
            {
                if (set.AccumulativeExp)
                    return;

                int newexp = 0;

                if (pm.Exp > pm.LevelAt)
                    newexp = pm.Exp - pm.LevelAt;

                pm.Exp = newexp;
                TimesLeveled++;
            }
            */

            for (int i = 1; pm.Exp >= pm.LevelAt; i++)
            {
                pm.LevelAt += set.NextLevelAt;
                pm.AccLevelAt += (int)(set.NextLevelAt + pm.AccKillExp);

                if (set.BonusStatOnLevel && pm.RawStatTotal != pm.StatCap && set.ChanceForBonusStat < Utility.Random(100))
                {
                    switch (Utility.Random(3))
                    {
                        case 0: pm.RawStr += 1; break;
                        case 1: pm.RawDex += 1; break;
                        case 2: pm.RawInt += 1; break;
                    }
                }

                TimesLeveled = i;
            }

            if (set.RefreshExpBarOnGain && pm.HasGump(typeof(ExpBar)))
            {
                pm.CloseGump(typeof(ExpBar));
                pm.SendGump(new ExpBar(pm));
            }

            pm.SendMessage("You're Level has increased by {0}", TimesLeveled);
            pm.Level += (int)TimesLeveled;
        }
 
Last edited by a moderator:
The section that's commented out handles setting player XP to the new value, why is it commented out?
 
The section that's commented out handles setting player XP to the new value, why is it commented out?

I've been looking at this for so long I've gone blind to it.... Will give it a try lol
[doublepost=1488920624][/doublepost]now im getting this.

Code:
Scripts: Compiling C# scripts...Failed with: 1 errors, 0 warnings
Errors:
 + APKV2/Systems/Level System/Core/Actions.cs:
    CS0266: Line 150: Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)
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 assuming everything works with 'double', yet this is an 'int';
Code:
int newexp = 0;

Try this;
Code:
double newexp = 0;
 
I'm assuming everything works with 'double', yet this is an 'int';
Code:
int newexp = 0;

Try this;
Code:
double newexp = 0;

ok so set my exp to 199/200 get exp and boom i crash server restarts im level 1 with 0/200 exp now

The entire "actions" script

Code:
using System;
using Server;
using Server.Gumps;
using Server.Items;
using Server.Mobiles;
using Server.Network;
using Server.Engines.Craft;
using Server.Engines.PartySystem;

namespace Server
{
    public class Actions
    {
        public static void StartGain(Mobile killer, Mobile killed)
        {
            Setup set = new Setup();
            PlayerMobile pm = null;

            if (killer is PlayerMobile) //Find & Set killer
                pm = killer as PlayerMobile;
            else
            {
                BaseCreature bc = killer as BaseCreature;

                if (bc.Controlled && set.ExpFromPetKills)
                    pm = bc.GetMaster() as PlayerMobile;
            }

            if (pm == null) //if no killer Exit system
                return;

            double Gain = Figures.GetKillExp(pm, killed, new Setup()); //Get the exp for the kill

            FinalizeExp(pm, killed, Gain, new Setup());
        }

        public static void ExpPlugin(Mobile m, double Gain)
        {
            Setup set = new Setup();
            FinalizeExp(m, null, Gain, false, new Setup());
        }

        public static void FinalizeExp(Mobile m, Mobile killed, double Gain, Setup set)//for kills (no Craft bool)
        {
            FinalizeExp(m, killed, Gain, false, new Setup());
        }

        public static void FinalizeExp(Mobile m, double Gain, bool Craft, Setup set)//for craft (no killed Mobile)
        {
            FinalizeExp(m, null, Gain, Craft, new Setup());
        }

        public static void FinalizeExp(Mobile m, Mobile killed, double Gain, bool Craft, Setup set)
        {
            double BeforeFilter;//used only for party exp system
            double AfterLevelDiffFilter;
            double AfterCapFilter;
            Party party = Party.Get(m);

            if (!Craft && killed != null && party != null && set.ExpPartyShare)
            {
                int PlayersInRange = 0;

                foreach (PartyMemberInfo info in party.Members)
                {
                    PlayerMobile pm = info.Mobile as PlayerMobile;

                    if (pm.Alive && pm.InRange(killed, set.PartyRange))
                        PlayersInRange++;
                }//Dumb that I have to count players this way....

                if (set.ExpEvenPartyShare)
                    BeforeFilter = Gain / PlayersInRange;
                else
                    BeforeFilter = Gain;

                foreach (PartyMemberInfo info in party.Members)
                {
                    PlayerMobile pm = info.Mobile as PlayerMobile;

                    if (pm.Alive && pm.InRange(killed, set.PartyRange))
                    {
                        AfterLevelDiffFilter = Figures.LevelDiffFilter(pm, killed, BeforeFilter, new Setup());
                        AfterCapFilter = Figures.CapFilter(pm, AfterLevelDiffFilter, new Setup());
                        AddExp(pm, AfterCapFilter, new Setup());
                    }
                }
            }
            else
            {
                PlayerMobile pm = m as PlayerMobile;
                AfterLevelDiffFilter = Figures.LevelDiffFilter(pm, killed, Gain, new Setup());
                AfterCapFilter = Figures.CapFilter(pm, AfterLevelDiffFilter, new Setup());

                AddExp(pm, AfterCapFilter, new Setup());
            }
        }

        public static void AddExp(Mobile m, double Gain, Setup set)
        {
            PlayerMobile pm = m as PlayerMobile;

            if (Gain > 0)
                pm.SendMessage("You've gained {0} exp.", Math.Round(Gain, 2));

            pm.KillExp += Math.Round(Gain, 2);
            pm.AccKillExp += Math.Round(Gain, 2);

            if (set.RefreshExpBarOnGain && pm.HasGump(typeof(ExpBar)))
            {
                pm.CloseGump(typeof(ExpBar));
                pm.SendGump(new ExpBar(pm));
            }

            if (pm.Level < pm.LevelCap && pm.Exp >= pm.LevelAt)
                DoLevel(pm, new Setup());
        }

        public static void DoLevel(Mobile m, Setup set)
        {
            double TimesLeveled = 0;
            PlayerMobile pm = m as PlayerMobile;

            pm.PlaySound(0x20F);
            pm.FixedParticles(0x376A, 1, 31, 9961, 1160, 0, EffectLayer.Waist);
            pm.FixedParticles(0x37C4, 1, 31, 9502, 43, 2, EffectLayer.Waist);

            if (set.StatRefillOnLevel)
            {
                if (pm.Hits < pm.HitsMax)
                    pm.Hits = pm.HitsMax;

                if (pm.Mana < pm.ManaMax)
                    pm.Mana = pm.ManaMax;

                if (pm.Stam < pm.StamMax)
                    pm.Stam = pm.StamMax;
            }


           
            while (pm.Exp >= pm.LevelAt && pm.Level != pm.LevelCap)
            {
                if (set.AccumulativeExp)
                    return;

                double newexp = 0;

                if (pm.Exp > pm.LevelAt)
                    newexp = pm.Exp - pm.LevelAt;

                pm.Exp = newexp;
                TimesLeveled++;
            }
           

            for (int i = 1; pm.Exp >= pm.LevelAt; i++)
            {
                pm.LevelAt += set.NextLevelAt;
                pm.AccLevelAt += (int)(set.NextLevelAt + pm.AccKillExp);

                if (set.BonusStatOnLevel && pm.RawStatTotal != pm.StatCap && set.ChanceForBonusStat < Utility.Random(100))
                {
                    switch (Utility.Random(3))
                    {
                        case 0: pm.RawStr += 1; break;
                        case 1: pm.RawDex += 1; break;
                        case 2: pm.RawInt += 1; break;
                    }
                }

                TimesLeveled = i;
            }

            if (set.RefreshExpBarOnGain && pm.HasGump(typeof(ExpBar)))
            {
                pm.CloseGump(typeof(ExpBar));
                pm.SendGump(new ExpBar(pm));
            }

            pm.SendMessage("You're Level has increased by {0}", TimesLeveled);
            pm.Level += (int)TimesLeveled;
        }
    }
}
[doublepost=1488929718][/doublepost]Opened up console after crash all seemed fine.... typed save had this error


Code:
Server Crash Report
===================

ServUO Version 0.5, Build 6275.26100
Operating System: Microsoft Windows NT 6.2.9200.0
.NET Framework: 4.0.30319.42000
Time: 07/03/2017 23:33:32
Mobiles: 15398
Items: 132317
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
   at Server.Mobile.get_PropertyList() in c:\ServUO-master\Server\Mobile.cs:line 9671
   at Server.Mobile.InvalidateProperties() in c:\ServUO-master\Server\Mobile.cs:line 9695
   at Server.Actions.DoLevel(Mobile m, Setup set)
   at Server.Actions.AddExp(Mobile m, Double Gain, Setup set)
   at Server.Actions.FinalizeExp(Mobile m, Mobile killed, Double Gain, Boolean Craft, Setup set)
   at Server.Actions.StartGain(Mobile killer, Mobile killed)
   at Server.Mobiles.BaseCreature.OnDamage(Int32 amount, Mobile from, Boolean willKill)
   at Server.Mobile.Damage(Int32 amount, Mobile from, Boolean informMount, Boolean checkDisrupt) in c:\ServUO-master\Server\Mobile.cs:line 5695
   at Server.Mobiles.BaseCreature.Damage(Int32 amount, Mobile from, Boolean informMount, Boolean checkDisrupt)
   at Server.AOS.Damage(IDamageable damageable, Mobile from, Int32 damage, Boolean ignoreArmor, Int32 phys, Int32 fire, Int32 cold, Int32 pois, Int32 nrgy, Int32 chaos, Int32 direct, Boolean keepAlive, Boolean archer, Boolean deathStrike)
   at Server.Items.BaseWeapon.OnHit(Mobile attacker, IDamageable damageable, Double damageBonus)
   at Server.Items.BaseKnife.OnHit(Mobile attacker, IDamageable defender, Double damageBonus)
   at Server.Items.BaseWeapon.OnSwing(Mobile attacker, IDamageable damageable, Double damageBonus)
   at Server.Mobile.CombatTimer.OnTick() in c:\ServUO-master\Server\Mobile.cs:line 2103
   at Server.Timer.Slice() in c:\ServUO-master\Server\Timer.cs:line 409
   at Server.Core.Main(String[] args) in c:\ServUO-master\Server\Main.cs:line 568

Clients:
- Count: 1
+ 127.0.0.1: (account = drewwales) (mobile = 0x3B2 'Anderson')
 
Back