Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Tuners
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    2. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    3. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    1. Grand Theft Auto Series

      1. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    6. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

      1. GTANet 20th Anniversary
    2. Support

    3. Suggestions

[TEST]dotnet scripthook xbox 360 pad support


Andrew
 Share

Recommended Posts

 

xBox360 Control Pad Support For Dotnet Scripthook 0.86

This is purely experimental, and may not work for everyone not to mention, there isn't many button configurations that can be used, since IV uses most of the buttons.

 

This is purely for script creators only!

 

Introduction

I've been experimenting, to try and enable the xbox control pad support for the dotnet scripts. So scriptors can configure controls for the 360 pad. Since I study computer games programming at University, I've used the C# / XNA framework in one of the team projects. The XNA framework has support for the xbox 360pad.

 

Extra items needed

Note: When releasing scripts that use the 360 pad, and this method. You'll need to include the xna 3.0 redistributable run time, available from the Microsoft website. -> http://www.microsoft.com/downloads/details...&displaylang=en

 

The method

Currently in order to get a constant update to the control pad state, I've had to place the pad checking code and polling code into the DrawPerFrame() method. Since this is the only method that is ran in milliseconds. I'm also using Visual Studio 2008, it shouldn't be that much different between 2005, or Visual C#.

 

Step 1

Extract the Microsoft.XNA.Framework.dll file to a folder anywhere on your computer. Open up the project you wish to add 360pad support to, and choose Project -> Add Reference Click on the Browse tab and choose the dll file you extracted. Don't add the Using Microsoft.Xna.Framework statement, doing so will cause conflicts between various items

 

Step 2

We need two control pad states, that will hold the state of the pad. One will hold the current state, and the other will hold a previous state. This is needed so we can only have the pad button pressed once. Without this one press of the pad button may execute that action multiple times.

 

Wherever you've declared all your variables, usually at the top of the script. You need to add the following code.

 

Microsoft.Xna.Framework.Input.GamePadState padState;Microsoft.Xna.Framework.Input.GamePadState oldPadState;

 

 

Step 3

We now need to poll the pad states, so they are up to date. In the DrawPerFrame() method, or any other method you want, providing the method is called constantly. We need to put this code at the very top of the method.

 

padState = Microsoft.Xna.Framework.Input.GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One);[code]At the very bottom of the method. We need to put this line of code.[code]oldPadState = padState

 

 

Step 4

Now we just need to add the button checking code. To check that the A button is only pressed once:

 

if(padState.IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.A && padState.IsButtonUp(Microsoft.Xna.Framework.Input.Buttons.A)

 

 

To check if the A button is held down.

 

if(padState.IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.A)

 

 

Done!

 

That's all there is to that, but hopefully it will allow script writers control over the 360 pad. The normal IV controls cannot be blocked. So if we were checking for button press on A. We'd still be getting the alternative brake applied.

 

Since we now have access to the padState, we can detect how hard the triggers are being held down for. Since the trigger state is between 0 and 1. (might help those checking for RPMs?) 0 being trigger released, and 1 being fully held down.

 

To check for the right trigger held more the halfway down.

 

if(padState.Triggers.Right > 0.5)

 

 

Any questions, or if it doesn't work. Post in this topic and I'll do my best to help. Also, discussion on how we can configure the 360 pad is more then welcome!

Link to comment
Share on other sites

Good job i must say.

Link to comment
Share on other sites

This is fantastic!

 

The LB button seems to be open to a function on-foot if you somehow disable calling a taxi and make sure you're not near a holdable object. Or better yet, script a check for such actions, inhibiting or enabling the function you're trying to implement (sit, grab car, etc...).

 

 

So now it would be possible to make a script have the analog stick act like it used to when walking around? (ie: push a little bit = walk, push all the way = run, tap A = sprint)This is half-way possible currently if one pushes the stick just enough to get Niko moving, then holds A (pressing A before moving makes him start off like he's running even if you let go before moving the stick).

Link to comment
Share on other sites

Hopefully this will be a good start to get pad-compatible mods, good job.

Link to comment
Share on other sites

Hopefully, but using this method I've got a few more ideas to try out that I thought off. XNA includes a method for drawing stuff to the screen, if I can get that object working in IV. Then that may prove useful as well, in fact there is alot of things in XNA that may prove useful.

 

Edit: Thats proving difficult, as somehow I have to create a new xna game and grab the graphics device...

Edited by Gangsta Killa
Link to comment
Share on other sites

  • 1 year later...

If got a problem:

This is my Keybindingfile:

 

[KeyBindings]

PositiveKey=190

NegativeKey=188

DanceKey=191

SlideKey=71

RollKey=67

 

 

Now I would like to use at least the rolekey on my xbox 360 controller by pressing down the right trigger.

But i don't know, how to do it.

 

Can u help me?

 

Sry for my bad english wink.gif

Link to comment
Share on other sites

  • 2 years later...

If you are just aiming for controller support I think XNA is not the best option. I have used SlimDX in older and newer project with great success.

 

And ScriptHook already uses some SlimDX based code, not that influences anything, but oh well.

 

SlimDX only requires SlimDX.dll to be deployed on client's machine, nothing else.

 

It gives me full controller of the 360 controller for windows and others aswell.

 

You can't still avoid polling.

 

Simple usage sample :

 

 

using SlimDX.input;///..///Controller GamePad = new Controller(UserIndex.One);///...///GamePad.GetState().Gamepad.RightTrigger;

 

 

UltimateFuelScriptV2 uses this.

 

check the class members for a better overview :

 

http://slimdx.org/docs/html/T_SlimDX_XInput_Controller.htm

 

http://slimdx.org/docs/html/T_SlimDX_XInput_Gamepad.htm

Edited by pedro2555
Link to comment
Share on other sites

the XNA dont need only the microsoft..xna...dll file? (i cant remember the exact name now)

 

thx for the tip, i will try this one too

Hope I am not wrong, but you will always need to install the redistributable version of the XNA Framework. Very much like .NET, you always need, at least, client profile.

Link to comment
Share on other sites

I have posted a beta state library to enable xBox 360 controller support for any .NET project in fact, but it is aimed at the .NET scripthook by HazardX.

 

It uses, as I was pointing out, the SlimDx SDK.

 

It is not my intention to kill other projects like this one, but I don't think the XNA Framework is the best approach only for controller support. Hope you keep up with this project still. It is not only different than the one I have posted, but it has a complete different range of uses, so please do keep with it, and I would love a source code post. XNA is great from what I can tell, PC and Xbox compatibility with the exact same code isn't ? That's awesome, as far as I can tell it is the best DirectX wrapper out there, but I don't really work with 3d drawing.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.