HID Scripting help needed
44 posts
• Page 4 of 5 • 1, 2, 3, 4, 5
Re: HID Scripting help needed
You can use any key you want and toggle a flag to disable/enable the whole scripts or parts of it or just keep it held down for disabling the script.
so use some kind of key_event function/header file to toggle or directly use key_status for disabling a flag/script as long holding it down.
if(get_actual(STICK_2_Y) < -98.0) is true as long as you hold the stick forward.
if you want to trigger that once set a flag and reset that flag when the stick is no longer in that range.
Something like that:
so use some kind of key_event function/header file to toggle or directly use key_status for disabling a flag/script as long holding it down.
if(get_actual(STICK_2_Y) < -98.0) is true as long as you hold the stick forward.
if you want to trigger that once set a flag and reset that flag when the stick is no longer in that range.
Something like that:
- Code: Select all
bool bStickForw = FALSE;
main {
if(get_actual(STICK_2_Y) < -98.0) {
if (!bStickForw) { // to only trigger once
bStickForw=TRUE;
// your stuff to run once here
// ...
}
} else {
bStickForw=FALSE; // reset flag on stick not full forward
}
}
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: HID Scripting help needed
thank you the code worked like a charm but i need to work on the combo to go with it.
but how do i disable this anti-recoil only while maintaining the rest of the script by holding down the "Y" key?
but how do i disable this anti-recoil only while maintaining the rest of the script by holding down the "Y" key?
- Code: Select all
#pragma METAINFO("Mouse Amax", 1, 0, "Scachi")
#include <keyboard.gph>
#include <mouse.gph>
#include <mouse_events.gph>
#include <key_events.gph>
#include <ps4.gph>
#define XKEYS_TO_MONITOR_MAX 5 // change 2 to the maximum number of keys you want to keep track of
#include "xkeys.gph"
// configuration
// advanced configuration
const int MOUSE_SPEED = 10; // <- should be around 10 or higher, a value too low can stop the mouse from working
// internal
fix32 antirecoil_X;
fix32 antirecoil_Y;
uint32 ARTIMER;
int32 X, Y, WHEEL;
int32 RX, RY;
fix32 ARX, ARY;
// mouse press time tracker for staged anti recoil
uint32 mb1timer;
uint8 KEY1, KEY2; // or any other name, this will get an index number assigned by the xkeys_add function
bool bStickForw = FALSE;
bool check_active(uint8 io, uint32 ms);
init {
port_connect(PORT_USB_C, PROTOCOL_HID);
keymapping();
mousemapping();
// use xkeys_add to add each key to monitor, it returns an uint8 number that has to be used with the functions
KEY1=xkeys_add(KEY_1); // add key KEY_A to monitoring
KEY2=xkeys_add(KEY_F); // add key KEY_S to monitoring
}
main {
key_passthru();
mouse_passthru();
X = 0; Y = 0; WHEEL = 0;
RX = 0; RY = 0;
if(mouse_status(MREPORT_UPDATED)) {
mouse_passthru(); // only passthru when there is data to send
X = mouse_status(MOUSE_X);
Y = mouse_status(MOUSE_Y);
WHEEL = mouse_status(MOUSE_WHEEL);
}
if(mouse_status(MBUTTON_1))
{
ARTIMER += elapsed_time(); // mouse speed timer
mb1timer += elapsed_time(); // mouse button press timer
// ADJUST VALUES & TIME and add more here as required
if (mb1timer < 95) { antirecoil_X = 5.0; antirecoil_Y = 6.0; }
else if (mb1timer < 300) { antirecoil_X = 2.0; antirecoil_Y = 6.0; }
else if (mb1timer < 900) { antirecoil_X = 0.0; antirecoil_Y = 4.0; }
else if (mb1timer < 1300) { antirecoil_X = -0.95; antirecoil_Y = 2.0; }
else if (mb1timer < 3000) { antirecoil_X = -0.95; antirecoil_Y = 2.0; }
else if (mb1timer < 6000) { antirecoil_X = -0.95; antirecoil_Y = 2.0; }
if(!(ARTIMER%MOUSE_SPEED)) {
ARX += (fix32)(antirecoil_X);
ARY += (fix32)(antirecoil_Y);
if (antirecoil_X < 0.0) RX += (int)ceil((ARX));
else RX += (int)floor((ARX));
if (antirecoil_Y < 0.0) RY += (int)ceil((ARY));
else RY += (int)floor((ARY));
mouse_set(MOUSE_X, X+RX);
mouse_set(MOUSE_Y, Y+RY);
mouse_set(MOUSE_WHEEL,WHEEL);
ARX = mod(ARX,1.0);
ARY = mod(ARY,1.0);
}
} else {
ARTIMER = MOUSE_SPEED; // reset mouse speed timer
ARX = 0.0; ARY = 0.0;
mb1timer = 0; // reset mouse button press timer
}
//PING
if(mouse_event_active(MBUTTON_1)) {
combo_run(ping);}
//HOLD BREATH
if(mouse_event_active(MBUTTON_2)){
combo_run(HB);}
//RAPID FIRE
if(key_status(KEY_Y) & (mouse_status(MBUTTON_1))) {
combo_run(RF);}
//SLIDE CANCEL
if(key_status(KEY_U) ) {
combo_run(SC);}
// RELOAD & ACTION
if (xkeys_is_active(KEY2) && xkeys_time_active(KEY2) > 100) {
key_set(KEY_R, 100);}
if (xkeys_is_active(KEY1) && xkeys_time_active(KEY1) > 300) {
combo_run(SC);}
//weapon switch & armor key
if (xkeys_is_active(KEY1) && xkeys_time_active(KEY1) > 400) {
key_set(KEY_1, 0);
key_set(KEY_4, 100);}
// REMAPING
// STICK FORWARD
if(get_actual(STICK_2_Y) < -40.0) {
key_set(KEY_W, 100);}
if(get_actual(STICK_2_Y) < -98.0) {
combo_run(TS);}
// STICK BACKWARD
if(get_actual(STICK_2_Y) > 50.0) {
key_set(KEY_S, 100);}
// STICK RIGHT
if(get_actual(STICK_2_X) > 50.0) {
key_set(KEY_D, 100);}
// STICK LEFT
if(get_actual(STICK_2_X) < -50.0) {
key_set(KEY_A, 100);}
// PS3 NAV L2
if(get_val(BUTTON_8)) {
key_set(KEY_SPACEBAR, 100);}
// PS3 NAV L1
if(get_val(BUTTON_7)) {
key_set(KEY_C, 100);}
// PS3 NAV L3
if(get_val(BUTTON_9)) {
key_set(KEY_LEFTSHIFT, 0);}
// PS3 NAV CIRCLE
if(get_val(BUTTON_15)) {
key_set(KEY_ESCAPE, 100);}
// PS3 NAV CROSS
if(get_val(BUTTON_16)) {
key_set(KEY_RETURNORENTER, 100);}
// PS3 NAV PS BUTTON
if(get_val(BUTTON_1)) {
key_set(KEY_M, 100);}
// PS3 NAV DOWN
if(get_val(BUTTON_11)) {
key_set(KEY_L, 100);}
// PS3 NAV UP
if(get_val(BUTTON_10)) {
key_set(KEY_LEFTALT, 100);}
// PS3 NAV RIGHT
if(get_val(BUTTON_13)) {
key_set(KEY_3, 100);}
// PS3 NAV LEFT
if(get_val(BUTTON_12)) {
key_set(KEY_M, 0);}
}
combo ping {
key_set(KEY_LEFTALT, 100);
wait(30);
key_set(KEY_LEFTALT, 0);
wait(80);
key_set(KEY_LEFTALT, 100);
wait(30);
key_set(KEY_LEFTALT, 0);
wait(1000);
}
combo RF {
mouse_set(MBUTTON_1, 100);
wait(20);
mouse_set(MBUTTON_1, 0);
wait(20);
}
combo TS {
key_set(KEY_LEFTSHIFT, 100);
wait(40);
key_set(KEY_LEFTSHIFT, 0);
wait(40);
key_set(KEY_LEFTSHIFT, 100);
wait(40);
key_set(KEY_LEFTSHIFT, 0);
wait(40);
}
combo HB {
wait(100);
key_set(KEY_LEFTSHIFT, 100);
wait(5000);
}
combo SC {
key_set(KEY_C, 100);
wait(40);
key_set(KEY_C, 0);
wait(200);
key_set(KEY_C, 100);
wait(40);
key_set(KEY_C, 0);
wait(40);
key_set(KEY_SPACEBAR, 100);
wait(40);
key_set(KEY_SPACEBAR, 0);
wait(800);
}
-
TT3000 - Master Sergeant
- Posts: 35
- Joined: Fri Nov 20, 2020 7:58 pm
Re: HID Scripting help needed
Also xkeys is amazing is there anything alike for mouse? With timer based functions?
-
TT3000 - Master Sergeant
- Posts: 35
- Joined: Fri Nov 20, 2020 7:58 pm
Re: HID Scripting help needed
One option to disable anti recoil is to add your keypress not pressed check to that line:
if(mouse_status(MBUTTON_1))
I don't know about a mouse header file with time tracking.
Code one yourself, use that mouse_event_active to set a custom timer (some uint32) for each mouse button you want to track to system_time() and you are almost done.
When you want to get the time since last button press use system_time() - YourButtonUint32.
if(mouse_status(MBUTTON_1))
I don't know about a mouse header file with time tracking.
Code one yourself, use that mouse_event_active to set a custom timer (some uint32) for each mouse button you want to track to system_time() and you are almost done.
When you want to get the time since last button press use system_time() - YourButtonUint32.
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: HID Scripting help needed
thank you scachi
I actually ended up making it so that it only activates if I hold mouse button 2 as well (since I only need it if I aim and shoot)
because I'm coming from t1 (and even then I wasn't fully into coding for it) I can't wrap my head around uint32 and bool and all these new words lol
tried to code a timer myself and wouldn't work as I had no clue or examples I could find.
I actually ended up making it so that it only activates if I hold mouse button 2 as well (since I only need it if I aim and shoot)
because I'm coming from t1 (and even then I wasn't fully into coding for it) I can't wrap my head around uint32 and bool and all these new words lol
tried to code a timer myself and wouldn't work as I had no clue or examples I could find.
-
TT3000 - Master Sergeant
- Posts: 35
- Joined: Fri Nov 20, 2020 7:58 pm
Re: HID Scripting help needed
TT3000 wrote:thank you scachi
I actually ended up making it so that it only activates if I hold mouse button 2 as well (since I only need it if I aim and shoot)
because I'm coming from t1 (and even then I wasn't fully into coding for it) I can't wrap my head around uint32 and bool and all these new words lol
tried to code a timer myself and wouldn't work as I had no clue or examples I could find.
I think in gpc1 everything was int16.
Now you have different datatypes with different possible value ranges to use: https://www.consoletuner.com/wiki/index ... data_types
Something like that should work as a timer for mouse button press time as an example:
- Code: Select all
#include <mouse.gph>
uint32 mt1;
main {
if (!mouse_status(MBUTTON_1)) mt1=system_time(); // updates timer when mouse button is not pressed
if (system_time()-mt1 > 1000) printf("mouse button 1 active > 1000ms"); // check for some time delta for button press time
}
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: HID Scripting help needed
ok so how do we then get this to trigger an action?
-
TT3000 - Master Sergeant
- Posts: 35
- Joined: Fri Nov 20, 2020 7:58 pm
Re: HID Scripting help needed
TT3000 wrote:ok so how do we then get this to trigger an action?
- Code: Select all
if (system_time()-mt1 > 1000) printf("mouse button 1 active > 1000ms");
Replace 1000ms with the time you want, replace the printf with the action you want.
ConsoleTuner Support Team || ConsoleTuner Discord || InputSense Discord
- Mad
- Major General
- Posts: 4536
- Joined: Wed May 22, 2019 5:39 am
Re: HID Scripting help needed
oh thank you so much this script is coming together nicely. at this point, you've pretty much made the whole script lol
-
TT3000 - Master Sergeant
- Posts: 35
- Joined: Fri Nov 20, 2020 7:58 pm
Re: HID Scripting help needed
the script is almost complete
my only question would be.
the anti-recoil doesn't seem to have a bypass mode or ignore mode for when I make corrections with my mouse (if the gun goes a little bit too much to the right and I try to correct for it the script seems to be fighting my input)
here is what used to have (a release of sorts with a threshold)
here is the current script
my only question would be.
the anti-recoil doesn't seem to have a bypass mode or ignore mode for when I make corrections with my mouse (if the gun goes a little bit too much to the right and I try to correct for it the script seems to be fighting my input)
here is what used to have (a release of sorts with a threshold)
- Code: Select all
define Release = 13;
main {
if ((get_val(PS4_L2)) && (get_val(PS4_R2))) {
if(get_ptime(PS4_R2) <= 95)
{
ARV = 29;
ARH = 7;
}
if(get_ptime(PS4_R2) >= 95)
{
ARV = 29;
ARH = 5;
}
if(get_ptime(PS4_R2) > 300)
{
ARV = 27;
ARH = 3;
}
if(get_ptime(PS4_R2) > 900)
{
ARV = 19;
ARH = -7;
}
if(get_ptime(PS4_R2) > 1300)
{
ARV = 17;
ARH = -5;
}
if(get_ptime(PS4_R2) > 2000)
{
ARV = 17;
ARH = -2;
}
combo_run(c_AntiRecoilak);
}
else combo_stop(c_AntiRecoilak);
if (abs(get_val(PS4_RY)) > Release|| abs(get_val(PS4_RX)) > Release) combo_stop(c_AntiRecoilak);
}
here is the current script
- Code: Select all
#pragma METAINFO("Mouse Amax", 1, 0, "Scachi")
#include <keyboard.gph>
#include <mouse.gph>
#include <mouse_events.gph>
#include <key_events.gph>
#include <ps4.gph>
#define XKEYS_TO_MONITOR_MAX 5 // change 2 to the maximum number of keys you want to keep track of
#include "xkeys.gph"
// configuration
// advanced configuration
const int MOUSE_SPEED = 10; // <- should be around 10 or higher, a value too low can stop the mouse from working
// internal
fix32 antirecoil_X;
fix32 antirecoil_Y;
uint32 ARTIMER;
int32 X, Y, WHEEL;
int32 RX, RY;
fix32 ARX, ARY;
// mouse press time tracker for staged anti recoil
uint32 mb1timer;
uint32 mb1timerS;
uint8 KEY1, KEY2; // or any other name, this will get an index number assigned by the xkeys_add function
bool bStickForw = FALSE;
init {
port_connect(PORT_USB_C, PROTOCOL_HID);
keymapping();
mousemapping();
// use xkeys_add to add each key to monitor, it returns an uint8 number that has to be used with the functions
KEY1=xkeys_add(KEY_1); // add key KEY_A to monitoring
KEY2=xkeys_add(KEY_F); // add key KEY_S to monitoring
}
main {
key_passthru();
mouse_passthru();
X = 0; Y = 0; WHEEL = 0;
RX = 0; RY = 0;
if(mouse_status(MREPORT_UPDATED)) {
mouse_passthru(); // only passthru when there is data to send
X = mouse_status(MOUSE_X);
Y = mouse_status(MOUSE_Y);
WHEEL = mouse_status(MOUSE_WHEEL);
}
//PRIMARY RECOIL
if(mouse_status(MBUTTON_1) & mouse_status(MBUTTON_2))
{
ARTIMER += elapsed_time(); // mouse speed timer
mb1timer += elapsed_time(); // mouse button press timer
// ADJUST VALUES & TIME and add more here as required
if (mb1timer < 290) { antirecoil_X = 0.8; antirecoil_Y = 2.0; }
else if (mb1timer < 830) { antirecoil_X = -0.5; antirecoil_Y = 2.0; }
else if (mb1timer < 1200) { antirecoil_X = -1.1; antirecoil_Y = 1.7; }
else if (mb1timer < 2400) { antirecoil_X = -1.0; antirecoil_Y = 2.0; }
else if (mb1timer < 3000) { antirecoil_X = -0.99; antirecoil_Y = 1.99; }
else if (mb1timer < 6000) { antirecoil_X = -0.99; antirecoil_Y = 1.99; }
if(!(ARTIMER%MOUSE_SPEED)) {
ARX += (fix32)(antirecoil_X);
ARY += (fix32)(antirecoil_Y);
if (antirecoil_X < 0.0) RX += (int)ceil((ARX));
else RX += (int)floor((ARX));
if (antirecoil_Y < 0.0) RY += (int)ceil((ARY));
else RY += (int)floor((ARY));
mouse_set(MOUSE_X, X+RX);
mouse_set(MOUSE_Y, Y+RY);
mouse_set(MOUSE_WHEEL,WHEEL);
ARX = mod(ARX,1.0);
ARY = mod(ARY,1.0);
}
} else {
ARTIMER = MOUSE_SPEED; // reset mouse speed timer
ARX = 0.0; ARY = 0.0;
mb1timer = 0; // reset mouse button press timer
}
//SECONDARY RECOIL
if(mouse_status(MBUTTON_1) && mouse_status(MBUTTON_2) && key_status(KEY_Y))
{
ARTIMER += elapsed_time(); // mouse speed timer
mb1timerS += elapsed_time(); // mouse button press timer
// ADJUST VALUES & TIME and add more here as required
if (mb1timerS < 290) { antirecoil_X = 0.0; antirecoil_Y = 0.0; }
else if (mb1timerS < 830) { antirecoil_X = 0.0; antirecoil_Y = 0.0; }
else if (mb1timerS < 1200) { antirecoil_X = 0.0; antirecoil_Y = 0.0; }
else if (mb1timerS < 2400) { antirecoil_X = 0.0; antirecoil_Y = 0.0; }
else if (mb1timerS < 3000) { antirecoil_X = 0.0; antirecoil_Y = 0.0; }
else if (mb1timerS < 6000) { antirecoil_X = 0.0; antirecoil_Y = 0.0; }
if(!(ARTIMER%MOUSE_SPEED)) {
ARX += (fix32)(antirecoil_X);
ARY += (fix32)(antirecoil_Y);
if (antirecoil_X < 0.0) RX += (int)ceil((ARX));
else RX += (int)floor((ARX));
if (antirecoil_Y < 0.0) RY += (int)ceil((ARY));
else RY += (int)floor((ARY));
mouse_set(MOUSE_X, X+RX);
mouse_set(MOUSE_Y, Y+RY);
mouse_set(MOUSE_WHEEL,WHEEL);
ARX = mod(ARX,1.0);
ARY = mod(ARY,1.0);
}
} else {
ARTIMER = MOUSE_SPEED; // reset mouse speed timer
ARX = 0.0; ARY = 0.0;
mb1timerS = 0; // reset mouse button press timer
}
//PING
if(mouse_event_active(MBUTTON_1) & mouse_status(MBUTTON_2)) {
mouse_set(MBUTTON_1, 100);
combo_run(ping);}
//HOLD BREATH
if(mouse_event_active(MBUTTON_2)){
combo_run(HB);}
//DUAL RAPID FIRE
if(key_status(KEY_Y) & (mouse_status(MBUTTON_1))) {
combo_stop(TS);
combo_run(DRF);}
//SLIDE CANCEL
if(key_status(KEY_U) ) {
combo_run(SC);}
// RELOAD & ACTION
if (xkeys_is_active(KEY2) && xkeys_time_active(KEY2) > 100) {
key_set(KEY_R, 100);}
//Switch weapon does slide cancel
if (xkeys_is_active(KEY1) && (get_actual(STICK_2_Y) < -98.0) && xkeys_time_active(KEY1) > 300) {
combo_run(SC);}
//Switch weapon does armour up
if (xkeys_is_active(KEY1) && xkeys_time_active(KEY1) > 200) {
key_set(KEY_1, 0);
combo_run(AU);}
// REMAPING
// STICK FORWARD
if(get_actual(STICK_2_Y) < -40.0) {
key_set(KEY_W, 100);}
if(get_actual(STICK_2_Y) < -98.0) {
combo_run(TS);}
// STICK BACKWARD
if(get_actual(STICK_2_Y) > 50.0) {
key_set(KEY_S, 100);}
// STICK RIGHT
if(get_actual(STICK_2_X) > 50.0) {
key_set(KEY_D, 100);}
// STICK LEFT
if(get_actual(STICK_2_X) < -50.0) {
key_set(KEY_A, 100);}
// PS3 NAV L2
if(get_val(BUTTON_8)) {
key_set(KEY_SPACEBAR, 100);}
// PS3 NAV L1
if(get_val(BUTTON_7)) {
key_set(KEY_C, 100);}
// PS3 NAV L3
if(get_val(BUTTON_9)) {
key_set(KEY_LEFTSHIFT, 100);}
// PS3 NAV CIRCLE
if(get_val(BUTTON_15)) {
key_set(KEY_ESCAPE, 100);}
// PS3 NAV CROSS
if(get_val(BUTTON_16)) {
key_set(KEY_RETURNORENTER, 100);}
// PS3 NAV PS BUTTON
if(get_val(BUTTON_1)) {
key_set(KEY_M, 100);}
// PS3 NAV DOWN
if(get_val(BUTTON_11)) {
key_set(KEY_L, 100);}
// PS3 NAV UP
if(get_val(BUTTON_10)) {
key_set(KEY_LEFTALT, 100);}
// PS3 NAV RIGHT
if(get_val(BUTTON_13)) {
key_set(KEY_3, 100);}
// PS3 NAV LEFT
if(get_val(BUTTON_12)) {
key_set(KEY_M, 0);}
}
combo ping {
wait(50);
key_set(KEY_LEFTALT, 100);
wait(30);
key_set(KEY_LEFTALT, 0);
wait(80);
key_set(KEY_LEFTALT, 100);
wait(30);
key_set(KEY_LEFTALT, 0);
wait(300);
}
combo TS {
key_set(KEY_LEFTSHIFT, 100);
wait(40);
key_set(KEY_LEFTSHIFT, 0);
wait(40);
key_set(KEY_LEFTSHIFT, 100);
wait(40);
key_set(KEY_LEFTSHIFT, 0);
wait(40);
}
combo HB {
wait(100);
key_set(KEY_LEFTSHIFT, 100);
wait(5000);
}
combo AU {
key_set(KEY_4, 100);
wait(100);
}
combo DRF {
mouse_set(MBUTTON_1, 100);
mouse_set(MBUTTON_2, 100);
wait(20);
mouse_set(MBUTTON_1, 0);
mouse_set(MBUTTON_2, 0);
wait(20);
}
combo SC {
key_set(KEY_C, 100);
wait(40);
key_set(KEY_C, 0);
wait(200);
key_set(KEY_C, 100);
wait(40);
key_set(KEY_C, 0);
wait(40);
key_set(KEY_SPACEBAR, 100);
wait(40);
key_set(KEY_SPACEBAR, 0);
wait(800);
}
-
TT3000 - Master Sergeant
- Posts: 35
- Joined: Fri Nov 20, 2020 7:58 pm
44 posts
• Page 4 of 5 • 1, 2, 3, 4, 5
Return to GPC2 Script Programming
Who is online
Users browsing this forum: No registered users and 144 guests