t2:gpc_scripting:examples_1

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
t2:gpc_scripting:examples_1 [2019/05/06 11:41]
scachi [GPC Script Examples]
t2:gpc_scripting:examples_1 [2021/03/09 17:38] (current)
scachi [Script On/Off]
Line 4: Line 4:
  
 There are always multiple ways to do a single thing. The examples don't claim to be the best solution to achieve something. There are always multiple ways to do a single thing. The examples don't claim to be the best solution to achieve something.
 +
 +Some examples make use of the [[t2:​printf|printf]] function to demonstrate how to use it to write text or values of variables to the ''​Output Panel''​ during script development. You may want to remove or ''​%%//​comment%%''​ the printf line when you have finished your script and use it for gaming.
  
 ^ Action ^ Script ^  ^ Action ^ Script ^ 
 ^ On trigger activity fully press it | [[t2:​gpc_scripting:​examples_1#​hair_trigger|Hair Trigger]] | ^ On trigger activity fully press it | [[t2:​gpc_scripting:​examples_1#​hair_trigger|Hair Trigger]] |
 ^ On full forward stick movement press a button | [[t2:​gpc_scripting:​examples_1#​auto_sprint|Auto Sprint]] & [[t2:​gpc_scripting:​examples_1#​auto_sprint|By Value]] | ^ On full forward stick movement press a button | [[t2:​gpc_scripting:​examples_1#​auto_sprint|Auto Sprint]] & [[t2:​gpc_scripting:​examples_1#​auto_sprint|By Value]] |
-^ On button press loop combo n times | [[t2:​gpc_scripting:​examples_1#​loopntimes|Loop <n> Times]] | 
 ^ On button press do press it twice | [[t2:​gpc_scripting:​examples_1#​double_jump|Double Jump]] | ^ On button press do press it twice | [[t2:​gpc_scripting:​examples_1#​double_jump|Double Jump]] |
 +^ On button press loop combo n times | [[t2:​gpc_scripting:​examples_1#​loop_combo_n_times|Loop <n> Times]] |
 +^ On button press loop combo endless | [[t2:​gpc_scripting:​examples_1#​loop_combo_endless|Loop Endless]] |
 ^ On button hold press it repetitive | [[t2:​gpc_scripting:​examples_1#​aim_assist_abuse|Aim Assist Abuse]] | ^ On button hold press it repetitive | [[t2:​gpc_scripting:​examples_1#​aim_assist_abuse|Aim Assist Abuse]] |
 ^ On button hold press it repetitive | [[t2:​gpc_scripting:​examples_1#​bunny_hop|Bunny Hop]] | ^ On button hold press it repetitive | [[t2:​gpc_scripting:​examples_1#​bunny_hop|Bunny Hop]] |
 +^ On button hold press it repetitive | [[t2:​gpc_scripting:​examples_1#​simple_rapid_fire|Rapid Fire]] |
 ^ On button double tap| [[t2:​gpc_scripting:​examples_1#​double_tap|Double Tap]] &  [[t2:​gpc_scripting:​examples_1#​double_tap|Toggle]] | ^ On button double tap| [[t2:​gpc_scripting:​examples_1#​double_tap|Double Tap]] &  [[t2:​gpc_scripting:​examples_1#​double_tap|Toggle]] |
 +^  \\ |  |  ​
 +^ Toggle script on/off - Script | [[t2:​gpc_scripting:​examples_1#​script_on_off|Script]] & [[t2:​gpc_scripting:​examples_1#​script_on_off|Toggle]] |
 ^ Toggle features on/off - Anti Recoil| [[t2:​gpc_scripting:​examples_1#​toggle_anti_recoil|Anti Recoil]] & [[t2:​gpc_scripting:​examples_1#​anti_recoil|Toggle]] | ^ Toggle features on/off - Anti Recoil| [[t2:​gpc_scripting:​examples_1#​toggle_anti_recoil|Anti Recoil]] & [[t2:​gpc_scripting:​examples_1#​anti_recoil|Toggle]] |
 ^ Toggle features on/off - Auto Scope| [[t2:​gpc_scripting:​examples_1#​toggle_scope|Auto Scope]] & [[t2:​gpc_scripting:​examples_1#​auto_scope|Toggle]] | ^ Toggle features on/off - Auto Scope| [[t2:​gpc_scripting:​examples_1#​toggle_scope|Auto Scope]] & [[t2:​gpc_scripting:​examples_1#​auto_scope|Toggle]] |
Line 38: Line 44:
 } }
 </​code>​ </​code>​
 +or on smaller movement: 
 +<code gpc2> 
 +main { 
 +    if (get_actual(STICK_2_Y) <=  -90.0) set_val(BUTTON_9,​100);​ 
 +
 +</​code>​
  
 ===== Double Jump ===== ===== Double Jump =====
Line 74: Line 85:
 </​code>​ </​code>​
  
 +===== Loop Combo n Times =====
 +When BUTTON_16 is getting pressed loop/play the combo cLoop 5 times. ​
 +<code gpc2>
 +#​define LOOP 5 // loop 5 times
 +uint8 iLoop;​
 +
 +main {
 +  if (event_active(BUTTON_16)) iLoop = LOOP; // initiate loop
 +
 +  if (iLoop) { // iLoop is not 0
 +    if (!cLoop) { // combo is not running at the moment
 +      iLoop--; // iLoop - 1
 +      printf("​starting combo cLoop, loops left: %d",​iLoop);​ // write text to the Output Panel
 +      combo_run(cLoop);​
 +    }
 +  }
 +}
 +
 +combo cLoop {
 +  set_val(BUTTON_16,​100); ​  // press button 16
 +  wait(100); ​             // (press) for 100ms
 +  set_val(BUTTON_16,​0);​ // release button 16
 +  wait(50); ​             // (release) for 50ms
 +}
 +</​code>​
 +
 +===== Loop Combo Endless =====
 +When BUTTON_16 is getting pressed play the combo in an endless loop. Press BUTTON_16 again to stop the endless loop.
 +<code gpc2>
 +bool bLoop=FALSE;​
 +
 +main {
 +  if (event_active(BUTTON_16)) bLoop = !bLoop; // invert the current state with each press TRUE<​->​FALSE
 +
 +  if (bLoop) combo_run(cLoop);​ // keep the combo playback active as long as bLoop == TRUE
 +}
 +
 +combo cLoop {
 +  set_val(BUTTON_16,​100); ​  // press button 16
 +  wait(100); ​             // (press) for 100ms
 +  set_val(BUTTON_16,​0);​ // release button 16
 +  wait(50); ​             // (release) for 50ms
 +}
 +</​code>​
 ===== Aim Assist Abuse ===== ===== Aim Assist Abuse =====
 Press BUTTON_8 again and again if you hold it down 200ms or longer. Press BUTTON_8 again and again if you hold it down 200ms or longer.
Line 107: Line 162:
  
 ===== Double Tap ===== ===== Double Tap =====
 +Simple Double tap detection to run a combo:
 +<code gpc2>
 +main {
 +  // BUTTON_17 has to be pressed twice faster than 200ms
 +  if (event_active(BUTTON_17) && time_release(BUTTON_17) < 200) {
 +    combo_run(cCmb);​
 +  }
 +}
 +
 +combo cCmb {
 +  set_val(BUTTON_14,​100);​ // press button
 +  wait(400); ​             // (press) for 400ms
 +  set_val(BUTTON_14,​0); ​  // release button
 +  wait(400); ​             // (release) for 400ms
 +}
 +</​code>​
 +
 Toggle the state on/off by double press of BUTTON_17 faster than 200ms. \\  Toggle the state on/off by double press of BUTTON_17 faster than 200ms. \\ 
 printf will write the text and value of bEnabled to the Output Panel of GTuner IV. \\  printf will write the text and value of bEnabled to the Output Panel of GTuner IV. \\ 
Line 155: Line 227:
 </​code>​ </​code>​
  
 +This will set bEnabled to TRUE on double press of the button and run the combo.\\ ​
 +Keep the button pressed on the second press to repeat the combo.\\ ​
 +Releasing the button will set bEnabled to FALSE, no longer repeating the combo.
 +<code gpc2>
 +bool bEnabled=FALSE;​
 +
 +main {
 +  if (event_active(BUTTON_17) && time_release(BUTTON_17) <= 200) { // start
 +      bEnabled = TRUE;
 +      printf("​Double Tap");
 +  }
 +  if (event_release(BUTTON_17)) bEnabled = FALSE; // stop repeating on release
 +  ​
 +  if (bEnabled) combo_run(cRepeat);​
 +}
 +
 +combo cRepeat {
 +  set_val(BUTTON_17,​100);​ // press button
 +  wait(200); ​             // (press) for 200ms
 +  set_val(BUTTON_17,​0); ​  // release button
 +  wait(200); ​             // (release) for 200ms
 +}
 +</​code>​
 +
 +===== Script On/Off =====
 +Press [Touch-Click|View] + [CROSS|A] to quickly enable/​disable the script without unload the Memory Slot.
 +<code gpc2>
 +bool bScript=FALSE;​
 +
 +main {
 +    // Playstation:​ Touch-Click + CROSS , XBox: View + A
 +    if (get_actual(BUTTON_2) && event_active(BUTTON_16)) bScript = !bScript;
 +    ​
 +    if (bScript) {
 +        // Add your code to run when script is enabled here
 +        ​
 +    }
 +}
 +
 +</​code>​
 ===== Anti Recoil ===== ===== Anti Recoil =====
 Anti Recoil moves the Aim Stick downward automatically to compensate the recoil of weapon when firing. Anti Recoil moves the Aim Stick downward automatically to compensate the recoil of weapon when firing.
Line 256: Line 368:
 ===== Rapid Fire ===== ===== Rapid Fire =====
 Rapid Fire does press and release the fire button while you are holding down the fire button. Rapid Fire does press and release the fire button while you are holding down the fire button.
 +
 +=== Simple Rapid Fire ===
 +When you hold down the fire button the script will press and release the button fast.
 +<code gpc2>
 +// Simple Rapid Fire
 +main {
 +  // run rapid fire only when press BUTTON_5
 +  if (is_active(BUTTON_5)) combo_run(cRapidFire);​
 +  // stop when releasing button
 +  if (event_release(BUTTON_5)) combo_stop(cRapidFire);​
 +}
 +
 +combo cRapidFire {
 +  set_val(BUTTON_5,​100);​ // press button 5
 +  wait(40); ​             // (press) for 40ms
 +  set_val(BUTTON_5,​0); ​  // release button 5
 +  wait(40); ​             // (release) for 40ms
 +}
 +</​code>​
 +
 === Toggle Rapid Fire === === Toggle Rapid Fire ===
 While holding BUTTON_8 press BUTTON_10 to toggle Rapid Fire usage on/off. While holding BUTTON_8 press BUTTON_10 to toggle Rapid Fire usage on/off.
Line 315: Line 447:
       set_val(STICK_1_X,​ clamp(get_val(STICK_1_X) * SENSITIVITY,​ -100.0, 100.0));       set_val(STICK_1_X,​ clamp(get_val(STICK_1_X) * SENSITIVITY,​ -100.0, 100.0));
       set_val(STICK_1_Y,​ clamp(get_val(STICK_1_Y) * SENSITIVITY,​ -100.0, 100.0));       set_val(STICK_1_Y,​ clamp(get_val(STICK_1_Y) * SENSITIVITY,​ -100.0, 100.0));
-    ​]+    ​}
 } }
 </​code>​ </​code>​
t2/gpc_scripting/examples_1.1557157265.txt.gz · Last modified: 2019/05/06 11:41 by scachi