PDA

View Full Version : Bob Church - HELP!!!!



worsel
14th March 2010, 06:12 AM
Hi Bob,

Many years ago (April 2003), you helped me write a script to use my Fighterstick in a video game called Splinter Cell.

Splinter Cell was unique because it used the mousewheel to scroll through 4 different run speeds. I have attached the map and script files... I hope you remember them.

I now have a different problem, but I believe the code you wrote for Splinter Cell holds the key.

First a quick re-cap on how I use my Fighterstick USB for Shooter Games:


Forward on the Joystick moves my character Forward... normally done with 'w' on the keyboard.
Backwards on the Joystick moves my character Backwards... 's' on the keyboard.
Pushing the Joystick to the Right makes my character Strafe to the Right... 'd' on keyboard.
Pushing the Joystick to the Left makes my character Strafe to the Left... 'a' on keyboard.
These games normally have 2 speeds; walk and run... run being "ON" by default. Usually holding down the 'Shift' button makes you walk. Releasing the 'Shift' button makes you resume running.

I have made numerous scripts to accomplish this... very simple because the "WALK" modifier is accomplished by holding down the "WALK" button. It is NOT a toggled event.

Now comes the problem.

I am trying to write a script for 2-speed movement in a game called "Lord of the Rings Online". The difference is that the "Walk-Run" command is a toggled one. So as the Joystick moves from centre and through a deadzone, the movement command will be given (in this case w, s, e, or q)... When it then reaches a 3rd zone, the "walk-run" button must be pressed and released. But when the joystick is moved back into zone 2 from zone 3, the walk-run button must be pressed and released again. This must be kept track of so you are walking when the joystick is in zone 2, and running when in zone 3. Zone 1 is the deadzone.

In my normal walk-run scripts, where the walk-run button must be held, it is a simple case of checking to see where the joystick is positioned, and then turning the walk-run button on or off.

This is how I do it normally:

cms.b1 = w (forward)
cms.b2 = d (strafe right)
cms.b3 = s (backward)
cms.b4 = a (strafe left)
cms.b5 = LSHF (walk when pressed, run when released)

First I check to see how far away the joystick is from centre. Since I do not care what direction it is in, just how far from centre, I use pythagorus' theorem a^2=b^2 + c^2. Since there is no function for taking the square root of a number, I just work with a^2, or the square of the distance from centre, as so:

a1 = ((js1.a1 - 128) * (js1.a1 - 128)) + ((js1.a2 - 128) * (js1.a2 - 128));

where a1 = the square of the distance that the joystick is from centre... the joystick's position from centre.

Then I check to see if a1 is in the walk zone or the run zone... 70 units, or a value of 4900, from centre:

IF ( [ A1 < 4900 ] ) THEN
CMS.B5 = TRUE;
ELSE
CMS.B5 = FALSE;
ENDIF

Then I decide which 'direction buttons' (w, s, a, or d) should be pressed at any given time, as long as the joystick is out of the deadzone. In the following example, the deadzone is from 0 to 196, where 196 is the square of the distance the joystick is from centre:

IF ( [ A1 > 196 ] ) THEN

// Forward
IF ( [JS1.A2 < 122] ) THEN
CMS.B1 = TRUE;
ELSE
CMS.B1 = FALSE;
ENDIF

// Right
IF ( [JS1.A1 > 134] ) THEN
CMS.B2 = TRUE;
ELSE
CMS.B2 = FALSE;
ENDIF

// Backwards
IF ( [JS1.A2 > 134] ) THEN
CMS.B3 = TRUE;
ELSE
CMS.B3 = FALSE;
ENDIF

// Left
IF ( [JS1.A1 < 122] ) THEN
CMS.B4 = TRUE;
ELSE
CMS.B4 = FALSE;
ENDIF

ELSE
CMS.B1=FALSE;
CMS.B2=FALSE;
CMS.B3=FALSE;
CMS.B4=FALSE;
ENDIF

And that's it... But, when the walk-run event is toggled, the task is MUCH more difficult because you have to press and release the walk-run button every time the joystick passes over the walk-run threshold. That's why I figured the script you wrote for Splinter Cell was the key to the answer. I have monkeyed around with it, and cannot get it to work.

I have also sent my non-working script (called "LOTRO Map.zip").
Your original solution for Splinter Cell is also attached (called "Splinter Cell Map.zip").

In the Lord of the Rings Online (LOTRO) game, the commands are as follows:
Move Forward = w
Move Backward = s
Strafe Right = e
Strafe Left = q
Walk-Run Toggle = KBINS (INSERT key)

So the way the walking and running works is as follows:

If you move any of the movement keys (w, s. e, or q), and you are running, if you press and release the INSERT key, you will start walking. And conversely, at any given time, if you are walking, pressing and releasing the INSERT key will make you start running.

Thanks, any help would be HUGELY appreciated.

Regards,
Rob Manning
email: worsel@mail.com

worsel
17th March 2010, 01:07 AM
I think I figured it out.

Here it is:



// CMS Script File: LOTRO-FS.map / .cms
//
// Game Title: Lord of the Rings Online
// Supports: Fighterstick USB
// Written By: Rob Manning (worsel)
// Date: March 16, 2010
//
//
// CMS.B1 = Move Forward (w)
// CMS.B2 = Strafe Right (e)
// CMS.B3 = Move Backwards (s)
// CMS.B4 = Strafe Left (q)
//
// CMS.B5 = Walk-Run Toggle (KBINS)
//
// A1 = (the square of) the distance that the joystick is from centre.
//
// B1 = ZONE FLAG; Flag to tell if Joystick has been in Walk Zone (TRUE), or Run Zone (FALSE).
//

SCRIPT

// Reset the ZONE FLAG the first time the script runs. It is, therefore, imperative
// that when you start the script running (by clicking the "DOWNLOAD" button in
// CH Control Manager) that the Joystick is in it's centred position.

IF ( FIRSTSCAN ) THEN
B1 = TRUE;
ENDIF


// Calculate Joystick Position
A1 = ((JS1.A1 - 128) * (JS1.A1 - 128)) + ((JS1.A2 - 128) * (JS1.A2 - 128));



// Press Walk-Run Toggle Button:

// If the Joystick is in the Walk Zone (B1=TRUE), WAIT until it transitions
// into the Run Zone, and then press the Walk-Run Button:

IF ( B1 ) THEN
SEQUENCE
WAIT ( [ A1 > 4900 ] );
CMS.B5 = TRUE;
B1 = FALSE;
DELAY( 3 );
CMS.B5 = FALSE;
ENDSEQUENCE
ENDIF


// If the Joystick is in the Run Zone (B1=FALSE), WAIT until it transitions
// into the Walk Zone, and then press the Walk-Run Button:

IF ( NOT B1 ) THEN
SEQUENCE
WAIT ( [ A1 < 4900 ] );
CMS.B5 = TRUE;
B1 = TRUE;
DELAY( 3 );
CMS.B5 = FALSE;
ENDSEQUENCE
ENDIF



// MOVE

IF ( [ A1 > 196 ] ) THEN

// Forward
IF ( [JS1.A2 < 122] ) THEN
CMS.B1 = TRUE;
ELSE
CMS.B1 = FALSE;
ENDIF

// Right
IF ( [JS1.A1 > 134] ) THEN
CMS.B2 = TRUE;
ELSE
CMS.B2 = FALSE;
ENDIF

// Backwards
IF ( [JS1.A2 > 134] ) THEN
CMS.B3 = TRUE;
ELSE
CMS.B3 = FALSE;
ENDIF

// Left
IF ( [JS1.A1 < 122] ) THEN
CMS.B4 = TRUE;
ELSE
CMS.B4 = FALSE;
ENDIF

ELSE
CMS.B1=FALSE;
CMS.B2=FALSE;
CMS.B3=FALSE;
CMS.B4=FALSE;
ENDIF

ENDSCRIPT



It works pretty well... every now and then the timing gets screwed up, and I end up running when the joystick is in the walk zone (when the joystick position A1 < 4900), and walking when the joystick is in the run zone (when the joystick position A1 > 4900). To fix it, you need to reach for the keyboard and press the Walk-Run Button once to set it back again... but having to do so could be problematic in the heat of the moment when you're trying to run away from something to save your life, and the walk-run sequence goes out. Maybe it's just a case of trying different DELAY times... currently I have them set to DELAY( 3 );

Can anyone think of a way to improve my script so this doesn't happen?
Do I need the DELAY( 3 ); lines at all?
If I took them out would the CMS.B5 button get pressed?

Now:

SEQUENCE
WAIT ( [ A1 > 4900 ] );
CMS.B5 = TRUE;
B1 = FALSE;
DELAY( 3 );
CMS.B5 = FALSE;
ENDSEQUENCE

What about this:

SEQUENCE
WAIT ( [ A1 > 4900 ] );
CMS.B5 = TRUE;
B1 = FALSE;
CMS.B5 = FALSE;
ENDSEQUENCE

Would the CMS.B5 button actually get pressed, or would the script run through the two states (CMS.B5=TRUE; --> CMS.B5=FALSE; so quickly that the Keypress (KBINS NULL) wouldn't get passed to the game?

Instead could I nest some SEQUENCE's and do away with the DELAY's all together?

If anyone has any thoughts, let me know... otherwise I'll monkey around some more...

almost got it though! I'm happy.

Bob Church
13th May 2010, 12:16 AM
Hi Worsel,

It usually does that if the key "sticks" which will happen when a key is not held for at least one or two frame times. If you put "DELAY( 2 )" (or whatever it takes) on both sides of the CMS.B5 statement it should hold the button down long enough that the sim won't miss seeing it.

Give it a try and see if that helps.

Best regards,

- Bob

The StickWorks
http://www.stickworks.com