I need some help regarding the code.
Problem is about walking to mob/monster. It walks perfect with 0x15 packet. Symptom is that at first few packets are good, so it does actually moves to the monster's position (distance is reducing).
But after few moves, suddenly the distance (difference between my x, y and monster's and vica versa) is larger than 1 packet sent before (distance is increasing). Wierd???
Here's a SS of my problem (note i print my numbers with %f )
*posted at bottom
I've tried using this tip below, but that part (Player[0].X+=tempx; Player[0].Y+=tempy; ) crashes engine:
Here are snippets of my code:Quote:
PHP Code:int WalkToMob(int target){
while(true){
difx=Mob[target].X-Player[0].X;
dify=Mob[target].Y-Player[0].Y;
range=((difx*difx)+(dify*dify))*1.0;
/*ATTACK IT*/
if (sqrt(range) < 33.0)
{
printf("Attack!\n");
return 2;
}
else
{
tempx=((difx)/sqrt(range))*32;
tempy=((dify)/sqrt(range))*32;
tempz = (MyHeightDetour(Something(Player[0].X+tempx,0x20),Something(Player[0].Y+tempy,0x20))*10)-Player[0].Z;
PacketSend(0x12,"bbb",tempx,tempy,tempz);
Player[0].X+=tempx;
Player[0].Y+=tempy;
Player[0].Z+=tempz;
//printf("%d %d\n",Player[0].X,Player[0].Y);
if(Mob[target].X == 0)
{
return 1;
}
Sleep(600);
}
}
}
MOB SEARCH:
PHP Code:
int SearchMob()
{
//Kal::ChatBox( "[Lungi]: ",4,"start");
int i = 0;
while( true )
{
Sleep(10);
int nearest = 1100;
int id = -1;
for ( i = 0 ; i < 100 ; i++ )
if ( ( Monster[i].X +1500 > Player1[0].X ) && ( Monster[i].X -1500 < Player1[0].X ))
{
Sleep(10);
// Kal::ChatBox( "[Lungi]: ",5,"found");
int difx =Monster[i].X - Player1[0].X;
int dify = Monster[i].Y - Player1[0].Y;
float Range=((difx*difx)+(dify*dify));
float Mobrange= sqrt(Range);
// Kal::ChatBox( "[Lungi]: ",4,"Range start is: %d",Mobrange);
Sleep(500);
if ( nearest > Mobrange )
{
id = i;
nearest = Mobrange;
//Kal::ChatBox( "[Lungi]: ",4,"mob near");
}
Sleep(100);
}
if ( id != -1 )
{
target = id;
return 1;
}
Sleep(90);
}
}
PHP Code:
int WalkToMob(int targetx){
bool forward = true;
// int moves = 0;
while(forward)
{
Sleep(20);
Kal::ChatBox( "[Lungi]: ",4,"walking");
int difx = Monster[ targetx ].X - Player1[0].X;
int dify = Monster[ targetx ].Y - Player1[0].Y;
//Kal::ChatBox( "[Lungi]: ",4,"Difference is: X: %d , Y: %d",difx,dify);
Sleep(100);
float Range=((difx*difx)+(dify*dify))*1.0;
float distance=sqrt( Range );
Kal::ChatBox( "[Lungi]: ",4,"distance is: %f ",distance);
Sleep(50);
if( Monster[ targetx ].X == 0)
{
forward = false;
return 1;
//Kal::ChatBox( "[Lungi]: ",4,"mob is shit");
}
if (distance > 35.0)
{
// Kal::ChatBox( "[Lungi]: ",6,"we WILL move");
unsigned char tempx = (( difx ) / sqrt( Range )) * 32;
unsigned char tempy = (( dify ) / sqrt( Range ) ) * 32;
Sleep(200);
SendKoemV2(0x15,"bbb",tempx,tempy,0);
// Player1[0].X+=tempx;
// Player1[0].Y+=tempy;
// Kal::ChatBox( "[Lungi]: ",2,"sending move packet");
[B] int minus = 0;
if (tempx < 128)
{
Player1[0].X += tempx;
}
else
{
if (tempx > 128)
{
minus=tempx - 256;
Player1[0].X += minus;
}
}
if (tempy < 128)
{
Player1[0].Y += tempy;
}
else
{
if (tempy > 128)
{
minus=tempy - 256;
Player1[0].Y+= minus;
}
}
}[/B]
else
{
Sleep(100);
forward = false;
return 2;
// Kal::ChatBox( "[Lungi]: ",4,"range is good, proceed attack");
}
}
// Kal::ChatBox( "[Lungi]: ",4,"failed loop");
//return 1;
}
I would appriciate any tip, suggestion, perhaps solution to my problem, if that's possible. I use these props on KoemV2 protected game.






