Your walk function

10/12/2023 15:18 RainbowJ#1
#Solved
10/14/2023 13:02 JONNST4R#2
Hey,
can u add comments to your code to help us to understand what you try to do at which point. But i can tell your distance is wrong because you dont know the player position only the goto position and you dont know if the player is moving or not (there is a memory flag).
10/14/2023 19:21 RainbowJ#3
Quote:
Originally Posted by JONNST4R View Post
Hey,
can u add comments to your code to help us to understand what you try to do at which point. But i can tell your distance is wrong because you dont know the player position only the goto position and you dont know if the player is moving or not (there is a memory flag).
Hello! Thank you for your comment.
I know the player position, receiving the "at" packet when i change map, or when i start the bot, just moving the player, with the first "walk" packet that i receive moving the player normally via client.

The code commented:

Code:
Func GoTo($x2, $y2)
	$x1 = $Me[0]   ;My current x position
	$y1 = $Me[1]    ;My current y position
	Dim $x2Iniz = $x2   ;Saving the x destination
	Dim $y2Iniz = $y2   ;Saving the y destination
;##########################################
;That just calcolate the best destination point
While ( ($x1 <> $x2) Or ($y1 <> $y2) )
	$x1 = $Me[0]
	$y1 = $Me[1]


	$WalkDistance = Sqrt( Abs($x1 - $x2)^2 + Abs($y1 - $y2)^2 )

	While ($WalkDistance > 6)

			If ($x1 > $x2) Then
			If($y1 > $y2) Then
				$x2=$x2+1
				$y2 = $y2+1
			ElseIf($y1 < $y2) Then
				$x = $x2+1
				$y2 = $y2-1
			Else
				$x2 = $x2+1
			EndIf
		ElseIf ($x1 < $x2) Then
			If($y1 > $y2) Then
				$x2 = $x2-1
				$y2 = $y2+1
			ElseIf($y1 < $y2) Then
				$x2 = $x2-1
				$y2 = $y2-1
			Else
				$x2 = $x2-1
			EndIf
		ElseIf ($x1 = $x2) Then
			If($y1 > $y2) Then
				$y2 = $y2+1
			Else
				$y2 = $y2-1
			EndIf
		EndIf
	$WalkDistance = Sqrt( Abs($x1 - $x2)^2 + Abs($y1 - $y2)^2 )
	WEnd
;##########################################


		If Mod($x2 + $y2,3) == 1 Then ;The walk packet wants 1 in the parameter if destionation's (x+y) % 3 == 1
		PacketLogger_SendPacket($PacketLogger_OpenSockets[0], "walk " & $x2 & " " & $y2 & " 1 16")
		Else
		PacketLogger_SendPacket($PacketLogger_OpenSockets[0], "walk " & $x2 & " " & $y2 & " 0 16")
EndIf
;Resetting starting destination's x and y 
		$x2 = $x2Iniz
		$y2 = $y2Iniz
;just tracking movement
		ConsoleWrite($x1 & " " & $y1)
		Sleep(600)
		PacketLogger_Handle($PacketLogger_OpenSockets[0], IncomingPacket) ;Receive eventual packets
		Sleep(600)
		;tp 1 myID 142 1 0 
;Receive the "tp" packet, just to show me in the destination
		PacketLogger_RecvPacket($PacketLogger_OpenSockets[0], "tp 1 "& id & " " & $Me[0] & " " & $Me[1])
		
;Just debugging
		;ConsoleWrite( "walk " & $x2 & " " & $y2 & " 0 11")
WEnd

EndFunc


Quote:
Originally Posted by JONNST4R View Post
you dont know if the player is moving or not (there is a memory flag).
Why should i not be moving after sending a walk packet?
10/14/2023 19:56 JONNST4R#4
Im sorry i dont use packets, I have some questions about them.
  1. Is there a packet, if you get a debuff like stun/blackout that makes you stop moving?
  2. Can u get the current player position all the time with the "at" packet?
10/14/2023 23:49 Limoo#5
Quote:
Originally Posted by JONNST4R View Post
Im sorry i dont use packets, I have some questions about them.
  1. Is there a packet, if you get a debuff like stun/blackout that makes you stop moving?
  2. Can u get the current player position all the time with the "at" packet?
The "at" packet gives you your exact coordinates however you only receive it when you change maps.

Quote:
Originally Posted by RainbowJ View Post
Why should i not be moving after sending a walk packet?
The "walk" packet is not accurate because it gives you the next cell at a distance of 4 (I think) and the final one if it is closer.
If you have to do 10 walk cells then it will give you the coordinates of cells 4, 8 and 10.

To emulate the packet walk you have to rely on the character's speed, so you know how many cells he can do in a given amount of time.
For the speed you can see the "cond" packet.

If you use the packet and not the game function for walking you will also have to use the "tp" packet to move the camera to the player's actual position (it's clientside, others see you walking).
10/18/2023 08:56 Diartios#6
Quote:
Originally Posted by JONNST4R View Post
Im sorry i dont use packets, I have some questions about them.
  1. Is there a packet, if you get a debuff like stun/blackout that makes you stop moving?
  2. Can u get the current player position all the time with the "at" packet?
about your first question check "cond" packet

cond entity_type entity_id cantattack cantwalk speed
10/23/2023 17:48 Apourtartt#7
Hey!

The logic implemented (checking for the position of the point, etc) will be fine if you don't have any obstacles. If you have an obstacle, you will need to implement a pathfinding algorithm, you can use A* which will be perfect for your use case.
Here is an example in C++: [Only registered and activated users can see links. Click Here To Register...]
Also you might be interested in a way to check for the "line of sight" (not willing to attack behind an obstacle, even thought the server will accept the request), the algorithm is: [Only registered and activated users can see links. Click Here To Register...]

Regarding the other details, you should walk not one cell by one cell but follow this formula: [Only registered and activated users can see links. Click Here To Register...]
As an example, if you have a speed of 10 (an adventurer without any speed boost), you will have to walk a distance of 3, which means that if you are walking in a straight line from 10;10 to the bottom, you will send walk 10 13. If you go to the lower right corner, you will not send walk 13 13 (because you will travel a distance of 4.25, (3²+3²)^0.5) but most probably walk 12 12 ((2²+2²)^0.5 is the latest value before exceeding a distance of 3).
Regarding the delay between each walk, you must follow this formula: [Only registered and activated users can see links. Click Here To Register...]
but use the actual distance traveled, not the calculated one, in the example with walk 12 12, you walk a distance of (2²+2²)^0.5=2.83, you have a speed of 10, so you must send the next walk not earlier than 2.83*2500/10=707ms.

You also need to follow two other things:
- you should not walk when you cannot (it was possible to walk while being stunned, but I think it has been patched) - so check for cond packet (rooted) and whether or not the character is alive
- you should listen to the tp packet - even though this implementation would make your walking algorithm really accurate and trustful, you might get a lag (in that case, the tp packet should restart your walk algorithm from the new position) but also, you might just get teleported