Command & Conquer: Tiberian Sun - WASD Map scrolling

Post gaming related scripts
Noitalommi_2
Posts: 224
Joined: 16 Aug 2023, 10:58

Command & Conquer: Tiberian Sun - WASD Map scrolling

Post by Noitalommi_2 » 11 Jan 2024, 10:29

Hi.

(I wasn't happy with the original script from here, so I improved it for the 3 people playing this game. ^^)

This script enables 8-directional map scrolling with keys, wasd is the preset for scrolling, however, other keys can also be used.
I also added the ability to adjust the scrolling speed using the mouse wheel while scrolling.

If scrolling is too fast, set the scroll speed to low in-game. The scrolling speed also depends on the resolution, thats why the script determines the game resolution.
Otherwise there isn't much to tell.The script waits until the game runs and exits itself when the game is closed.

Since this script uses BlockInput, I added an exit with F4, just in case.

Code: Select all

#Requires AutoHotkey >=2.0
#SingleInstance

ScrollSpeed := 0.3

Key := Map("Up"   , "w",
		   "Down" , "s",
		   "Left" , "a",
		   "Right", "d")

For , Key in Key
	Hotkey Key, (*) => false

RButton := false

CoordMode("Mouse", "Client")
WinWaitActive(Title := "ahk_class Tiberian Sun")
Loop
	Sleep(1000),WinGetPos(,,&CX, &CY, Title)
until CX >= 800 && CY >= 600

S := [r := CX*ScrollSpeed/10, r]
CX //= 2, CY //= 2

Loop {

	Sleep 100
	Count := 0
	For ,Key_ in Key
		if GetKeyState(Key_) && WinActive(Title) {

			if !GetKeyState("RButton") {
				BlockInput "MouseMove"
				MouseMove(CX, CY), Sleep(10)
				SendEvent("{RButton down}"), RButton := true
			}

			if GetKeyState(Key["Up"], "P") && GetKeyState(Key["Right"], "P")
				MouseMove(CX+S[1], CY-S[1])
			else if GetKeyState(Key["Up"], "P") && GetKeyState(Key["Left"], "P")
				MouseMove(CX-S[1], CY-S[1])
			else if GetKeyState(Key["Down"], "P") && GetKeyState(Key["Right"], "P")
				MouseMove(CX+S[1], CY+S[1])
			else if GetKeyState(Key["Down"], "P") && GetKeyState(Key["Left"], "P")
				MouseMove(CX-S[1], CY+S[1])
			else if GetKeyState(Key["Up"], "P")
				MouseMove(CX, CY-S[1])
			else if GetKeyState(Key["Down"], "P")
				MouseMove(CX, CY+S[1])
			else if GetKeyState(Key["Left"], "P")
				MouseMove(CX-S[1], CY)
			else if GetKeyState(Key["Right"], "P")
				MouseMove(CX+S[1], CY)
		}
		else Count++

	if GetKeyState("RButton") && Count = 4 && RButton = true {
		SendEvent("{RButton up}"), RButton := false
		BlockInput "MouseMoveOff"
	}
	if !WinExist(Title)
		ExitApp
}
F4::ExitApp
#Hotif RButton
*LButton::return
*RButton::return
*WheelUp::S[1] += S[1] >= S[2]*2 ? 0 : S[2]/10, Sleep(125)
*WheelDown::S[1] -= S[1] <= S[2]*0.4 ? 0 : S[2]/10, Sleep(125)

Return to “Gaming”