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

    1. GTA Online

      1. The Diamond Casino Heist
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
    2. Red Dead Online

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

      1. Events
    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

    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. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

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

    1. News

    2. Forum Support

    3. Site Suggestions

Symbolic

Use Scripts with Controller

Recommended Posts

Symbolic

Hi, my question is on the title, i want to use my Gamepad to activate an Script, i would like to know how to write that on ScripthookV .NET C#

Share this post


Link to post
Share on other sites
LeeC22
Posted (edited)

Depends on how you want it to work but there are typically 2 ways.

 

By pressing a control:

// Place this in onTick()
if (Game.IsControlJustPressed(2, Control.Sprint))
{
    // Do something here when the Sprint control is pressed
}

By holding a control:

// Place this in the class declaration section to make it a Global variable
float HoldTimer = 0;

// Place this in onTick()
if (Game.IsControlPressed(2, Control.Sprint))
{
    HoldTimer += Game.LastFrameTime;

    if (HoldTimer >= 1f)
    {
        // Do something here when you have held the control for at least 1 second
    }
}
else
{
    // Set the HoldTimer to zero if the control is not being pressed
    HoldTimer = 0;
}

Game.LastFrameTime returns a float that represents the number of milliseconds as a fraction of 1 second. The typical number of milliseconds for 60fps is 16 or 17, so Game.LastFrameTime will return .016f or .017f. If you multiply it by 1000 (the number of milliseconds in 1 second), you will get the value as the actual number of milliseconds.

 

So IsControlJustPressed for button presses, IsControlPressed for holding a button for a period of time.

Edited by LeeC22

Share this post


Link to post
Share on other sites
Symbolic

There is some way to set two buttons to trigger the script?, i tried something like this and not worked xd

Game.IsControlJustPressed(2, GTA.Control.Phone && GTA.Control.Aim);

 

Edited by Symbolic

Share this post


Link to post
Share on other sites
LeeC22

You have to use the && on two Game.IsControlJustPressed() calls for it to work, like:

if(Game.IsControlJustPressed(2, Control.Sprint) && Game.IsControlJustPressed(2, Control.Jump))

But that means you have to press both buttons at exactly the same time and that can be tricky. You're better off doing something like this:

if(Game.IsControlPressed(2, Control.Sprint) && Game.IsControlJustPressed(2, Control.Jump))

That way, you can be holding one control and then pressing the second one. I usually use Control.Cover as the one being held and then any other button for the one being pressed. I never use cover in-game, so I disable it so it is free to use for scripts.

 

If you choose to disable a control, just change the Game.IsControlJustPressed() to Game.IsDisabledControlJustPressed() and it will be detected.

Edited by LeeC22

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.


  • 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.