[SOLVED] Double tap hold button to activate combo

GPC2 script programming for Titan Two. Code examples, questions, requests.

[SOLVED] Double tap hold button to activate combo

Postby LuckyBastard » Tue May 07, 2019 3:06 am

I know this is really simple, but I have been at it all day. I am trying to make a script to activate a combo and I have rewritten it many times yet I can't get it to work.

I am trying to activate a combo by double pressing a button and holding it down the second time, the combo activates. Then when I release the button it stops running. Can someone post a script, or a link to a script. I have tried cutting up the examples given in the guide, and splicing other codes I have found for similar actions but none seem to work. Thanks in advance for any responses.

This is where it is at as of now.
Code: Select all
 
 bool bEnabled=FALSE;
 
main {
  if (event_active(BUTTON_16) && time_release(BUTTON_16) < 200)combo_run(sprint); {
      bEnabled = !bEnabled;   
      printf("sprint, bEnabled is now: %d",bEnabled);
  }
  if (bEnabled) combo_run(sprint);
  if(event_release(BUTTON_16)) {
      bEnabled= FALSE;
  }
}
 
combo sprint {
  set_val(BUTTON_16,100);
  wait(150);
  set_val(BUTTON_16,0);
  wait(150);
}
 


edit: now its repeating, but its not stopping when I release the button, any suggestions?
Last edited by LuckyBastard on Sat Aug 07, 2021 4:38 am, edited 3 times in total.
User avatar
LuckyBastard
Staff Sergeant
Staff Sergeant
 
Posts: 11
Joined: Fri Apr 26, 2019 1:30 am

Re: Double tap hold button to activate combo

Postby Scachi » Tue May 07, 2019 5:01 am

Use the "T2 Code" button, this will format your code posted..

You have some misplaced commands:
in first "if (" line there is a combo_run command that is outside of your { }
in your line "else if" there is a ";" at the end of that line directly before { . That ";" shouldn't be there

This will work:
Code: Select all
bool bEnabled=FALSE;
 
main {
    if (event_active(BUTTON_16) && time_release(BUTTON_16) < 200) {
        bEnabled = TRUE;
        printf("sprint, bEnabled is now: %d",bEnabled);
    }
    if (bEnabled) combo_run(sprint);
 
    if(event_release(BUTTON_16)) {
        bEnabled=FALSE;
    }
}
 
combo sprint {
    set_val(BUTTON_16,100);
    wait(150);
    set_val(BUTTON_16,0);
    wait(150);
}
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Double tap hold button to activate combo

Postby LuckyBastard » Tue May 07, 2019 5:20 am

Thank you so much! I have been messing with that code on and off for 12 hours. Are there any resources you can suggest, if I have more questions about coding in the future, so I dont have to bother people with my basic questions.
User avatar
LuckyBastard
Staff Sergeant
Staff Sergeant
 
Posts: 11
Joined: Fri Apr 26, 2019 1:30 am

Re: Double tap hold button to activate combo

Postby Scachi » Tue May 07, 2019 5:32 am

The wiki: https://www.consoletuner.com/wiki/index ... _scripting
Or scripts from the GTuner IV Oline Resource that have a "Download" button, those source code can be viewed & edited.

Asking at the forum is fine.. I'll try add stuff to the wiki section GPC Scripting that is missing or need more examples/information.

For control statements information like if / if else / for / while.. search the web for "C language control statements" tutorials will help you with that, example: http://www.tutorialspoint.com/ansi_c/c_ ... ements.htm
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Double tap hold button to activate combo

Postby DontAtMe » Tue May 07, 2019 6:38 am

LuckyBastard wrote:Thank you so much! I have been messing with that code on and off for 12 hours. Are there any resources you can suggest, if I have more questions about coding in the future, so I dont have to bother people with my basic questions.

Feel free to join the Community Discord If you need more help.
You don't have to feel like your bothering anyone with questions either. We have many members willing to help newcomers.
User avatar
DontAtMe
Captain
Captain
 
Posts: 502
Joined: Tue Oct 02, 2018 4:49 am

Re: Double tap hold button to activate combo

Postby alanmcgregor » Tue May 07, 2019 6:49 pm

Or you can try this:

The only difference is making sure to stop the combo for a more reliable performance like avoiding USB offsyncs (XIM purple lights) I find out some scripts where the combos are not properly manage, weird issues like that pops up.

Code: Select all
 
bool bEnabled = FALSE;
 
main {
    if(event_active(BUTTON_16) && time_release(BUTTON_16) < 200)
        bEnabled = TRUE;
    else
        if(event_release(BUTTON_16))
            bEnabled = FALSE;
 
    if(bEnabled) combo_run(sprint);
    else combo_stop(sprint);
}
 
combo sprint {
    set_val(BUTTON_16, 100.0);
    wait(150);
    set_val(BUTTON_16, 0.0);
    wait(150);
    set_val(BUTTON_16, 0.0);
}
 


:smile0517:
User avatar
alanmcgregor
Major
Major
 
Posts: 988
Joined: Tue Mar 27, 2018 8:38 am

Re: Double tap hold button to activate combo

Postby LuckyBastard » Wed May 08, 2019 2:51 am

I just came back to say that the double tap hold method is extremely unreliable, and it is causing issues with not turning off or activating properly. So I have switched back to holding a button for a set amount of time to activate.

Thanks for the new script alanmcgregor, I will try this when I jump on to red dead tonight. Also, the main reason I starting creating my own scripts is because I could not find your scripts for rdr2 listed in the GTuner IV search function. I could find several references listing what your RDR2 script does, but no actual links to download or implement them.

When I have all my scripts working I will make a separate post. The most useful one I have come up with is instantly replacing your hat when it is shot off while you are on a horse. It's god-like when someone shoots my hat off while I'm using Never Without One, then I double tap down on the d-pad and I have a new hat before they can even reload their gun. When used in conjunction with level 3 Slow and Steady, and a quick script for health tonics, I can take infinite headshots.
User avatar
LuckyBastard
Staff Sergeant
Staff Sergeant
 
Posts: 11
Joined: Fri Apr 26, 2019 1:30 am

Re: Double tap hold button to activate combo

Postby LuckyBastard » Wed May 08, 2019 8:22 am

I tried out your script and it is definitely more effective in getting the result I need, and the code looks alot cleaner. I can understand everything in it. The line in my code here;

printf("sprint, bEnabled is now: %d",bEnabled);

is something I copied out of the example code from the gtuner iv guide, and it doesn't make a lick of sense to me. It seems like it is just cluttering up the script. Thanks again for the script. Do you think, I could get a hold of your RDR2 scripts somewhere? I would love to take a look at them, and it would be very helpful for me me to learn more about coding.
User avatar
LuckyBastard
Staff Sergeant
Staff Sergeant
 
Posts: 11
Joined: Fri Apr 26, 2019 1:30 am

Re: Double tap hold button to activate combo

Postby Scachi » Wed May 08, 2019 9:14 am

Those printf commands in the wiki are there for feedback for the user at runtime when testing those or creating own scripts.
The purpose of the GPC Scripting wiki section is to learn scripting and showing examples .. how to do things.
When one has never used printf before you have no idea that it can be used for testing the function of a script.
The comment also explains its usage. From the wiki: "// write out the value to the Output Panel"
Its easy enough to remove a single line from an example :innocent_smile_1:
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Double tap hold button to activate combo

Postby bonefisher » Wed May 08, 2019 9:57 am

Code: Select all
 
bool sprint_toggle;
main {
    if(sprint_toggle){
    if(get_val(BUTTON_16)){
        combo_run(sprint);
    }else{ sprint_toggle = 0;}
    }else if(event_active(BUTTON_16)
    && time_release(BUTTON_16) < 140){
        sprint_toggle = 1;
    }
}
combo sprint
{
    set_val(BUTTON_16, 100.0);
    wait(100);
    set_val(BUTTON_16, 0.0);
    wait(100);
    set_val(BUTTON_16, 0.0);
}
 
bonefisher
Lieutenant General
Lieutenant General
 
Posts: 5413
Joined: Thu Jan 29, 2015 10:49 am

Next

Return to GPC2 Script Programming

Who is online

Users browsing this forum: Google [Bot], proxy342 and 137 guests