Mouse scripting
9 posts
• Page 1 of 1
Mouse scripting
- Code: Select all
#pragma METAINFO("PC BATTALION 1944 Script", 1, 0, "GamingScene")
#include <keyboard.gph>
#include <mouse.gph>
// SCRIPT START
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
// INIT START
// ADS BOOST START
#define HIP_SENS 1.00
#define ADS_BOOST_SENS 1.00
#define ADS_BOOST_SENS1 2.15
#define ADS_BOOST_DELAY 200
uint8 ads_delay_timer;
// ADS BOOST END
init {
port_connect(PORT_USB_C, PROTOCOL_HID);keymapping();mousemapping();}
// INIT END
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
// MAIN START
main {
// HID PASSTHROUGH START
key_passthru();
mouse_passthru();
// HID PASSTHROUGH END
// RAPID FIRE START
if(mouse_status(MBUTTON_1)) {combo_run(RAPID_FIRE);}
// RAPID FIRE END
// ADS BOOST START
if(mouse_status(MBUTTON_2)) {if(ads_delay_timer < ADS_BOOST_DELAY) ads_delay_timer += elapsed_time();
mouse_set(MOUSE_X, clamp(mouse_get(MOUSE_X) * (HIP_SENS + (ADS_BOOST_SENS - HIP_SENS) * ((fix32)ads_delay_timer / (fix32)ADS_BOOST_DELAY)), -100.0, 100.0));
mouse_set(MOUSE_Y, clamp((MOUSE_Y) * (HIP_SENS + (ADS_BOOST_SENS1 - HIP_SENS) * ((fix32)ads_delay_timer / (fix32)ADS_BOOST_DELAY)), -100.0, 100.0));}
else ads_delay_timer = 0;}
// ADS BOOST END
// MAIN END
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
// COMBO START
// RAPID PICKUP COMBO START
combo RAPID_FIRE {
mouse_set(MBUTTON_1, 100);
wait(irand(92));
mouse_set(MBUTTON_1, 0);
wait(irand(52));
mouse_set(MBUTTON_1, 0);}
// RAPID PICKUP COMBO END
// COMBO END
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
// SCRIPT FUNCTIONS START
int irand(int scramble) {fix32 fraction = (fix32) scramble * 0.15;int vmin = scramble - (int) fraction;int vmax = scramble + (int) fraction;return(((int)(rand() * (fix32)(vmax + 1 - vmin))) + vmin);}
// SCRIPT FUNCTIONS END
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
// SCRIPT END
Can some one explain to me why the 'ADS BOOST' doesn't work?
-
GamingScene - Sergeant Major
- Posts: 104
- Joined: Sat May 26, 2018 6:17 pm
Re: Mouse scripting
You need to take care of different data types.
Lookup each function you are using in the GPC Language Reference and check if your variable matches the required data type.
Cast them where required of use a variable/number in the correct type:
https://www.consoletuner.com/wiki/index ... _explained
https://www.consoletuner.com/wiki/index ... data_types
You were very close to the correct types..you missed 1 : to match the "mouse_set" data type only (int32)
mouse_set requires the value to set in int32 type
in your second line you are missing (fix32)mouse_get before your MOUSE_Y
I haven't tested running it, but this compiles:
Lookup each function you are using in the GPC Language Reference and check if your variable matches the required data type.
Cast them where required of use a variable/number in the correct type:
https://www.consoletuner.com/wiki/index ... _explained
https://www.consoletuner.com/wiki/index ... data_types
You were very close to the correct types..you missed 1 : to match the "mouse_set" data type only (int32)
mouse_set requires the value to set in int32 type
in your second line you are missing (fix32)mouse_get before your MOUSE_Y
I haven't tested running it, but this compiles:
- Code: Select all
if(mouse_status(MBUTTON_2)) {if(ads_delay_timer < ADS_BOOST_DELAY) ads_delay_timer += elapsed_time();
mouse_set(MOUSE_X, (int32)clamp((fix32)mouse_get(MOUSE_X) * (HIP_SENS + (ADS_BOOST_SENS - HIP_SENS) * ((fix32)ads_delay_timer / (fix32)ADS_BOOST_DELAY)), -100.0, 100.0));
mouse_set(MOUSE_Y, (int32)clamp((fix32)mouse_get(MOUSE_Y) * (HIP_SENS + (ADS_BOOST_SENS1 - HIP_SENS) * ((fix32)ads_delay_timer / (fix32)ADS_BOOST_DELAY)), -100.0, 100.0));}
else ads_delay_timer = 0;}
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: Mouse scripting
Scachi wrote:You need to take care of different data types.
Lookup each function you are using in the GPC Language Reference and check if your variable matches the required data type.
Cast them where required of use a variable/number in the correct type:
https://www.consoletuner.com/wiki/index ... _explained
https://www.consoletuner.com/wiki/index ... data_types
You were very close to the correct types..you missed 1 : to match the "mouse_set" data type only (int32)
mouse_set requires the value to set in int32 type
in your second line you are missing (fix32)mouse_get before your MOUSE_Y
I haven't tested running it, but this compiles:
- Code: Select all
if(mouse_status(MBUTTON_2)) {if(ads_delay_timer < ADS_BOOST_DELAY) ads_delay_timer += elapsed_time();
mouse_set(MOUSE_X, (int32)clamp((fix32)mouse_get(MOUSE_X) * (HIP_SENS + (ADS_BOOST_SENS - HIP_SENS) * ((fix32)ads_delay_timer / (fix32)ADS_BOOST_DELAY)), -100.0, 100.0));
mouse_set(MOUSE_Y, (int32)clamp((fix32)mouse_get(MOUSE_Y) * (HIP_SENS + (ADS_BOOST_SENS1 - HIP_SENS) * ((fix32)ads_delay_timer / (fix32)ADS_BOOST_DELAY)), -100.0, 100.0));}
else ads_delay_timer = 0;}
- Code: Select all
// MOUSE ADS START
if(mouse_status(MBUTTON_2)) {if(ads_delay_timer < ADS_BOOST_DELAY) ads_delay_timer += elapsed_time();
mouse_set(MOUSE_X, (int32)clamp((fix32)mouse_get(MOUSE_X) * (HIP_SENS + (ADS_BOOST_SENS - HIP_SENS) * ((fix32)ads_delay_timer / (fix32)ADS_BOOST_DELAY)), -100.0, 100.0));
mouse_set(MOUSE_Y, (int32)clamp((fix32)mouse_get(MOUSE_Y) * (HIP_SENS + (ADS_BOOST_SENS1 - HIP_SENS) * ((fix32)ads_delay_timer / (fix32)ADS_BOOST_DELAY)), -100.0, 100.0));}
else ads_delay_timer = 0;}
// MOUSE ADS END
Ok so this now does kinda of what I wanted it to! Which was to increase the vertical movements of my mouse to help compensate for recoil in battalion 1944.
But I move my mouse in one direction and it constantly keeps moving in that direction how do I eliminate this?
-
GamingScene - Sergeant Major
- Posts: 104
- Joined: Sat May 26, 2018 6:17 pm
Re: Mouse scripting
If I remember correctly mouse_get will keep reporting the last value when there is currently no input.
You can try to check "mouse_status(MREPORT_UPDATED)" to test if there is some new mouse input and apply your mouse_set movement seperate by axis only if this check returns TRUE and MOUSE_X or MOUSE_Y is != 0
Try something like this:
Full example:
You can try to check "mouse_status(MREPORT_UPDATED)" to test if there is some new mouse input and apply your mouse_set movement seperate by axis only if this check returns TRUE and MOUSE_X or MOUSE_Y is != 0
Try something like this:
- Code: Select all
if (mouse_status(MREPORT_UPDATED)) {
mx = mouse_get(MOUSE_X);
my = mouse_get(MOUSE_Y);
if (mx) printf("x: %d",mx); // movement mod x here
if (my) printf("y: %d",my); // movement mod y here
}
Full example:
- Code: Select all
#include <mouse.gph>
int32 mx, my;
init {
port_connect(PORT_USB_C, PROTOCOL_HID);
keymapping();
mousemapping();
}
main {
mouse_passthru();
if (mouse_status(MREPORT_UPDATED)) {
mx = mouse_get(MOUSE_X);
my = mouse_get(MOUSE_Y);
if (mx) {
printf("x: %d",mx);
mouse_set(MOUSE_X,mx*10);
}
if (my) {
printf("y: %d",my);
mouse_set(MOUSE_Y,my*10);
}
}
}
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: Mouse scripting
Scachi wrote:If I remember correctly mouse_get will keep reporting the last value when there is currently no input.
You can try to check "mouse_status(MREPORT_UPDATED)" to test if there is some new mouse input and apply your mouse_set movement seperate by axis only if this check returns TRUE and MOUSE_X or MOUSE_Y is != 0
Try something like this:
- Code: Select all
if (mouse_status(MREPORT_UPDATED)) {
mx = mouse_get(MOUSE_X);
my = mouse_get(MOUSE_Y);
if (mx) printf("x: %d",mx); // movement mod x here
if (my) printf("y: %d",my); // movement mod y here
}
Full example:
- Code: Select all
#include <mouse.gph>
int32 mx, my;
init {
port_connect(PORT_USB_C, PROTOCOL_HID);
keymapping();
mousemapping();
}
main {
mouse_passthru();
if (mouse_status(MREPORT_UPDATED)) {
mx = mouse_get(MOUSE_X);
my = mouse_get(MOUSE_Y);
if (mx) {
printf("x: %d",mx);
mouse_set(MOUSE_X,mx*10);
}
if (my) {
printf("y: %d",my);
mouse_set(MOUSE_Y,my*10);
}
}
}
- Code: Select all
#include <mouse.gph>
int32 mx, my;
#define HIP_SENS 1.00
#define ADS_BOOST_SENS 1.00
#define ADS_BOOST_SENS1 1.00
#define ADS_BOOST_DELAY 200
uint8 ads_delay_timer;
init {
port_connect(PORT_USB_C, PROTOCOL_HID);
keymapping();
mousemapping();
}
main {
mouse_passthru();
key_passthru();
if (mouse_status(MREPORT_UPDATED)) {
mx = mouse_get(MOUSE_X); mouse_set(MOUSE_X, (int32)clamp((fix32)mouse_get(MOUSE_X) * (HIP_SENS + (ADS_BOOST_SENS - HIP_SENS) * ((fix32)ads_delay_timer / (fix32)ADS_BOOST_DELAY)), -100.0, 100.0));
my = mouse_get(MOUSE_Y);mouse_set(MOUSE_Y, (int32)clamp((fix32)mouse_get(MOUSE_Y) * (HIP_SENS + (ADS_BOOST_SENS1 - HIP_SENS) * ((fix32)ads_delay_timer / (fix32)ADS_BOOST_DELAY)), -100.0, 100.0));
if (mx) {
printf("x: %d",mx);
mouse_set(MOUSE_X,mx*1);
}
if (my) {
printf("y: %d",my);
mouse_set(MOUSE_Y,my*1);
}
}
}
Is this how you meant?
I changed the
- Code: Select all
mx*10 // in your example to
mx*1 // because my aim was stuttering otherwise
but it doesn't alter the X axis at all unless im missing something
-
GamingScene - Sergeant Major
- Posts: 104
- Joined: Sat May 26, 2018 6:17 pm
Re: Mouse scripting
You do not modify mx or my at all.you set mx to current mouse_get values and in the same line set MOUSE_X/_Y to modified value and overwriting it again with unmodifed mx & my (*1 isn't doing any changes to the value). You have two seperate statements in this line (for y as well):
only use mouse_set in the "if (mx)" and "if (my)" sections.
Your current math doesn't do any modification when your ads_delay_timer is 0. This code isn't setting this variable at the moment.
Here is my code integrated into yours. I have added a deazone setting to not modify small mouse movement with your ads mod values:
- Code: Select all
mx = mouse_get(MOUSE_X); mouse_set(MOUSE_X,.....
only use mouse_set in the "if (mx)" and "if (my)" sections.
Your current math doesn't do any modification when your ads_delay_timer is 0. This code isn't setting this variable at the moment.
Here is my code integrated into yours. I have added a deazone setting to not modify small mouse movement with your ads mod values:
- Code: Select all
#pragma METAINFO("PC BATTALION 1944 Script", 1, 0, "GamingScene")
#include <keyboard.gph>
#include <mouse.gph>
// SCRIPT START
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
// INIT START
// ADS BOOST START
#define HIP_SENS 1.00
#define ADS_BOOST_SENS 1.00
#define ADS_BOOST_SENS1 2.15
#define ADS_BOOST_DELAY 200
#define DEADZONE_X 1
#define DEADZONE_Y 1
uint8 ads_delay_timer;
// ADS BOOST END
init {
port_connect(PORT_USB_C, PROTOCOL_HID);keymapping();mousemapping();}
// INIT END
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
// MAIN START
main {
// HID PASSTHROUGH START
key_passthru();
mouse_passthru();
// HID PASSTHROUGH END
// RAPID FIRE START
if(mouse_status(MBUTTON_1)) {combo_run(RAPID_FIRE);}
// RAPID FIRE END
// ADS BOOST START
if(mouse_status(MBUTTON_2)) {
if(ads_delay_timer < ADS_BOOST_DELAY) ads_delay_timer += elapsed_time();
if (mouse_status(MREPORT_UPDATED)) {
if (abs(mouse_get(MOUSE_X)) > DEADZONE_X) {
printf("xorg: %d, xnew: %d",mouse_get(MOUSE_X),(int32)clamp((fix32)mouse_get(MOUSE_X) * (HIP_SENS + (ADS_BOOST_SENS - HIP_SENS) * ((fix32)ads_delay_timer / (fix32)ADS_BOOST_DELAY)), -100.0, 100.0));
mouse_set(MOUSE_X, (int32)clamp((fix32)mouse_get(MOUSE_X) * (HIP_SENS + (ADS_BOOST_SENS - HIP_SENS) * ((fix32)ads_delay_timer / (fix32)ADS_BOOST_DELAY)), -100.0, 100.0));
}
if (abs(mouse_get(MOUSE_Y)) > DEADZONE_Y) {
printf("yorg: %d, ynew: %d",mouse_get(MOUSE_Y),(int32)clamp((fix32)mouse_get(MOUSE_Y) * (HIP_SENS + (ADS_BOOST_SENS1 - HIP_SENS) * ((fix32)ads_delay_timer / (fix32)ADS_BOOST_DELAY)), -100.0, 100.0));
mouse_set(MOUSE_Y, (int32)clamp((fix32)mouse_get(MOUSE_Y) * (HIP_SENS + (ADS_BOOST_SENS1 - HIP_SENS) * ((fix32)ads_delay_timer / (fix32)ADS_BOOST_DELAY)), -100.0, 100.0));
}
}
} else ads_delay_timer = 0;}
// ADS BOOST END
// MAIN END
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
// COMBO START
// RAPID PICKUP COMBO START
combo RAPID_FIRE {
mouse_set(MBUTTON_1, 100);
wait(irand(92));
mouse_set(MBUTTON_1, 0);
wait(irand(52));
mouse_set(MBUTTON_1, 0);}
// RAPID PICKUP COMBO END
// COMBO END
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
// SCRIPT FUNCTIONS START
int irand(int scramble) {fix32 fraction = (fix32) scramble * 0.15;int vmin = scramble - (int) fraction;int vmax = scramble + (int) fraction;return(((int)(rand() * (fix32)(vmax + 1 - vmin))) + vmin);}
// SCRIPT FUNCTIONS END
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
// SCRIPT END
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: Mouse scripting
Scachi wrote:You do not modify mx or my at all.you set mx to current mouse_get values and in the same line set MOUSE_X/_Y to modified value and overwriting it again with unmodifed mx & my (*1 isn't doing any changes to the value). You have two seperate statements in this line (for y as well):
- Code: Select all
mx = mouse_get(MOUSE_X); mouse_set(MOUSE_X,.....
only use mouse_set in the "if (mx)" and "if (my)" sections.
Your current math doesn't do any modification when your ads_delay_timer is 0. This code isn't setting this variable at the moment.
Here is my code integrated into yours. I have added a deazone setting to not modify small mouse movement with your ads mod values:
- Code: Select all
#pragma METAINFO("PC BATTALION 1944 Script", 1, 0, "GamingScene")
#include <keyboard.gph>
#include <mouse.gph>
// SCRIPT START
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
// INIT START
// ADS BOOST START
#define HIP_SENS 1.00
#define ADS_BOOST_SENS 1.00
#define ADS_BOOST_SENS1 2.15
#define ADS_BOOST_DELAY 200
#define DEADZONE_X 1
#define DEADZONE_Y 1
uint8 ads_delay_timer;
// ADS BOOST END
init {
port_connect(PORT_USB_C, PROTOCOL_HID);keymapping();mousemapping();}
// INIT END
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
// MAIN START
main {
// HID PASSTHROUGH START
key_passthru();
mouse_passthru();
// HID PASSTHROUGH END
// RAPID FIRE START
if(mouse_status(MBUTTON_1)) {combo_run(RAPID_FIRE);}
// RAPID FIRE END
// ADS BOOST START
if(mouse_status(MBUTTON_2)) {
if(ads_delay_timer < ADS_BOOST_DELAY) ads_delay_timer += elapsed_time();
if (mouse_status(MREPORT_UPDATED)) {
if (abs(mouse_get(MOUSE_X)) > DEADZONE_X) {
printf("xorg: %d, xnew: %d",mouse_get(MOUSE_X),(int32)clamp((fix32)mouse_get(MOUSE_X) * (HIP_SENS + (ADS_BOOST_SENS - HIP_SENS) * ((fix32)ads_delay_timer / (fix32)ADS_BOOST_DELAY)), -100.0, 100.0));
mouse_set(MOUSE_X, (int32)clamp((fix32)mouse_get(MOUSE_X) * (HIP_SENS + (ADS_BOOST_SENS - HIP_SENS) * ((fix32)ads_delay_timer / (fix32)ADS_BOOST_DELAY)), -100.0, 100.0));
}
if (abs(mouse_get(MOUSE_Y)) > DEADZONE_Y) {
printf("yorg: %d, ynew: %d",mouse_get(MOUSE_Y),(int32)clamp((fix32)mouse_get(MOUSE_Y) * (HIP_SENS + (ADS_BOOST_SENS1 - HIP_SENS) * ((fix32)ads_delay_timer / (fix32)ADS_BOOST_DELAY)), -100.0, 100.0));
mouse_set(MOUSE_Y, (int32)clamp((fix32)mouse_get(MOUSE_Y) * (HIP_SENS + (ADS_BOOST_SENS1 - HIP_SENS) * ((fix32)ads_delay_timer / (fix32)ADS_BOOST_DELAY)), -100.0, 100.0));
}
}
} else ads_delay_timer = 0;}
// ADS BOOST END
// MAIN END
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
// COMBO START
// RAPID PICKUP COMBO START
combo RAPID_FIRE {
mouse_set(MBUTTON_1, 100);
wait(irand(92));
mouse_set(MBUTTON_1, 0);
wait(irand(52));
mouse_set(MBUTTON_1, 0);}
// RAPID PICKUP COMBO END
// COMBO END
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
// SCRIPT FUNCTIONS START
int irand(int scramble) {fix32 fraction = (fix32) scramble * 0.15;int vmin = scramble - (int) fraction;int vmax = scramble + (int) fraction;return(((int)(rand() * (fix32)(vmax + 1 - vmin))) + vmin);}
// SCRIPT FUNCTIONS END
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
// SCRIPT END
Thanks im currently out now I will try this when I get back to see if it works. Thanks for your help so far
edit :
This is working great is it possible to do a mouse anti recoil?
-
GamingScene - Sergeant Major
- Posts: 104
- Joined: Sat May 26, 2018 6:17 pm
Re: Mouse scripting
I think so.
You can take a look at the "Online Resource" -> "Antirecoil_USB_HID".
It is using two seperate combos to get a low y antirecoil value working as I couldn't get a low anti recoil to work reliable evenly without using combos.
This one is a bit old .. I have almost no experience in using the T2 for USB HID / PC gaming. It works but is feels like kind of a hack because of using combos and can get laggy when using a high value too high for the wait time.
Someone more experienced with T2 & USB HID pc usage should be able to code a better one.
You can take a look at the "Online Resource" -> "Antirecoil_USB_HID".
It is using two seperate combos to get a low y antirecoil value working as I couldn't get a low anti recoil to work reliable evenly without using combos.
This one is a bit old .. I have almost no experience in using the T2 for USB HID / PC gaming. It works but is feels like kind of a hack because of using combos and can get laggy when using a high value too high for the wait time.
Someone more experienced with T2 & USB HID pc usage should be able to code a better one.
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: Mouse scripting
Kk if contacted Pablo but he hasn't gotten back to me yet
-
GamingScene - Sergeant Major
- Posts: 104
- Joined: Sat May 26, 2018 6:17 pm
9 posts
• Page 1 of 1
Return to GPC2 Script Programming
Who is online
Users browsing this forum: No registered users and 45 guests