Toggle error (event_press not working)

GPC script programming for Titan Two device. Code examples, how to, questions, requests.

Moderators: The_Rabid_Taco, pablosscripts, bonefisher

Toggle error (event_press not working)

Postby Derivates » Mon Feb 11, 2019 6:37 pm

Code: Select all
#define RAPID_FIRE_KEY     KEY_F1              // F1 enables/disables Rapid-Fire //
 
main {
  // toggle
  if (key_status(RAPID_FIRE_KEY)) RapidFire = !RapidFire;
  // run only when it is enabled and you press BUTTON_5
  if (RapidFire) {
  if (get_actual(BUTTON_8) && get_actual(BUTTON_5)) combo_run(cRapidFire);
      if (event_release(BUTTON_5)) combo_stop(cRapidFire);
  }
  }


I need help with this, the toggle for F1 worked perfectly fine yesterday, of course a lot of code is missing but I can't seem to replace key_status to event_press it says it's not declared. Please help.
User avatar
Derivates
First Sergeant
First Sergeant
 
Posts: 50
Joined: Sat Jan 19, 2019 6:15 pm

Re: Toggle error (event_press not working)

Postby Scachi » Mon Feb 11, 2019 7:13 pm

For the T2 it is event_active
But that isn't working for keys..only for buttons.
You can try this to get similar function for keyboard: viewtopic.php?f=23&t=10201
User avatar
Scachi
Colonel
Colonel
 
Posts: 1645
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Toggle error (event_press not working)

Postby Derivates » Mon Feb 11, 2019 7:27 pm

Scachi wrote:For the T2 it is event_active
But that isn't working for keys..only for buttons.
You can try this to get similar function for keyboard: viewtopic.php?f=23&t=10201

This is my script currently and I can't add the xkeys.gph for some reason..
By the way my code is a little messed up I started using main methods everywhere.. could you help me fixing and optimizing this script? Take your time.

Code: Select all
 
#pragma METAINFO("RainbowSixSiege_ModPack_byDerivates", 1, 0, "Derivates")
#include <keyboard.gph>
#include "xkeys.gph"
 
init {
    // Load an Keyboard Mapping to reproduce the default BF1 layout
    const uint8 map[] = {
        KEY_W,           STICK_2_Y | KEYMAP_NEGATIVE,     // Forward
        KEY_A,           STICK_2_X | KEYMAP_NEGATIVE,    // Left
        KEY_S,           STICK_2_Y,                        // Backwards
        KEY_D,           STICK_2_X,                    // Right
        KEY_R,           BUTTON_17,                   // Square
        KEY_SPACEBAR,    BUTTON_16,                  // Cross (X)
        KEY_C,           BUTTON_15,                    // Circle (O)
        KEY_1,             BUTTON_14,                   // Triangle
        KEY_LEFTALT,     BUTTON_9,                   // L3
        KEY_Q,           BUTTON_9,                  // L3
        KEY_E,           BUTTON_6,                // R3
        KEY_K,           BUTTON_7,                // L1
        KEY_L,           BUTTON_4,              // R1
        KEY_B,           BUTTON_10,                             // D-Pad-Up
        KEY_Z,           BUTTON_12,                            // D-Pad-Left
        KEY_6,           BUTTON_13,                        // D-Pad-Right
        KEY_5,           BUTTON_11,                       // D-Pad-Down
        KEY_TAB,         BUTTON_2,                          // Touch-Pad
        KEY_PRINTSCREEN, BUTTON_18,                     // Share
        KEY_ESCAPE,      BUTTON_3,                       // Options
        KEY_RIGHTGUI,      BUTTON_1,                      // PS-Button
    };
    keymapping(map);
}
 
// DEFINES
#define SLOW_WALK_KEY      KEY_LEFTCONTROL    // LEFT_CONTROL used to reduce left stick movent (no toggle)// (SETTINGS)
#define SPIN_KEY_180       KEY_X              // Press "T" to perform a 180 spin // (SETTINGS)
#define SPIN_KEY_360       KEY_T              // Press "T" to perform a 360 spin // (SETTINGS)
#define RAPID_FIRE_KEY     KEY_F1              // F1 enables/disables Rapid-Fire //
#define ANTI_RECOIL_KEY    KEY_F2             // F2        "         Anti-Recoil //
#define CROUCH_SPAM_KEY    KEY_F3             // F3        "         Crouch-Spam //
#define LEAN_SPAM_KEY      KEY_F4             // F4        "         Lean-Spam //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// TOGGLES
bool RapidFire = TRUE;
bool AntiRecoil = TRUE;
bool CrouchSpam = FALSE;
bool LeanSpam = FALSE;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// VARIABLES & DEFINES [SETTINGS]
fix32 RECOIL_V = 6.0;
#define SLOW_WALK_SPEED        60.0
#define SPIN_TIME_360  400 // Adjust for correct spin //
#define SPIN_TIME_180  235 // Adjust for correct spin //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                    // Slow-Movement
main {
    if(key_status(SLOW_WALK_KEY)) {
  if(get_val(STICK_2_X) <= -SLOW_WALK_SPEED) { set_val(STICK_2_X, -SLOW_WALK_SPEED); }
  if(get_val(STICK_2_X) >=  SLOW_WALK_SPEED) { set_val(STICK_2_X,  SLOW_WALK_SPEED); }
  if(get_val(STICK_2_Y) <= -SLOW_WALK_SPEED) { set_val(STICK_2_Y, -SLOW_WALK_SPEED); }
  if(get_val(STICK_2_Y) >=  SLOW_WALK_SPEED) { set_val(STICK_2_Y,  SLOW_WALK_SPEED); }
    }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                    // Spinning 180
main {
  if (key_status(SPIN_KEY_180)) {
    combo_run(cSpin180);
  }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                    // Spinning 360
main {
  if (key_status(SPIN_KEY_360)) {
    combo_run(cSpin360);
  }
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                    // Rapid-Fire
main {
  // toggle
  if (key_status(RAPID_FIRE_KEY)) RapidFire = !RapidFire;
  // run only when it is enabled and you press BUTTON_5
  if (RapidFire) {
  if (get_actual(BUTTON_8) && get_actual(BUTTON_5)) combo_run(cRapidFire);
      if (event_release(BUTTON_5)) combo_stop(cRapidFire);
  }
  }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                    // Anti-Recoil
main {
  // toggle
  if (key_status(ANTI_RECOIL_KEY)) AntiRecoil = !AntiRecoil;
  // run only when it is enabled and you press BUTTON_5
  if (AntiRecoil && get_val(BUTTON_5)) {
     set_val(STICK_1_Y,(RECOIL_V * (100.0 - abs(get_val(STICK_1_Y)))) / 100.0 + get_val(STICK_1_Y));
  } 
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                    // Crouch-Spam
main {
  // toggle
  if (key_status(CROUCH_SPAM_KEY)) CrouchSpam = !CrouchSpam;
  // run only when it is enabled and you press BUTTON_5
  if (CrouchSpam) {
  if (get_actual(BUTTON_8) && get_actual(BUTTON_5)) combo_run(cCrouchSpam);
      if (event_release(BUTTON_5)) combo_stop(cCrouchSpam)
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                    // Lean-Spam
main {
  // toggle
  if (key_status(LEAN_SPAM_KEY)) LeanSpam = !LeanSpam;
  // run only when it is enabled and you press BUTTON_5
  if (LeanSpam) {
  if (get_actual(BUTTON_8) && get_actual(BUTTON_5)) combo_run(cLeanSpam);
      if (event_release(BUTTON_5)) combo_stop(cLeanSpam);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                    // Parkour Mod
main {
  if (check_active(BUTTON_16,960)) combo_run(cParkour);
  if (event_release(BUTTON_16)) combo_stop(cParkour);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// COMBOS
combo cRapidFire {
  set_val(BUTTON_5,100);
  wait(64);
  set_val(BUTTON_5,0);
  wait(17);
}
combo cCrouchSpam {
  set_val(BUTTON_15,100);
  wait(25);
  set_val(BUTTON_15,0);
  wait(25);
}
combo cLeanSpam {
  set_val(BUTTON_9,100);
  wait(100);   
  set_val(BUTTON_6,100);
  wait(100);
}
combo cParkour {
  set_val(BUTTON_16,0);
  wait(80);
  set_val(BUTTON_16,100);
  wait(80);
}
combo cSpin180 {
  set_val(STICK_1_X,100);
  wait(SPIN_TIME_180); // Adjust settings at top of script //
  wait(0);
}
combo cSpin360 {
  set_val(STICK_1_X,100);
  wait(SPIN_TIME_360); // Adjust settings at top of script //
  wait(0);
}
 


Helps is always appreciated.
User avatar
Derivates
First Sergeant
First Sergeant
 
Posts: 50
Joined: Sat Jan 19, 2019 6:15 pm

Re: Toggle error (event_press not working)

Postby J2Kbr » Tue Feb 12, 2019 6:19 am

When accessing keyboard keys direct there is no builtin event detection, however, you can implement in the script as the following:
Code: Select all
#include <keyboard.gph>
 
#define RAPID_FIRE_KEY     KEY_F1              // F1 enables/disables Rapid-Fire //
 
bool RapidFire;
bool key_f1_event;
 
main {
    // Toggle
    if(key_status(RAPID_FIRE_KEY)) {
        if(!key_f1_event) {
            key_f1_event = TRUE;
            RapidFire = !RapidFire;
        }
    } else key_f1_event = FALSE;
}
 
ConsoleTuner Support Team
User avatar
J2Kbr
General of the Army
General of the Army
 
Posts: 16860
Joined: Tue Mar 18, 2014 1:39 pm

Re: Toggle error (event_press not working)

Postby Derivates » Tue Feb 12, 2019 5:11 pm

J2Kbr wrote:When accessing keyboard keys direct there is no builtin event detection, however, you can implement in the script as the following:
Code: Select all
code
 

I'm having issues assigning it to different toggles, worked first for Rapid Fire then tried for Lean Spam toggle and didn't work (im thinking the key_f1_event is only assigned for only one.. or something like that) I also have some specific bools set to true and false so i boot the script with specific toggles on and off.
Code: Select all
 
// DEFINES
#define SLOW_WALK_KEY      KEY_LEFTCONTROL    // LEFT_CONTROL used to reduce left stick movent (no toggle)// (SETTINGS)
#define SPIN_KEY_180       KEY_X              // Press "T" to perform a 180 spin // (SETTINGS)
#define SPIN_KEY_360       KEY_T              // Press "T" to perform a 360 spin // (SETTINGS)
#define RAPID_FIRE_KEY     KEY_F1              // F1 enables/disables Rapid-Fire //
#define ANTI_RECOIL_KEY    KEY_F2             // F2        "         Anti-Recoil //
#define CROUCH_SPAM_KEY    KEY_F3             // F3        "         Crouch-Spam //
#define LEAN_SPAM_KEY      KEY_F4             // F4        "         Lean-Spam //
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// TOGGLES
bool RapidFire = TRUE;
    bool key_f1_event;
bool AntiRecoil = TRUE;
bool CrouchSpam = FALSE;
bool LeanSpam = FALSE;
    bool key_f1_event;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                    // Rapid-Fire
main {
    // Toggle
    if(key_status(RAPID_FIRE_KEY)) {
        if(!key_f1_event) {
            key_f1_event = TRUE;
            RapidFire = !RapidFire;
        }
    } else key_f1_event = FALSE;
  if (RapidFire) {
  if (get_actual(BUTTON_8) && get_actual(BUTTON_5)) combo_run(cRapidFire);
      if (event_release(BUTTON_5)) combo_stop(cRapidFire);
  }
  }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                    // Lean-Spam
main {
    // Toggle
    if(key_status(LEAN_SPAM_KEY)) {
        if(!key_f1_event) {
            key_f1_event = TRUE;
            LeanSpam = !LeanSpam;
        }
    } else key_f1_event = FALSE;
  // run only when it is enabled and you press BUTTON_5
  if (LeanSpam) {
  if (get_actual(BUTTON_8) && get_actual(BUTTON_5)) combo_run(cLeanSpam);
      if (event_release(BUTTON_5)) combo_stop(cLeanSpam);
}
 
User avatar
Derivates
First Sergeant
First Sergeant
 
Posts: 50
Joined: Sat Jan 19, 2019 6:15 pm

Re: Toggle error (event_press not working)

Postby Scachi » Tue Feb 12, 2019 5:33 pm

You can't use the same variable name for different keys, you have used bool key_f1_event; twice.
You have to use unique names, like
Code: Select all
bool key_f1_event; // for F1
bool key_f2_event; // for F2
bool key_f3_event; //...
...
User avatar
Scachi
Colonel
Colonel
 
Posts: 1645
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Toggle error (event_press not working)

Postby Derivates » Tue Feb 12, 2019 7:43 pm

Scachi wrote:You can't use the same variable name for different keys, you have used bool key_f1_event; twice.
You have to use unique names, like
Code: Select all
bool key_f1_event; // for F1
bool key_f2_event; // for F2
bool key_f3_event; //...
...

Oh! Didn't notice the F1 was specifically for the key! How clumsy.. Thanks again Scachi.. :smile0203:
User avatar
Derivates
First Sergeant
First Sergeant
 
Posts: 50
Joined: Sat Jan 19, 2019 6:15 pm


Return to GPC Script Programming (Titan Two)

Who is online

Users browsing this forum: Buffy, enf004946 and 17 guests