PDA

View Full Version : Defenstar and autohotkey script problem



Keyser_Soze
06-07-2011, 11:01 AM
Hi,

I am trying to get the PC Defenstar game to work the same way as my Mame Defender game.

Joystick for up and down
Key beside joystick for reverse
key for thrust and a key for fire.

I can set the U360 to 2 way up and down through the main HyperLaunch script. I also create a separate defenstar.exe (autohotkey script) to map other keys and launch the game through the exe script via the game .lnk file
as loppydog suggested.

The script can toggle the ship's direction (using the button near the joystick)

I have some more code in a loop that checks for direction and either sends an {Left} or {Right} Key. This way I can us the same key to thrust in the correct direction. This works too but

- I Either send to many keys with let's say Send {Left 30} causing a lag if I try to change direction using the toggle direction button. The toggle waits for the send buffer to empty out.

or

- I try Send {Left} but it does not trigger often enough causing my ship to fly slower. I have fiddled with the loop sleep setting it both low and high and no cigar

No matter what I have tried, I can't get it to play right.

Anyone out there who has seen something similar. I'll attach the script later since I'm not at home right now.

Thanks
Marc

Keyser_Soze
06-10-2011, 05:39 AM
Here's the code I mentioned. Hope this helps since the truth is always in the code. Thanks.

Executable = defenstar

;**************************************
BlockInput, on
SetKeyDelay , 50, 50

BlockInput, off
Run, %Executable%.exe, , Max
sleep, 1000
Process, Waitclose, %Executable%.exe
BlockInput, on

;********Refresh Resloution***********
WinActivate, HyperSpin
WinMaximize, HyperSpin
Sleep, 500
WinActivate, HyperSpin
;************************************

ExitAPP
return

;***********Key Changes****************

r = 1

loop
{
$d:: ; used to reverse direction
if (r = 1)
{
r = 0
Send {Left}
}
else
{
r = 1
Send {Right}
}


$b:: ; thrust either left or right depending on above direction
if (r = 1)
{
Send {Right}
; tried Send {Right 20}
}
else
{
Send {Left}
; tried Send {Left 20}
}

sleep 5
; tried various sleep amounts

return
}


$End::
Process, Close, %Executable%.exe
Process, WaitClose, %Executable%.exe
return

chillinwater
06-10-2011, 01:57 PM
one step closer but not quite there yet.
If you hold down "thrust"- "b" and release then you slow down to a stop.
If you tap "b" thrust stays on until you hold down and release again.
So still needs some work

changes made


#InstallKeybdHook ;i put this at the top of your script

$b:: ; thrust either left or right depending on above direction
if (r = 1)
{
Send {Right Down}
GetKeyState, State_b, b , P
if State_b = U
Send {Right Up}
Return
; tried Send {Right 20}
}
else
{
Send {Left Down}
GetKeyState, State_b, b , P
if State_b = U
Send {Left Up}
return
; tried Send {Left 20}
}

sleep 5
; tried various sleep amounts

Keyser_Soze
06-13-2011, 05:22 AM
Hi Chillinwater,

Thanks for your help with this. It seems to work better now except there is still up to a 1 second delay when switching directions when 'd' is pressed. Not sure why the 'd' press doesn't trigger immediately. I may just fall back to using the joystick for all directions.

#InstallKeybdHook ;i put this at the top of your script

Executable = defenstar

;**************************************
BlockInput, on
SetKeyDelay , 50, 50

BlockInput, off
Run, %Executable%.exe, , Max
sleep, 1000
Process, Waitclose, %Executable%.exe
BlockInput, on

;********Refresh Resloution***********
WinActivate, HyperSpin
WinMaximize, HyperSpin
Sleep, 500
WinActivate, HyperSpin
;************************************

ExitAPP
return

;***********Key Changes****************

loop
{
$d:: ; used to reverse direction
if (r = 1)
{
r = 0
Send {Left}
}
else
{
r = 1
Send {Right}
}


$b:: ; thrust either left or right depending on above direction
if (r = 1)
{
Send {Right Down}
GetKeyState, State_b, b , P

if State_b = U
Send {Right Up}

return
}
else
{
Send {Left Down}
GetKeyState, State_b, b , P

if State_b = U
Send {Left Up}

return
}

sleep 5
return
}

$End::
Process, Close, %Executable%.exe
Process, WaitClose, %Executable%.exe
return

chillinwater
06-18-2011, 11:13 PM
Try with this:
SetKeyDelay , 25, 25

its somewhat better, "d" takes affect quicker.
Other settings may be even more desirable.

I still dont like the thrust (tap or hold) I mean it gets going quick but doesnt slow down very quick (but it is a little quicker now).

I guess you have to suspend belief and imagine its inertia or forward momentum lol. :D
Also could be thought of as a way to increase the difficulty...realism mode!

Keyser_Soze
06-20-2011, 09:56 AM
After putzing around with this a bit more than is healthy, I came up with this thanks to chillinwater's help. It seems to work pretty much as I would like it too and now plays the same way as mame defender.

It's a pretty decent game. You guys should check it out.

Thanks.

#InstallKeybdHook ;i put this at the top of your script

Executable = defenstar

;**************************************
BlockInput, on
SetKeyDelay , 50, 50

BlockInput, off
Run, %Executable%.exe, , Max
sleep, 1000
Process, Waitclose, %Executable%.exe
BlockInput, on

;********Refresh Resloution***********
WinActivate, HyperSpin
WinMaximize, HyperSpin
Sleep, 500
WinActivate, HyperSpin
;************************************

ExitAPP
return

;***********Key Changes****************

r = 1


loop
{
$d::
if (r = 1)
{
r = 0

Send {Left Down}
}
else
{
r = 1

Send {Right Down}
}

$b:: ; thrust either left or right depending on above direction
if (r = 1)
{

Send {Right Down}
}
else
{
Send {Left Down}
}

KeyWait, b, U

if (r = 1)
{

Send {Right Up}
}
else
{
Send {Left Up}
}


sleep 40
return
}

$End::
Process, Close, %Executable%.exe
Process, WaitClose, %Executable%.exe
return

chillinwater
06-23-2011, 09:47 PM
Yeah, works much better now thanks!
I can still break it though, probably just because I'm lame not the script.

If I'm thrusting along and I hit "b" reverse, while pressing thrust, thrust continues even if unpressed, until I press, hold and release thrust.

I can live with it and will just consider it realism mode :D