Mouse movement issues with rapid and recoil script.
7 posts
• Page 1 of 1
Mouse movement issues with rapid and recoil script.
Here is a script for Rapid fire and recoil for XBox X|S
I am using a Xim with a Azeron and Mouse as well as a keyboard plugged directly into the Titan2 (for switching modes)
Keyboard Buttons:
Q = Toggle Primary Recoil
W = Toggle Secondary Recoil
O = Toggle Primary Rapid Fire
P = Toggle Secondary Rapid Fire
As you toggle them on or off the display shows 0 for off and 1 for on
XBox 'Y' Button - Toggle Primary and Secondary
Display shows P for Primary and S for secondary
It's a work in progress for led signals as well
Anyway, I have an issue with the mouse movement. If you keep the mouse still (right stick via the Xim) the recoil works fine, however, if you move the mouse 'sometimes' the recoil jumps alarmingly as if it is fighting the mouse movement and then just gives up and it steps down miles.
This is my first coding exercise in GPC2 (I only started yesterday). Any comments on coding practises would be appreciated (the Titan2 is running at 0.90% cpu with this script).
I am using a Xim with a Azeron and Mouse as well as a keyboard plugged directly into the Titan2 (for switching modes)
Keyboard Buttons:
Q = Toggle Primary Recoil
W = Toggle Secondary Recoil
O = Toggle Primary Rapid Fire
P = Toggle Secondary Rapid Fire
As you toggle them on or off the display shows 0 for off and 1 for on
XBox 'Y' Button - Toggle Primary and Secondary
Display shows P for Primary and S for secondary
It's a work in progress for led signals as well
- Code: Select all
#pragma METAINFO("Switchable Recoil and auto-fire", 1, 0, "Coilover")
#include <keyboard.gph>
#include <display.gph>
bool bPrimaryRapid = FALSE;
bool bPrimaryAntiRecoil = FALSE;
bool bSecondaryRapid = FALSE;
bool bSecondaryAntiRecoil = FALSE;
bool bSecondaryWeapon = FALSE;
// The stored keys - used to ensure keystrokes or button presses are not repeated - e.g. clean toggles
bool bStoredStatus_Key1 = FALSE;
bool bStoredStatus_Key2 = FALSE;
bool bStoredStatus_Key3 = FALSE;
bool bStoredStatus_Key4 = FALSE;
bool bStoredStatus_Key5 = FALSE;
// You can adjust this value to the resting values of your right stick. Use the Device Monitor,
// move the sticks around and release them a couple of time. Put in the maximum resting value of your stick.
#define StickNoise 2.00
// vertical recoil setting
fix32 PrimaryRECOIL_V = 28.0;
fix32 SecondaryRECOIL_V = 5.0;
// horizontal recoil setting
fix32 PrimaryRECOIL_H = 0.0;
fix32 SecondaryRECOIL_H = 0.0;
main {
// Set Booleans - used to ensure keystrokes or button presses are not repeated - e.g. clean toggles
bool bCurrentStatus_Key1;
bool bCurrentStatus_Key2;
bool bCurrentStatus_Key3;
bool bCurrentStatus_Key4;
bool bCurrentStatus_Key5;
// toggle Keyboard Primary rapid fire
bCurrentStatus_Key1 = key_status(KEY_Q);
//On Hold
if (bCurrentStatus_Key1 && bStoredStatus_Key1) {
set_val(BUTTON_21,99.99);
}
//On Release
if (!bCurrentStatus_Key1 && bStoredStatus_Key1) {
printf("Key Up - key Q");
bPrimaryRapid = !bPrimaryRapid;
if (bPrimaryRapid) {
display_overlay(_1_,1000);
}
else {
display_overlay(_0_,1000);
}
SetDisplay();
}
bStoredStatus_Key1 = bCurrentStatus_Key1;
// toggle Keyboard Primary recoil
bCurrentStatus_Key2 = key_status(KEY_W);
//On Hold
if (bCurrentStatus_Key2 && bStoredStatus_Key2) {
set_val(BUTTON_21,99.99);
}
//On Release
if (!bCurrentStatus_Key2 && bStoredStatus_Key2) {
printf("Key Up - key W");
bPrimaryAntiRecoil = !bPrimaryAntiRecoil;
if (bPrimaryAntiRecoil) {
display_overlay(_1_,1000);
}
else {
display_overlay(_0_,1000);
}
SetDisplay();
}
bStoredStatus_Key2 = bCurrentStatus_Key2;
// toggle Keyboard Secondary rapid fire
bCurrentStatus_Key3 = key_status(KEY_O);
//On Hold
if (bCurrentStatus_Key3 && bStoredStatus_Key3) {
set_val(BUTTON_21,99.99);
}
//On Release
if (!bCurrentStatus_Key3 && bStoredStatus_Key3) {
printf("Key Up - key O");
bSecondaryRapid = !bSecondaryRapid;
if (bSecondaryRapid) {
display_overlay(_1_,1000);
}
else {
display_overlay(_0_,1000);
}
SetDisplay();
}
bStoredStatus_Key3 = bCurrentStatus_Key3;
// toggle Keyboard Secondary recoil
bCurrentStatus_Key4 = key_status(KEY_P);
//On Hold
if (bCurrentStatus_Key4 && bStoredStatus_Key4) {
set_val(BUTTON_21,99.99);
}
//On Release
if (!bCurrentStatus_Key4 && bStoredStatus_Key4) {
printf("Key Up - key P");
bSecondaryAntiRecoil = !bSecondaryAntiRecoil;
if (bSecondaryAntiRecoil) {
display_overlay(_1_,1000);
}
else {
display_overlay(_0_,1000);
}
SetDisplay();
}
bStoredStatus_Key4 = bCurrentStatus_Key4;
// toggle Primary/Secondary
bCurrentStatus_Key5 = is_active(BUTTON_14);
// On Press
if (bCurrentStatus_Key5 && !bStoredStatus_Key5) {
printf("Key Down - XBox X");
}
//On Hold
if (bCurrentStatus_Key5 && bStoredStatus_Key5) {
set_val(BUTTON_21,99.99);
}
//On Release
if (!bCurrentStatus_Key5 && bStoredStatus_Key5) {
printf("Key Up - key XBox X");
bSecondaryAntiRecoil = !bSecondaryAntiRecoil;
if (bSecondaryAntiRecoil) {
display_overlay(_S_,2000);
}
else {
display_overlay(_P_,2000);
}
SetDisplay();
}
bStoredStatus_Key5 = bCurrentStatus_Key5;
// run rapid fire only when it is enabled and you press BUTTON_5
if (bPrimaryRapid && !bSecondaryWeapon) {
if (is_active(BUTTON_5)) combo_run(cPrimaryRapidFire);
if (event_release(BUTTON_5)) combo_stop(cPrimaryRapidFire);
}
if (bSecondaryRapid && bSecondaryWeapon) {
if (is_active(BUTTON_5)) combo_run(cSecondaryRapidFire);
if (event_release(BUTTON_5)) combo_stop(cSecondaryRapidFire);
}
// only use when bPrimaryAntiRecoil is TRUE and firing
if (bPrimaryAntiRecoil && !bSecondaryWeapon && get_val(BUTTON_5)) {
// Remove small unwanted movement as your controller sticks may not return to zero exactly after release.
if (abs(get_actual(STICK_1_X)) < StickNoise) {
set_val(STICK_1_X, 0.0);
}
if (abs(get_actual(STICK_1_Y)) < StickNoise) {
set_val(STICK_1_Y, 0.0);
}
AntiRecoil(STICK_1_Y,PrimaryRECOIL_V); // Y Axis - vertical recoil compensation
AntiRecoil(STICK_1_X,PrimaryRECOIL_H); // X Axis - horizontal recoil compensation
}
if (bSecondaryAntiRecoil && bSecondaryWeapon && get_val(BUTTON_5)) {
// Remove small unwanted movement as your controller sticks may not return to zero exactly after release.
if (abs(get_actual(STICK_1_X)) < StickNoise) {
set_val(STICK_1_X, 0.0);
}
if (abs(get_actual(STICK_1_Y)) < StickNoise) {
set_val(STICK_1_Y, 0.0);
}
AntiRecoil(STICK_1_Y,SecondaryRECOIL_V); // Y Axis - vertical recoil compensation
AntiRecoil(STICK_1_X,SecondaryRECOIL_H); // X Axis - horizontal recoil compensation
}
}
// Void Anti Recoil
void AntiRecoil (uint8 axis, fix32 recoil) {
fix32 RY = get_actual(STICK_1_Y); // read the actual stick y value
fix32 RX = get_actual(STICK_1_X); // read the actual sitck x value
// only apply anti recoil if the actual movement of x&y is lower than the recoil to apply
if (get_val(BUTTON_5) && (sqrt(RX*RX + RY*RY)) <= abs(recoil))
{
if(abs(RY) <= abs(recoil)) // only apply when y movement is lower than the recoil to apply
{
set_val(axis,(recoil * (100.0 - abs(get_val(axis)))) / 100.0 + get_val(axis));
}
}
}
void SetDisplay () {
if (bPrimaryRapid && !bPrimaryAntiRecoil) {
led_set(LED_1, 50.0, 400);
led_set(LED_2, 0.0, 0);
led_set(LED_3, 0.0, 0);
led_set(LED_4, 0.0, 0);
}
else if (!bPrimaryRapid && bPrimaryAntiRecoil) {
led_set(LED_1, 0.0, 0);
led_set(LED_2, 50.0, 400);
led_set(LED_3, 0.0, 0);
led_set(LED_4, 0.0, 0);
}
else if (bPrimaryRapid && bPrimaryAntiRecoil) {
led_set(LED_1, 50.0, 400);
led_set(LED_2, 50.0, 400);
led_set(LED_3, 50.0, 400);
led_set(LED_4, 0.0, 0);
}
else {
led_reset();
}
}
// Combo Rapid Fire
combo cPrimaryRapidFire {
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
}
combo cSecondaryRapidFire {
set_val(BUTTON_5,100); // press button 5
wait(200); // (press) for 80ms
set_val(BUTTON_5,0); // release button 5
wait(200); // (release) for 80ms
}
Anyway, I have an issue with the mouse movement. If you keep the mouse still (right stick via the Xim) the recoil works fine, however, if you move the mouse 'sometimes' the recoil jumps alarmingly as if it is fighting the mouse movement and then just gives up and it steps down miles.
This is my first coding exercise in GPC2 (I only started yesterday). Any comments on coding practises would be appreciated (the Titan2 is running at 0.90% cpu with this script).
-
Coilover - Staff Sergeant
- Posts: 15
- Joined: Thu Nov 04, 2021 6:59 pm
Re: Mouse movement issues with rapid and recoil script.
To fix this for XIM check if STICK_1_X is released before applying horizontal recoil compensation.
- Code: Select all
if(is_release(STICK_1_X)) AntiRecoil(STICK_1_X,PrimaryRECOIL_H);
ConsoleTuner Support Team || ConsoleTuner Discord || InputSense Discord
- Mad
- Major General
- Posts: 4536
- Joined: Wed May 22, 2019 5:39 am
Re: Mouse movement issues with rapid and recoil script.
Hi Mad,
Cheers for the pointer. I will mod the script, test and post results.
Cheers for the pointer. I will mod the script, test and post results.
-
Coilover - Staff Sergeant
- Posts: 15
- Joined: Thu Nov 04, 2021 6:59 pm
Re: Mouse movement issues with rapid and recoil script.
Hi,
Did some experiments today with this on R6 Siege and it makes it 'better' but not reliable enough for use in-game.
With rapid fire on I get a nice straight line up the wall with most weapons on single fire.
Use rapid fire + recoil control and I get laser flat shooting... until I move the mouse and then it still produces some shocking jumps down, left, right, up. Just appears to be random.
I am currently exploring different recoil scripts.
My set-up is xim into Titan2, using Azeron and Mouse.
Did some experiments today with this on R6 Siege and it makes it 'better' but not reliable enough for use in-game.
With rapid fire on I get a nice straight line up the wall with most weapons on single fire.
Use rapid fire + recoil control and I get laser flat shooting... until I move the mouse and then it still produces some shocking jumps down, left, right, up. Just appears to be random.
I am currently exploring different recoil scripts.
My set-up is xim into Titan2, using Azeron and Mouse.
-
Coilover - Staff Sergeant
- Posts: 15
- Joined: Thu Nov 04, 2021 6:59 pm
Re: Mouse movement issues with rapid and recoil script.
For R6 try the universal gamepack
Select one of these anti recoil options drnefario, j2kbr dz comp, dontatme v2 and enter 20 for deadzone compensation.
Select one of these anti recoil options drnefario, j2kbr dz comp, dontatme v2 and enter 20 for deadzone compensation.
ConsoleTuner Support Team || ConsoleTuner Discord || InputSense Discord
- Mad
- Major General
- Posts: 4536
- Joined: Wed May 22, 2019 5:39 am
Re: Mouse movement issues with rapid and recoil script.
Hi Mad,
I was hoping to find a script that I could incorporate into my own custom script.
I am also very interested about the theory of recoil control and how polling rates affect it. Some of the downloadable packs suggest 500Mhz polling as a max and tuning the Titan to match. How does this affect the recoil ?
I assume that there is some matching of rates to ensure that there is not any 'cross chatter' upsetting the recoil control.
Very interested in the mechanics of how to get the best solution and getting under the bonnet of how best to achieve robust solutions.
really enjoying the scripting process and the hardware by the way.
I was hoping to find a script that I could incorporate into my own custom script.
I am also very interested about the theory of recoil control and how polling rates affect it. Some of the downloadable packs suggest 500Mhz polling as a max and tuning the Titan to match. How does this affect the recoil ?
I assume that there is some matching of rates to ensure that there is not any 'cross chatter' upsetting the recoil control.
Very interested in the mechanics of how to get the best solution and getting under the bonnet of how best to achieve robust solutions.
really enjoying the scripting process and the hardware by the way.
-
Coilover - Staff Sergeant
- Posts: 15
- Joined: Thu Nov 04, 2021 6:59 pm
Re: Mouse movement issues with rapid and recoil script.
Same question regarding polling rate impacts on recoil control. I'm currently using 250hz on Xim app and T2 (input and output). I need to test again with 500 and 1000hz to see the differences.
-
Nagato - Sergeant First Class
- Posts: 19
- Joined: Tue May 11, 2021 12:21 pm
7 posts
• Page 1 of 1
Return to GPC2 Script Programming
Who is online
Users browsing this forum: No registered users and 67 guests