C# Calculating sp/min&hour

04/10/2011 20:19 Janick_#1
Hey guys,

I've been trying to figure out for some days already why my code isn't working. I still can't figurue out why it isn't working ...

Here is the formula i use and also the source


Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace ReadMemory_GUI_
{
    public partial class Form1 : Form
    {
        int currentsp;
        int startingsp;
        int sptotal;
        int sec = 0;



        public Form1()
        {
            InitializeComponent();





        }


        private void timer1_Tick(object sender, EventArgs e)
        {

            Memory mem = new Memory("sro_client");


            string charactername = mem.ReadString(0xF9E9B8);
            string servername = mem.ReadString(0xF9E8B8);
            string[] lines = System.IO.File.ReadAllLines("exp.txt");
            int maxhp = mem.ReadOffset(0xFB970C, 0x460);
            int curhp = mem.ReadOffset(0xFB970C, 0x468);
            currentsp = mem.ReadOffset(0xFB970C, 0x888);
            int maxmp = mem.ReadOffset(0xFB970C, 0x464);
            int curmp = mem.ReadOffset(0xFB970C, 0x45C);
            int currentexp = mem.ReadOffset(0xFB970C, 0x878);
            int lv = mem.ReadOffset(0xFB970C, 0x874);
            decimal lving = (((decimal)currentexp / decimal.Parse(lines[lv - 1])) * 100);


            label1.Text = "CharacterName:" + charactername;
            label2.Text = "Maximum HP:" + maxhp;
            label3.Text = "Current HP:" + curhp;
            label4.Text = "Maximum MP:" + maxmp;
            label5.Text = "Minimum MP:" + curmp;
            label6.Text = "Skill Points:" + currentsp;
            label7.Text = "Exp:" + lving.ToString("f2") + "%";
            label8.Text = "Level:" + lv;
            label9.Text = "Server:" + servername;

        }
        public void Main()
        {
            startingsp = currentsp;
        }

        public void timer2_Tick(object sender, EventArgs e)
        {

            sptotal = currentsp - startingsp;
            sec++;
            int spmin = ((60 * sptotal) / sec);
            int sphour = ((3600 * sptotal) / sec);
            label10.Text = "SP/min:" + spmin;
            label11.Text = "SP/hour:" + sphour;
            label12.Text = "Value:" + sec;
        }
    }
}

I've tried tons of things already. I hope anyone can help me out..:rolleyes:
04/11/2011 08:56 kevin_owner#2
Oke well I don't know how C# exactly works I can read the code but I don't know the details but i'll try to help you.

This is how I should create this tool:

Well uuhm idk how exactly memory reading works but I suppose that your way works:)

Uuhm well I should create some kind of timer which checks the sp like every 5 seconds(you could also create a trigger but an timer is easier I guess).

well like you already did you got an starting sp and the current sp so the way you're doing it might work but you need to have some timer which updates the sp every 5 seconds and also updates the labels on your form. Idk if this is the whole code cause you're not using any of the "timer" functions but I guess that's just cause you were testing stuff:)
04/11/2011 13:20 Janick_#3
It gets updated every 0.3 sec already, i only took startingsp = currentsp; out of the timer becuase the starting sp dont need to be updated.
04/11/2011 13:41 kevin_owner#4
Oke so if it updates every 0.3 sec you increase the integer sec also every 0.3 seconds am I correct?

btw what doesn't work about this code? is it the output or is it just the whole code? also try to set some breakpoints to see where things gets messed up:P
04/11/2011 14:53 Janick_#5
I've got 2 timers, for MP,HP, current sp and exp it gets updated every 0.3 sec, the other timer updates every 1 sec , every 1 sec the value gets increased.

And it shows, well the number are way to big , it shows like something 250213sp/min or so.
04/11/2011 15:20 kevin_owner#6
hmm. Well I don't know about timers ect in C# so I assume that those are correct. Did you also check the startingsp if those values are correct and the currentsp which gets udpated every second? mabye log them into an file to check if they increase properly.

But just a little notice which doesn't affect the code but it looks cleaner if you write the calculations like this.

(sptotal / sec) * 60

this way you can easly see what you're doing cause now i had to look what you were doing cause i was like hmm oke 60 well those are the seconds and then he divides them with the sec so it was a littel confusing:)

So you could try to take a look at the values of the startingsp and the currentsp to see if those are correct cause I assume that those values aren't correct.
04/11/2011 15:40 Janick_#7
Hmm, ye i think it was the startingsp.. anyway another problem

Why do i sometimes get this, sometimes i don't get it and sometimes i do and bleh its annoying and i dunno what is causing it. :

[Only registered and activated users can see links. Click Here To Register...]

EDIT: its the Level: not showing the right value for some reason ..
04/11/2011 16:02 kevin_owner#8
Well it's caused by bad reading of the exp file:)

mabye you could add a check to vervy that the number of lines are correct:) I guess that it has to be 140 so if it fails reading the file you get and out of index error:)

So just check if the numer of lines are equal or larger than 140. But If i were you I would read the file into an list with some objects at the main_load so you only read it it once and then you're done. now you read it everytime you launch the timer1_tick.
04/12/2011 09:57 lesderid#9
lv-1 is too low/high.