[Release]Level Based CP Drop

04/18/2011 01:50 hyperco#1
Everyone saw the cp drop system created by walmartboi, so i get the code and maked it according to character's level. (VERSION 5165)

Code:
if (MyMath.ChanceSuccess(100))
                {
                    string acc = "";
                    int CpBase = 1000; // Default Cp drop, i mean lvl 1 :P
                    double cprandomdrop = (Convert.ToDouble(MobTarget.Level) / Convert.ToDouble(Char.Level)) * CpBase;
                    if (MyMath.ChanceSuccess(cprandomdrop))
                    {
                        int cpToAdd = cprandomdrop / Char.Level;

                        Char.CPs += Convert.ToUInt32(cpToAdd);
                        Char.MyClient.LocalMessage(2005, "[CPs] You have gained: " + cpToAdd + " CPs for killing a(n) " + MobTarget.Name + " at your current level.");
                        Database.SaveCharacter(Char, acc);
                    }
But it give me Server crashes, and i found not any problem on this code :/
if someone can finish it better, ill be very grateful.
remembering, its a base (and based) code for cpsdrop system.

If i get new code lines for this, ill update this post.
04/18/2011 02:52 pro4never#2
Why not just use the one I wrote that takes into account random chance + monster levels?


Someone already upgraded it to work with 5165 lotf lol.

Not sure what would be causing your error just at first glance but couple concerns...

(Convert.ToDouble(MobTarget.Level) / Convert.ToDouble(Char.Level)) * CpBase

You're going to come up with some funky values...

Mob Level 83 (birdmen examples)
Character level 120 (random hunter)
CpBase 1000

Chance for drop is... 83/120 * 1000

Aka 691.6666666666667

So you're saying there's a 700 percent chance of an item dropping from that monster...

You need to think through your values (ALL possibilities) and take that into account.

Do a simple try/catch catch on the code and print out the exception and see if it comes up with anything... the alternative is that your database save code is freezing the server (wouldn't be surprised with lotf lol)
04/18/2011 05:19 hyperco#3
lol man, i forgot to using try an catch, thx pro...

ill try to solve my problem :P
04/20/2011 13:47 iStefan#4
Why saving account each CP Drop? It will lag out as f*ck.
Also you might get an exception for using the Save Void two times at once.
04/20/2011 16:58 _DreadNought_#5
Check impulses source guys, seriously.

Update each value as its changed.

Update all values when only one has changed == false;
Update the value that changed when its changed == true;
04/20/2011 17:06 -Shunsui-#6
this can be like 1 line? use the C# math class
04/22/2011 16:13 hyperco#7
i guess that impulse source will have a better support to these codes....
04/23/2011 11:07 xElement#8
Quote:
Originally Posted by _DreadNought_ View Post
Check impulses source guys, seriously.

Update each value as its changed.

Update all values when only one has changed == false;
Update the value that changed when its changed == true;
Jesus para, get Impulse out of your vagina.