Page 1 of 1

I'm having alot of wierd reactions from my movement code..

Posted: Thu Nov 11, 2010 10:15 pm
by Exempt
Edit: I just noticed that it's not my code causing the issue. The game is the problem. For some odd reason the coordX is always 100% correct after about 150 tests but coordY is almost never right as the player moves it jump around alot.

I start with the Sleep to make sure my player position variables have a chance to update. tries is just a quick stuck check i made for testing, I'm not sure of a better way to handle that part atm. Don't mind the attack() function..


What i do is use curX to store my player position mtX[] is an array of x coords I want to walk to in order. So, I check where I am and subtract mtX[mt] to get how many spaces i need to move in game. Then i just use this random calcution I made after a stupid amount of test time.

WS is a RECT type that holds my screen size.

Code: Select all

int x = ((WS.right/17-1)*(mtX[mt]-curX-2)+(WS.right/2));
This code seems to work perfect to find where the mouse should move to.

For some reason I'm getting a ton of crazy jumping around and stuff that is no where close to where i need to be and i'm not sure why.

Code: Select all

void movePlayer(int mtX[], int mtY[], int delay) 
{
    Sleep(400);
    int curX = memReadInt(playerX);
    int curY = memReadInt(playerY);
	
	if (tries < 3) 
	{
        if(tries <= 2)
            attack(250);
        if((curX - mtX[mt]) < 3 and (curX - mtX[mt]) > -3 and (curY - mtY[mt]) < 3 and (curY - mtY[mt]) > -3)
	    {
            tries = 0;
            if(mt > (sizeof(desX) / sizeof(desX[0])-2))
                mt = 1;
            else
                mt++;
         }   
         //Sleep(300);
         int x = ((WS.right/17-1)*(mtX[mt]-curX)+(WS.right/2));
	     int y = ((WS.bottom/13-1)*(mtY[mt]-curY)+(WS.bottom/2));
         cout<<"MT: " << mt << " curX: " << curX << " mtX[mt]: " << mtX[mt] << " curY: " << curY << " mtY[mt]: " << mtY[mt] << " tries: " << tries << endl;
         
         moveMouse(x, y, 1);
         pressKey(castTrans, 50);
         leftClick(50);
         tries++;
    }else{
         //Sleep(300);
         int x = ((WS.right/17-1)*(mtX[mt]-curX-2)+(WS.right/2));
         int y = ((WS.bottom/13-1)*(mtY[mt]-curY-2)+(WS.bottom/2));
         cout<<"MT: " << mt << " curX: " << curX << " mtX[mt]: " << mtX[mt] << " curY: " << curY << " mtY[mt]: " << mtY[mt] << " tries: " << tries << endl;
         moveMouse(x, y, 1);
         pressKey(castTrans, 50);
         leftClick(50);
         tries = 0;
    }
         
}

Re: I'm having alot of wierd reactions from my movement code

Posted: Fri Nov 12, 2010 7:20 pm
by Administrator
Can you reduce the code down any further and/or be more specific about exactly where the variable is wrong?

Is it right or wrong after this line executes?

Code: Select all

    int curY = memReadInt(playerY);

Re: I'm having alot of wierd reactions from my movement code

Posted: Sat Nov 13, 2010 8:01 pm
by Exempt
Sorry, I was to slow with my edit I guess. The problem was in the way the client handle the player coord variables. It had 2 varibles that seemed to = the same thing all the time when infact one way for the destination the other was the accual position of my player. I hadn't noticed this at all...tooks me almost a year to see it lol... I have the positions working 100% now.