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 Summer Special
      2. The Diamond Casino Heist
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

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

    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Redemption

    1. Grand Theft Auto Series

    2. GTA 6

      1. St Andrews Cathedral
    3. GTA V

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

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    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. DYOM
      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
    3. Gangs

    1. Announcements

    2. Support

    3. Suggestions

Billsy93

Game Input - Xbox 360 Gamepad Support

Recommended Posts

Billsy93

Hello,

 

I'm writing some mods for GTA IV in C++ (file format .asi) and I was wondering if it's possible to toggle the input of the xbox 360 controller in order to perform actions within created mods?

 

Specifically I want the player to be able to teleport when the xbox 360 controller 'A' (green) button is pressed as oppose to a keyboard button.

 

Edit: I've found this function in scripting.h within the scripthook.sdk directory;

 

 

static b8 IsButtonPressed(u32 padIndex, ePadButton button) { return NativeInvoke::Invoke<NATIVE_IS_BUTTON_PRESSED, b8>(padIndex, button); }

 

 

My question now is, how do I find the values for the padIndex and ePadButton parameters?

 

Thanks,

 

Billsy

Edited by Billsy93

Share this post


Link to post
Share on other sites
Mordecki

 

Look into ScriptingEnums.h

 

 

enum ePadButton{ BUTTON_BACK = 0xD, BUTTON_START = 0xC, BUTTON_X = 0xE, BUTTON_Y = 0xF, BUTTON_A = 0x10, BUTTON_B = 0x11, BUTTON_DPAD_UP = 0x8, BUTTON_DPAD_DOWN = 0x9, BUTTON_DPAD_LEFT = 0xA, BUTTON_DPAD_RIGHT = 0xB, BUTTON_TRIGGER_LEFT = 0x5, BUTTON_TRIGGER_RIGHT = 0x7, BUTTON_BUMPER_LEFT = 0x4, BUTTON_BUMPER_RIGHT = 0x6, BUTTON_STICK_LEFT = 0x12, BUTTON_STICK_RIGHT = 0x13};

 

 

 

In your case you might use this:

 

if(IsButtonPressed(0, BUTTON_A))  // the first 0 depends on controller ID you are using, i suggest you are using only one at time

 

 

Have fun!

Edited by MOrdecki

Share this post


Link to post
Share on other sites
julionib
Look into ScriptingEnums.h

 

 

enum ePadButton{ BUTTON_BACK = 0xD, BUTTON_START = 0xC, BUTTON_X = 0xE, BUTTON_Y = 0xF, BUTTON_A = 0x10, BUTTON_B = 0x11, BUTTON_DPAD_UP = 0x8, BUTTON_DPAD_DOWN = 0x9, BUTTON_DPAD_LEFT = 0xA, BUTTON_DPAD_RIGHT = 0xB, BUTTON_TRIGGER_LEFT = 0x5, BUTTON_TRIGGER_RIGHT = 0x7, BUTTON_BUMPER_LEFT = 0x4, BUTTON_BUMPER_RIGHT = 0x6, BUTTON_STICK_LEFT = 0x12, BUTTON_STICK_RIGHT = 0x13};

 

 

 

In your case you might use this:

 

if(IsButtonPressed(0, BUTTON_A))  // the first 0 depends on controller ID you are using, i suggest you are using only one at time

 

 

Have fun!

nice, do you know if its possible detect Stick X/Y values with native calls?

Share this post


Link to post
Share on other sites
Soyeldiablo

 

void GetStickPos(out int a , out int b, out int c, out int d){   GTA.Native.Pointer pA = typeof(Int32);   GTA.Native.Pointer pB = typeof(Int32);   GTA.Native.Pointer pC = typeof(Int32);   GTA.Native.Pointer pD = typeof(Int32);   GTA.Native.Function.Call("GET_POSITION_OF_ANALOGUE_STICKS" pA, pB, pC, pD);   a = Convert.ToInt32(pA.Value);   b = Convert.ToInt32(pB.Value);   c = Convert.ToInt32(pC.Value);   d = Convert.ToInt32(pD.Value);}

 

 

metadata won't save u ;P

Edited by Soyeldiablo

Share this post


Link to post
Share on other sites
AgentWD40

 

if(protection){ uint pos[4]; GET_POSITION_OF_ANALOGUE_STICKS(0,&pos[0],&pos[1],&pos[2],&pos[3]); if(pos[0] == 0 && pos[1] == 0) 	FREEZE_CHAR_POSITION(pPlayer,true); else 	FREEZE_CHAR_POSITION(pPlayer,false);}

 

 

neat, ill just put this here also

Share this post


Link to post
Share on other sites
julionib
void GetStickPos(out int a , out int b, out int c, out int d){   GTA.Native.Pointer pA = typeof(Int32);   GTA.Native.Pointer pB = typeof(Int32);   GTA.Native.Pointer pC = typeof(Int32);   GTA.Native.Pointer pD = typeof(Int32);   GTA.Native.Function.Call("GET_POSITION_OF_ANALOGUE_STICKS" pA, pB, pC, pD);   a = Convert.ToInt32(pA.Value);   b = Convert.ToInt32(pB.Value);   c = Convert.ToInt32(pC.Value);   d = Convert.ToInt32(pD.Value);}

 

 

metadata won't save u ;P

lol, the metadata guy ^^

 

thx

 

GTA.Native.Function.Call("GET_POSITION_OF_ANALOGUE_STICKS" pA, pB, pC, pD);

 

damm, this is the only time when i think that is bad idea use VB.Net instead of C# sad.gif

Share this post


Link to post
Share on other sites
Soyeldiablo

 

GTA.Native.Function.Call("GET_POSITION_OF_ANALOGUE_STICKS", pA, pB, pC, pD);

 

 

Forgot a comma and yes vb is garbage but y can't u translate this to vb??

Share this post


Link to post
Share on other sites
julionib
GTA.Native.Function.Call("GET_POSITION_OF_ANALOGUE_STICKS", pA, pB, pC, pD);

 

 

Forgot a comma and yes vb is garbage but y can't u translate this to vb??

i guess that we cant use pointers like this method needs, but im not sure

Share this post


Link to post
Share on other sites
Soyeldiablo

 

GTA.Native.Function.Call("GET_POSITION_OF_ANALOGUE_STICKS", pA, pB, pC, pD);

 

 

Forgot a comma and yes vb is garbage but y can't u translate this to vb??

i guess that we cant use pointers like this method needs, but im not sure

im pretty sure u can, the Pointer object is in the GTA.Native namespace, just add to your Imports

 

and btw, i never mentioned... a value is for horizontal axis on left stick and b is vertical axis on left stick, c and d are same but for right stick

 

example:

 

values range -100 to 100 (iirc, need to verify)

 

a = -10 ... left stick little left

b = 50 ... left stick half way forward

c = 30 ... right stick 30% right

d = -40 ... right stick 40% down

 

please verify

 

also u should use with this so u dont call unnecessaryily, im sure checking if using controller is more efficient when not using a controller

 

 

Function.Call<bool>("IS_USING_CONTROLLER")

 

Edited by Soyeldiablo

Share this post


Link to post
Share on other sites
julionib

nice

 

this "IS_USING_CONTROLLER" is very useful

 

 

the use of XNA Dll or SlimDX Dll to have access to xbox control input its good but has some side effects like some people that just cant load the mod or bad precision (like i had with slimDx), so its better try to do all with native calls

Share this post


Link to post
Share on other sites
julionib

this is beautiful, thx for the tip, now i can use this same pointer idea for a lot of methods, damm i was stuck with some script ideas because i tought it was impossible to use some native calls in VB.net and i was too lazy to migrate to C# ^^

 

 

 

Dim P1, P2, P3, P4 As GTA.Native.PointerP1 = New GTA.Native.Pointer(GetType(Int32))P2 = New GTA.Native.Pointer(GetType(Int32))P3 = New GTA.Native.Pointer(GetType(Int32))P4 = New GTA.Native.Pointer(GetType(Int32))Native.Function.Call("GET_POSITION_OF_ANALOGUE_STICKS", 0, P1, P2, P3, P4)msg("Res: p1: " & P1.ToString & "   p2: " & P2.ToString & "   p3: " & P3.ToString & "   p4: " & P4.ToString, 1500)

 

 

 

the values go from -127 to 127 for each axis in each stick

Share this post


Link to post
Share on other sites
Soyeldiablo

Yeah I was wondering why all these mods are being released using xna stuff when gta already does it

Share this post


Link to post
Share on other sites
julionib
Yeah I was wondering why all these mods are being released using xna stuff when gta already does it

yeah, it makes more complicated to install, some people ignore the file and the game just crash at loading screen when script loads

i guess that its indicated to games/programs that cant have direct access to xbox control

 

now i will upgrade some scripts with this native methods.

Share this post


Link to post
Share on other sites
pedro2555

Excellent posts on this topic.

 

And what about the back triggers ? They are also analog inputs. Can they be accessed the same way ?

Share this post


Link to post
Share on other sites
adsvsdvasdvasdv

 

Excellent posts on this topic.

 

And what about the back triggers ? They are also analog inputs. Can they be accessed the same way ?

new name... same person haha...

 

 

bool LeftTriggerPressed(){   return Function.Call<bool>("IS_CONTROL_PRESSED", 0, 6);}Game.isGameKeyPressed(GameKey.Attack)//right trigger

 

 

note GameKey.Aim only detects right mouse button and not left trigger so u must wrap the native yourself wink.gif

 

i suggest u guys actually look at the code ur writing and u would already know this... so get ilspy or whatever and look at the code in the shdn... everything is there wink.gif

 

or look at the gtaiv game scripts that were decompiled by alexander blade i think

 

you wont need to ask if u do the research wink.gif

 

user posted image

Edited by adsvsdvasdvasdv

Share this post


Link to post
Share on other sites
adsvsdvasdvasdv

This is how u reverse needed parameter for is_control_pressed

 

 

void GetInputPressedValues_Tick(object sender, EventArgs e){   for (int i = 0; i < 1500; i++)       if (Function.Call<bool>("IS_CONTROL_PRESSED", 0, i)           Game.DisplayText(i.ToString() + " pressed");}

 

 

Btw I forgot what the max value is but change 1500 to max value + 1

Edited by adsvsdvasdvasdv

Share this post


Link to post
Share on other sites
julionib

yep, sometimes im just too much lazy to do an search in the SCOCL or scripthook source code ^^

 

if was looking there now and find an interesting point related to the analogue sticks:

 

 

void Game::GetMovement(int* x, int* y) { int x2 = 0; int y2 = 0; *x = 0; *y = 0; Scripting::GetPositionOfAnalogueSticks(0, x, y, &x2, &y2); if ((*x == 0) && (*y == 0)) Scripting::GetKeyboardMoveInput(x, y);}

 

 

 

this is one side effect of having an "easy" method like XNA or SlimDX, we forget about game natives

 

 

 

but about what pedro asked, i guess that he want to know how much the trigger is pressed, we have this data on SlimDX and XNA but i guess that we dont have with native calls

Share this post


Link to post
Share on other sites
pedro2555

Just to clarify what buttons I'm talking about, it's AXIS 3. Left and Right Triggers. I think SlimDX returns a byte value 0 to 255.

 

user posted image

 

Researching for this just takes too long, I would love to have the time thought.

Share this post


Link to post
Share on other sites
hellothereyoupieceofshit

im sure it can be done since vehicle acceleration is based on pressure of triggers, if u cant find a native then i suppose use a 3rd party lib

Share this post


Link to post
Share on other sites
pedro2555
im sure it can be done since vehicle acceleration is based on pressure of triggers, if u cant find a native then i suppose use a 3rd party lib

Thats why I used SlimDX with Ultimate Fuel Script, I rely exclusively in AXIS3, which apparently isn't obtainable via natives.

 

Correct me if I'm wrong ,but vehicle control isn't handled by native calls at all, so there is no reason for AXIS3 to be available via native calls.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • 2 Users Currently Viewing
    0 members, 0 Anonymous, 2 Guests

×
×
  • Create New...

Important Information

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