mem981 Posted September 10, 2021 Posted September 10, 2021 Hello everyone. I want add new stats 23, 24 to HP and MP, but my code is bug Every time I die, the amount of max HP and MP is increased, i dont know why, pls help me!
1 nvh Posted September 11, 2021 Posted September 11, 2021 18 minutes ago, mem981 said: do i need to add StatsGiven[] in this line??? location (intersect.Server/Database/Item.cs)  public virtual void Set(Item item)        {            ItemId = item.ItemId;            Quantity = item.Quantity;            BagId = item.BagId;            Bag = item.Bag;            for (var i = 0; i < (int) Stats.StatCount; i++)            {                StatBuffs[i] = item.StatBuffs[i];            }                     //My line----------------------------------            for (var i = 0; i < (int) Stats.StatCount; i++)            {                StatsGiven[i] = item.StatsGiven[i];            }        ///---------------------------        }  no! don't do it this way is work! Spoiler for (var i = 0; i < Options.EquipmentSlots.Count; i++)          {             var equipment = Equipment[i];             if (Equipment[i] >= 0 && Equipment[i] < Options.MaxInvItems && Equipment[i] < Items.Count)             {                if (Items[Equipment[i]].ItemId != Guid.Empty)                {                   var itemx = Items[equipment];                   var item = ItemBase.Get(Items[Equipment[i]].ItemId);                   var descriptor = ItemBase.Get(itemx.ItemId);                   if (item != null)                   {                                                classVital +=                         item.VitalsGiven[vital] +                         (vital == (int)Vitals.Health ?                         (descriptor.StatsGiven[23] + Items[Equipment[i]].StatBuffs[23]) :                         (descriptor.StatsGiven[24] + Items[Equipment[i]].StatBuffs[24]))                         + item.PercentageVitalsGiven[vital] * baseVital / 100;                   }                }             }          }  mem981 1
0 boasfesta Posted September 10, 2021 Posted September 10, 2021 The problem is happening because you are adding the stat just after the measure involving the baseVital. Cut and replicate the whole formula inside the IFs, so you just need to add the item.StatsGiven/StatBuffs after item.VitalsGiven. Remember to keep VitalsPercentage at last. Hope it helps mem981 1
0 mem981 Posted September 10, 2021 Author Posted September 10, 2021 45 minutes ago, boasfesta said: The problem is happening because you are adding the stat just after the measure involving the baseVital. Cut and replicate the whole formula inside the IFs, so you just need to add the item.StatsGiven/StatBuffs after item.VitalsGiven. Remember to keep VitalsPercentage at last. Hope it helps thank u! it's work but how to know [vital] is Health or Mana, i want add StatsGiven[23] for Health and SG[24] for Mana Spoiler for (var i = 0; i < Options.EquipmentSlots.Count; i++)            {                if (Equipment[i] >= 0 && Equipment[i] < Options.MaxInvItems && Equipment[i] < Items.Count)                {                    if (Items[Equipment[i]].ItemId != Guid.Empty)                    {                        var item = ItemBase.Get(Items[Equipment[i]].ItemId);                        if (item != null)                        {                                                    classVital += item.VitalsGiven[vital] + Items[Equipment[i]].StatBuffs[23] + item.PercentageVitalsGiven[vital] * baseVital / 100;                                                   }                    }                }            } Â
0 boasfesta Posted September 10, 2021 Posted September 10, 2021 6 minutes ago, mem981 said: thank u! it's work but how to know [vital] is Health or Mana, i want add StatsGiven[23] for Health and SG[24] for Mana  Hide contents for (var i = 0; i < Options.EquipmentSlots.Count; i++)            {                if (Equipment[i] >= 0 && Equipment[i] < Options.MaxInvItems && Equipment[i] < Items.Count)                {                    if (Items[Equipment[i]].ItemId != Guid.Empty)                    {                        var item = ItemBase.Get(Items[Equipment[i]].ItemId);                        if (item != null)                        {                                                    classVital += item.VitalsGiven[vital] + Items[Equipment[i]].StatBuffs[23] + item.PercentageVitalsGiven[vital] * baseVital / 100;                                                   }                    }                }            }   You can just keep the two IFs as you did Not the right way, the best you can do is to create two variables for fixed and percentage values and do the measure at the end, but it would cost more lines. For an easy way you can use inline conditionals just like that: classVital += item.VitalsGiven[vital] + (vital == (int)Vitals.Health ? Items[Equipment[i]].StatBuffs[23] : Items[Equipment[i]].StatBuffs[24]) + item.PercentageVitalsGiven[vital] * baseVital / 100; The conditional (vital == (int)Vitals.Health ? Items[Equipment[i]].StatBuffs[23] : Items[Equipment[i]].StatBuffs[24]) decide which stat use for Health/Mana mem981 1
0 mem981 Posted September 11, 2021 Author Posted September 11, 2021 10 hours ago, boasfesta said:  You can just keep the two IFs as you did Not the right way, the best you can do is to create two variables for fixed and percentage values and do the measure at the end, but it would cost more lines. For an easy way you can use inline conditionals just like that: classVital += item.VitalsGiven[vital] + (vital == (int)Vitals.Health ? Items[Equipment[i]].StatBuffs[23] : Items[Equipment[i]].StatBuffs[24]) + item.PercentageVitalsGiven[vital] * baseVital / 100; The conditional (vital == (int)Vitals.Health ? Items[Equipment[i]].StatBuffs[23] : Items[Equipment[i]].StatBuffs[24]) decide which stat use for Health/Mana I just realized that Stats Given[23] = 0, but Stats Buff[23] has a value in inter.sever/database/item.cs I have set Spoiler descriptor.StatsGiven[23] += 5000; descriptor.StatsGiven[24] += 8000; but StatBuff[23] and [24] has value
0 boasfesta Posted September 11, 2021 Posted September 11, 2021 18 minutes ago, mem981 said: I just realized that Stats Given[23] = 0, but Stats Buff[23] has a value in inter.sever/database/item.cs I have set  Hide contents descriptor.StatsGiven[23] += 5000; descriptor.StatsGiven[24] += 8000; but StatBuff[23] and [24] has value  Maybe its been overwritten by the database i guess? Its hard to know. You need to specify how your system work and what do you expect to do with it. But, why dont you use VitalsGiven/VitalsPercentage for items by default? mem981 1
0 mem981 Posted September 11, 2021 Author Posted September 11, 2021 15 minutes ago, boasfesta said: Â Maybe its been overwritten by the database i guess? Its hard to know. You need to specify how your system work and what do you expect to do with it. But, why dont you use VitalsGiven/VitalsPercentage for items by default? i don't know how to make VitalBuff[] and i'm also afraid it will cause error!
0 mem981 Posted September 11, 2021 Author Posted September 11, 2021 5 hours ago, boasfesta said: Â Maybe its been overwritten by the database i guess? Its hard to know. You need to specify how your system work and what do you expect to do with it. But, why dont you use VitalsGiven/VitalsPercentage for items by default? do i need to add StatsGiven[] in this line??? location (intersect.Server/Database/Item.cs) Â public virtual void Set(Item item) Â Â Â Â Â Â Â { Â Â Â Â Â Â Â Â Â Â Â ItemId = item.ItemId; Â Â Â Â Â Â Â Â Â Â Â Quantity = item.Quantity; Â Â Â Â Â Â Â Â Â Â Â BagId = item.BagId; Â Â Â Â Â Â Â Â Â Â Â Bag = item.Bag; Â Â Â Â Â Â Â Â Â Â Â for (var i = 0; i < (int) Stats.StatCount; i++) Â Â Â Â Â Â Â Â Â Â Â { Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â StatBuffs[i] = item.StatBuffs[i]; Â Â Â Â Â Â Â Â Â Â Â }Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â //My line---------------------------------- Â Â Â Â Â Â Â Â Â Â Â for (var i = 0; i < (int) Stats.StatCount; i++) Â Â Â Â Â Â Â Â Â Â Â { Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â StatsGiven[i] = item.StatsGiven[i]; Â Â Â Â Â Â Â Â Â Â Â }Â Â Â Â Â Â Â Â ///--------------------------- Â Â Â Â Â Â Â } Â
Question
mem981
Hello everyone. I want add new stats 23, 24 to HP and MP, but my code is bug
Every time I die, the amount of max HP and MP is increased, i dont know why, pls help me!
8 answers to this question
Recommended Posts