homepage

Warthog Views Script ?

Posted By: Lightning

Warthog Views Script ? - 10/10/14 10:14 PM

Hello
Just by way of background, let me tell you that I have been a Thrustmaster user since the beginning, WAY back.
I even wrote all the files used in the original Ver2 install disk from Thrustmaster for the FCS Pro / WCS Mark II.
Have written MANY files for the F16 / F22 / Cougar systems.
So you see I'm not just lazy, maybe it's cause I'm old (67) :), but I'm so far totally baffled by the programming language of my brand new Warthog frown
Thought I could use Target software to program a simple H1 (Hat 1) file for views in FS9 / Combat Flight Simulator 1&2, but it doesn't allow for anything more than 4 positions, no angles.
Tried to figure out Script Editor to no avail frown
Thinking maybe I spent $800 for new setup and stand by mistake?
Would someone please be so kind as to help me out with this?
As you can see from below, all I want is to be able to have all 8 views with Button S3 as an "UP" modifier so I can do a little flying and combat.
I have been away from flightsims for a few years but, would like to get my feet wet again.

Again, any help would be VERY much appreciated.

My Old File:-

# FS2004.tmj

Rem #################################################################
Rem
Rem Flight Sim 2004
Rem for
Rem Flight Sim 2004
Rem
Rem by Robert "Lightning-=BS=-CO" Baum
Rem
Rem Last modified: 10 January 2004, 10:42 am
Rem
Rem Controllers: Thrustmaster Cougar
Rem
Rem #################################################################
Rem
Rem This file works equally well with CFS1 or CFS2
Rem Views work as in Hat1 POV, with the S3 key as "UP" modifier.
Rem All other buttons assigned in FS preferences
Rem #################################################################

USE ALL_DIRECTX_BUTTONS
USE MDEF #FS2004.tmm

BTN H1U /P USB (D60 D5D)
/R USB (U60 U5D)

BTN H1UL /H KP7
BTN H1UR /H KP9
BTN H1L /H KP4
BTN H1R /H KP6
BTN H1D /H KP2
BTN H1DL /H KP1
BTN H1DR /H KP3

BTN S3 /H KP5
Posted By: Nicu

Re: Warthog Views Script ? - 10/14/14 09:31 AM

Advice: use first the GUI to generate simple scripts, then examine the scripts to learn how they are made.
Also, the manual have some good examples.

Regarding your code, I tried to translate it (please let me know if I missed something).
Normally the translation from FOXY is quite straightforward, but because you need the HAT corners and TARGET does not translate these corners to virtual keys, I needed to use the Event Handler.

Code:
include "target.tmh"

//program startup
int main()
{
    if(Init(&EventHandle)) return 1; // declare the event handler, return on error
	
    POVKeys[0] = CHAIN(KP8, KP5);
    MapKey(&Joystick, S3, KP5); // BTN S3 /H KP5
}

//event handler
int prevKey = -1;
int POVKeys[] = {KP8, KP9, KP6, KP3, KP2, KP1, KP4, KP7};
int EventHandle(int type, alias o, int x)
{
    if((&o == &Joystick) & (x == POV))
    {
	if(prevKey != -1) ActKey(POVKeys[prevKey / 45]);
	prevKey = o[x];
	if(prevKey != -1) ActKey(KEYON + POVKeys[prevKey / 45]);
    }
    else DefaultMapping(&o, x);
}
Posted By: Lightning

Re: Warthog Views Script ? - 10/18/14 05:02 AM

Thank you for the reply, just found it smile

Will try it tomorrow.

Got buttons programmed in 6 installs of FS9 and 3 of FSX using standard DX USB buttons and it works ok, but can't imagine Dog Fighting without my up diagonals (lose sight lose fight:) )

Can't wait to try your code in Combat Flight Sims (and later other Combat Sims as well)

Been a long time since I did much flying, but I may even get back into War Birds etc.

Thanks again.

PS:- I did actually spend a bunch more time reading the manuals, but it hurt my old brain smile
Posted By: Lightning

Re: Warthog Views Script ? - 11/01/14 06:56 PM

Ok, just now had a chance to try this.
RL got in my way last couple of weeks frown

Created FS9 Corner Views.tmc

Ran it from TARGET Script Editor and it does indeed give me the corner views, and S3 gives up view, but S3 does not work as a modifier while in one of the other views.

Whole idea is to be able to track a target in any view from just the S3 and the hat.

If I just had one file that worked I hope that I could adapt this to any other flight sims I might want to fly.
I had everything under the sun programmed on my old Thrustmaster joysticks, but this new Warthog is getting more and more frustrating frown
Posted By: Nicu

Re: Warthog Views Script ? - 11/03/14 02:03 PM

Try to delete the following line from <main>:
Code:
POVKeys[0] = CHAIN(KP8, KP5);

I added it because your FOXY script seems to do it, but I don't see its meaning...

Now, the script presses KP1,2,3,4,6,7,8,9 according with the HAT1 position, and KP5 when S3 is pressed.
I can not test the script in game, as I don't have it installed. You can use <Event Tester> to verify if the keys are correctly generated, and to detail me what else do you need.
Posted By: Lightning

Re: Warthog Views Script ? - 11/08/14 03:08 AM

Ok tried it and still no go, but I did run the script from Script Editor and then tried to see what happens in notepad.
It DID generate the proper keypad strokes, but here's the thing, in Game Controllers, it still seems to be generating DX hat keys.
Been a long time since I did any TM programming, but shouldn't the script disable the DX inputs from the hat?
Posted By: Nicu

Re: Warthog Views Script ? - 11/10/14 09:46 AM

In order to bypass the DX hat, you may add o[x] = -1 in EventHandle, as below:
Code:
int EventHandle(int type, alias o, int x)
{
    if((&o == &Joystick) & (x == POV))
    {
	if(prevKey != -1) ActKey(POVKeys[prevKey / 45]);
	prevKey = o[x];
	if(prevKey != -1) ActKey(KEYON + POVKeys[prevKey / 45]);
        o[x] = -1;
    }
    else DefaultMapping(&o, x);
}
Posted By: Lightning

Re: Warthog Views Script ? - 11/11/14 05:09 PM

Hi Nico
Been trying out your code (first one), but just noticed I am getting this error message.


Running script: C:\Documents and Settings\PC Gamer\My Documents\Thrustmaster Files\TM Warthog Corner Views.tmc
Compile Error: Name already defined: EventHandle in TM Warthog Corner Views.tmc at line 29

Sorry to be a pest but this whole process is just beyond my programming skills frown
Posted By: Nicu

Re: Warthog Views Script ? - 11/12/14 08:03 AM

No problem.
Maybe you copied the EventHandle function from my last post over the script from my first one, instead of simply adding o[x]=-1 as indicated.
I will give you the full script again, just get it and replace the old one with this:

Code:
include "target.tmh"

//program startup
int main()
{
    if(Init(&EventHandle)) return 1; // declare the event handler, return on error
	
//    POVKeys[0] = CHAIN(KP8, KP5);
    MapKey(&Joystick, S3, KP5); // BTN S3 /H KP5
}

//event handler
int prevKey = -1;
int POVKeys[] = {KP8, KP9, KP6, KP3, KP2, KP1, KP4, KP7};
int EventHandle(int type, alias o, int x)
{
    if((&o == &Joystick) & (x == POV))
    {
	if(prevKey != -1) ActKey(POVKeys[prevKey / 45]);
	prevKey = o[x];
	if(prevKey != -1) ActKey(KEYON + POVKeys[prevKey / 45]);
        o[x] = -1;
    }
    else DefaultMapping(&o, x);
}
Posted By: Lightning

Re: Warthog Views Script ? - 11/15/14 06:05 PM

Hello again.
I have tried this code in Target Script editor (FS9 Corner Views.tmc)

//Code:
include "target.tmh"

//program startup
int main()
{
if(Init(&EventHandle)) return 1; // declare the event handler, return on error

POVKeys[0] = CHAIN(KP8, KP5);
MapKey(&Joystick, S3, KP5); // BTN S3 /H KP5
}

//event handler
int prevKey = -1;
int POVKeys[] = {KP8, KP9, KP6, KP3, KP2, KP1, KP4, KP7};
int EventHandle(int type, alias o, int x)
{
if((&o == &Joystick) & (x == POV))
{
if(prevKey != -1) ActKey(POVKeys[prevKey / 45]);
prevKey = o[x];
if(prevKey != -1) ActKey(KEYON + POVKeys[prevKey / 45]);
o[x] = -1;
}
else DefaultMapping(&o, x);
}


Compiles and runs without errors.
All views are perfect, but the thing is...none of the axis (joystick or throttle) do anything.
Don't show any movement in Windows Game Controller applet, or in game.
What am I doing wrong here?
Can I not just run the script from the Target Script Editor?
Can I add this to an .FCF file and run from Target GUI?
Again thanks for your patience and help.
Posted By: RogueSqdn

Re: Warthog Views Script ? - 11/16/14 10:15 AM

I'm wanting to do something similar in X-wing & in TIE Fighter, but using KP5 as the up position, and I want KP8 to be pressed/released when there is no active button on H1.

I changed KP8 to 5 in the code for int POVKeys. Can you figure a way for KP8 to be pressed once nothing else is being pressed on H1?

Code:
include "target.tmh"

//program startup
int main()
{
    if(Init(&EventHandle)) return 1; // declare the event handler, return on error
	


}

//event handler
int prevKey = -1;
int POVKeys[] = {KP5, KP9, KP6, KP3, KP2, KP1, KP4, KP7};
int EventHandle(int type, alias o, int x)
{
    if((&o == &Joystick) & (x == POV))
    {
	if(prevKey != -1) ActKey(POVKeys[prevKey / 45]);
	prevKey = o[x];
	if(prevKey != -1) ActKey(KEYON + POVKeys[prevKey / 45]);
        o[x] = -1;
    }
    else DefaultMapping(&o, x);
}
Posted By: Lightning

Re: Warthog Views Script ? - 11/16/14 11:42 PM

Seems to me when I programmed the hat views for X-Wing in the Cougar, or was it the F22, I had to do a...
Press KP9 (etc.) and then a
Release KP8 ?

No idea at all how to do this with this maddening Warthog programming frown
Hope this might be of help to you.

Let me know how you make out, cause I just bought and started playing GOG X-Wing and TIE Fighter myself.
Can't believe I didn't save my "General.plt" files with ALL medals etc. from X-Wing DOS, as I save everything smile
Posted By: RogueSqdn

Re: Warthog Views Script ? - 11/16/14 11:46 PM

I fiddled around with the above script, and I couldn't figure out how to make it execute KP8 when there is no active position on H1 (sort of like having an H1M). If you were only doing four directions, it would be pretty easy, because you could simply program a release action on each direction.
Posted By: RogueSqdn

Re: Warthog Views Script ? - 11/17/14 12:05 AM

I just figured the thing out!

Here's the script:

Code:

include "target.tmh"

//program startup
int main()
{
    if(Init(&EventHandle)) return 1; // declare the event handler, return on error

}

//event handler
int prevKey = -1;
int POVKeys[] = {KP5, KP9, KP6, KP3, KP2, KP1, KP4, KP7};
int EventHandle(int type, alias o, int x)
{
    if((&o == &Joystick) & (x == POV))
    {
	if(prevKey != -1) ActKey(POVKeys[prevKey / 45]);
	prevKey = o[x];
	if(prevKey != -1) ActKey(KEYON + POVKeys[prevKey / 45]);
        o[x] = -1;
        if(prevKey == -1) ActKey(KEYON + PULSE+USB[0x60]);
        o[x] = -1;
    }
    else DefaultMapping(&o, x);
}


The added part:
Quote:

if(prevKey == -1) ActKey(KEYON + PULSE+USB[0x60]);
o[x] = -1;


Doing this seems to execute KP8 whenever H1 is released, but won't execute it if you're simply moving from one direction to the other. It waits until you completely release the hat.

This has been one of my biggest frustrations with TARGET, compared to Foxy.
Posted By: Nicu

Re: Warthog Views Script ? - 11/17/14 08:44 AM

RogueSqdn: You may remove the <if(prevKey == -1)>, and leave only the <ActKey>, and KP8 will be executed each time the HAT is changing position.

Lightning: Regarding the axis movement, the small script I provided does not configure the axis, so this is the reason you see no axis movement on the virtual joystick.
You need to add code for axis mapping, (with MapAxis).
Posted By: RogueSqdn

Re: Warthog Views Script ? - 11/17/14 10:37 AM

I didn't want KP8 executing every time the hat changed directions, only when it was completely released. Would your suggestion do that, or would it spit out KP8 as you were moving it around?

Thanks for the script!
Posted By: Nicu

Re: Warthog Views Script ? - 11/17/14 10:48 AM

OK, I had the impression that your want to pulse KP8 whenever you move around, and not only when you release the HAT.
If you are happy with your solution please ignore my suggestion.
Posted By: RogueSqdn

Re: Warthog Views Script ? - 11/17/14 11:12 AM

Ok thanks. I only have one more question about this then. Is it possible to have shifted actions on the hat with this script? It's not the end of the world if I can't, but it would be nice.

For instance, X-Wing has an angle modifier of KP. that lets you look up 45 degrees, and if I can I'd like to put it as H1U, shifted with S3.
Posted By: Nicu

Re: Warthog Views Script ? - 11/17/14 11:37 AM

You can have shifted actions, in fact you can have whatever you want with the script.
I changed the EventHandler to allow S3 as shift (you may change the content of POVKeysShifted as you need):

Code:
//event handler
int prevKey = -1;
int POVKeys[] = {KP8, KP9, KP6, KP3, KP2, KP1, KP4, KP7};
int POVKeysShifted[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
int EventHandle(int type, alias o, int x)
{
    if((&o == &Joystick) & (x == POV))
    {
		if(prevKey != -1) ActKey(prevKey);
		if(o[x] != -1)
		{
			if(Joystick[S3]) prevKey =  POVKeysShifted[o[x] / 45];
			else prevKey =  POVKeys[o[x] / 45];
			ActKey(KEYON + prevKey);
		}
		else ActKey(KEYON + PULSE+USB[0x60]);
		o[x] = -1;
	}
    else DefaultMapping(&o, x);
}
Posted By: RogueSqdn

Re: Warthog Views Script ? - 11/17/14 11:43 AM

Thanks a bunch. When I get home I'll try it out. Work day is just starting. frown
Posted By: RogueSqdn

Re: Warthog Views Script ? - 11/17/14 09:23 PM

Ok, I'm having a few issues. One, KP. is not recognized in TARGET, and I can't figure out what I should be putting in. I tried inserting an ActKey statement there, but had no luck.

Two, I need KP8 to not be pressed if the hat is released while shifted.
Posted By: Nicu

Re: Warthog Views Script ? - 11/18/14 08:48 AM

1 - for KP. you can use the number 1099
2 - for shifted KP8 replace the line:

else ActKey(KEYON + PULSE+USB[0x60]);

with

else if(!Joystick[S3]) ActKey(KEYON + PULSE+USB[0x60]);
© 2024 SimHQ Forums