I Request help for Age of Empires 2 DE very specific and famous problem... Topic is solved

Ask gaming related questions (AHK v1.1 and older)
phalanxdarken
Posts: 5
Joined: 02 Jan 2022, 16:11

I Request help for Age of Empires 2 DE very specific and famous problem...

02 Jan 2022, 19:25

Hi everyone, Mike here...

I will go straight to the point: Iam trying to create my own "inverted mouse drag camera move" AHK script for the game Age of Empires 2 definitive edition. This game does not include a MODERN camera move system like other RTS or MOBAs like League of Legends or Dota 2 where you just click and drag the camera with the Right Click in the ground working as an anchor. Instead they provide a trash and unuseful drag system that nobody likes - BTW in this game you can control the camera with the arrow keys like other many games, but this is very unconfortable for most ppl.

What I want, is like "Change movement to scroll" but instead, "Change movement to simulated keys" where I can specify a key sequence to send depending on the direction I move the mouse while a desired button is being pressed. This way when I click and drag, the script will simulate Keyboard directional arrow keys UP DOWN R or L and then I will be able to move the camera without blocking the original function for that click ( R click gives a character the order to walk to that point. Iam embedding a video here for example purpouses:

https://imgur.com/a/qTIjh5r

This is my little analisis and iam not so good at programming, But Iam sure that a lot of Aoe2DE players could be benefit using a script like this. If you can help me please share your opinions or send me a PM.

Thank you everybody in advance :superhappy:
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: I Request help for Age of Empires 2 DE very specific and famous problem...  Topic is solved

02 Jan 2022, 22:35

phalanxdarken wrote:
02 Jan 2022, 19:25
Hi everyone, Mike here...
...........
Hello, I write this code when I was playing construction simulator 2015, to control the crane or some other machines you need to let go of the mouse and use the arrows keys, so I made this to help play with the mouse all the time.

I made some modification to it, try it and let me know if its works!
Code

Rename the picture file to "Guid.png" and put it next to the script file.
Image
:wave: There is always more than one way to solve a problem. ;)
phalanxdarken
Posts: 5
Joined: 02 Jan 2022, 16:11

Re: I Request help for Age of Empires 2 DE very specific and famous problem...

02 Jan 2022, 23:30

@YoucefHam

Hi friend, let me thank you for your answer, I think the solution was very close until now. 2 things:

1- I don't want to hold SHIFT anytime I want to scroll the camera, I need it to be ALWAYS ON, just R click without interfering / blocking the original R click function (which is used for ordering the units to walk that point).

2- The behaviour of this script you have coded makes the cursor start to move when it reach any border of the Orange Symbol, (I don't know if it is neccesary for the Script) but I need it to be very smaller, and no existent if it is possbile because what I want is to start the movement at the same time I R click in any point of the screen, using the script right now takes a long time for activate movement due to the distance the cursor must travel. Maybe we can set that GUID to be so small that it is only neccesary to move a little, only a little for camera scroll activation, this way we avoid accidental movement too - missclick. Now it takes too long and when playing, I need more agility and fast movements.

Iam happy that your solution was very close to what I want to achieve, I'll wait for your answer :D
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: I Request help for Age of Empires 2 DE very specific and famous problem...

03 Jan 2022, 00:11

phalanxdarken wrote:
02 Jan 2022, 23:30
Hi friend, let me thank you for your answer, I think the solution was very close until now. 2 things:
..............
I change the script to start the GUI when you hold right mouse button, and if you click the right mouse button it should work as normal.
try this, and try to change this variables as you like.

KeyPressPerSec := 3 ;###### Change how many key press rep 1 second
DeadZone := 20 ;###### Mouse lock position from center
MinDist := 5 ;###### Min distance to start the keys


Code
:wave: There is always more than one way to solve a problem. ;)
phalanxdarken
Posts: 5
Joined: 02 Jan 2022, 16:11

Re: I Request help for Age of Empires 2 DE very specific and famous problem...

03 Jan 2022, 02:51

@YoucefHam

We are almost there sir! you are a genious :D

I modified only the number values adjusting towards my comfort and it fells a lot more natural than before, setting the delay to 0 was one of the best decisions because now the scrolling starts inmediately. i am sorry that I don't know programming, I try to do my best.

Now what remains is to give a "higher preference" to UP DOWN R and L because the natural hand drag always tends to slide to the diagonals. I assume we can achieve this giving greater range to the 4 most important directions (North, East, South and West) so that when you slide with the mouse in form of (X) you have to make more travel or movement towards the diagonals when you want to go towards these directions intentionally and not accidentally. This is a little hard to explain with words so there's a video showing how hard is to keep the scroll in form of (Cross +), I literally have to move my hand like a robot haha.

Also i wanted to ask you how to remove (make invisible) that orange symbol GUID or at least change the color to white and more transparent.

Video HERE:

https://kapwi.ng/c/vEdTIVVeij

Updated code:

Code: Select all

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Screen
SetKeyDelay, 0, 0
#SingleInstance Force


KeyPressPerSec := 0  ;###### Change how many key press rep 1 second
DeadZone := 15       ;###### Mouse lock position from center
MinDist := 3         ;###### Min distance to start the keys

Gui, Add, Pic, -0x20 w50 h50 vPic, Guid.png
Gui, Color, #E0FFFF
Gui, +LastFound
winset, transcolor,#000000
Gui, +AlwaysOnTop -Caption -Border -Sysmenu +ToolWindow
return

;Hold Right mouse button to start
$RButton::
KeyWait, RButton, T0.15
if !ErrorLevel
{
	Send, {RButton Down}
	Sleep, 62
	Send, {RButton Up}
	return
}
Send, {Blind}
MouseGetPos, x0, y0
Gui,+LastFound +AlwaysOnTop
Gui, show, % "x" x0 - 34 " y" y0 - 34 " NoActivate", hhh
WinSet, ExStyle, +0x20, hhh

StartTime := A_TickCount
Loop
{
	;###### Keep mouse in center of the Guide
	MouseGetPos, x, y
	if (y - y0) > DeadZone
		MouseMove, % x, % y0+DeadZone
	else if (y - y0) < -DeadZone
		MouseMove, % x, % y0-DeadZone
	if (x - x0) > DeadZone
		MouseMove, % x0+DeadZone, % y
	else if (x - x0) < -DeadZone
		MouseMove, % x0-DeadZone, % y
	;###### Keep mouse in center of the Guide
	
	
	;###### Calculate the key press
	if (ElapsedTime > 1000 / KeyPressPerSec)
	{
		if Abs(y0 - y) >= MinDist
		{
			if (y0 - y) < 0
			{
				Send, {Blind}{Up Up}
				Send, {Blind}{Down Down}
			}
			else
			{
				Send, {Blind}{Down Up}
				Send, {Blind}{Up Down}
			}
		}
		else
		{
			Send, {Blind}{Down Up}
			Send, {Blind}{Up Up}
		}
		if Abs(x0 - x) >= MinDist
		{
			if (x0 - x) > 0
			{
				Send, {Blind}{Right Up}
				Send, {Blind}{Left Down}
			}
			else
			{
				Send, {Blind}{Left Up}
				Send, {Blind}{Right Down}
			}
		}
		else
		{
			Send, {Blind}{Left Up}
			Send, {Blind}{Right Up}
		}
		StartTime := A_TickCount
	}
	;###### Calculate the key press
	Sleep, 10
	ElapsedTime := A_TickCount - StartTime
}until !GetKeyState("RButton","P")
Send, {Blind}{Down Up}
Send, {Blind}{Up Up}
Send, {Blind}{Left Up}
Send, {Blind}{Right Up}
Gui, Cancel
return
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: I Request help for Age of Empires 2 DE very specific and famous problem...

03 Jan 2022, 14:07

phalanxdarken wrote:
03 Jan 2022, 02:51
We are almost there sir! you are a genious :D
.................

Hi, :D glade its working, I added some extra option for you to change so you will be comfortable with it.


KeyPressPerSec := 3 ;###### Change how many key press rep 1 second (use number bigger than or equal to 1)
DeadZone := 20 ;###### Mouse lock position from center

MinDist := 4 ;###### Min distance to start the keys
MinDistUpDown := 0 ;###### add extra distance to start the keys up/down
MinDistRightLeft := 10 ;###### add extra distance to start the keys right/left

UseGUI := 1 ;###### Change to 1 to use GUI
invertUpDown := 1 ;###### Change to 1 to invert up/down
invertRightLeft := 1 ;###### Change to 1 to invert right/left


Code
:wave: There is always more than one way to solve a problem. ;)

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 33 guests