need help to add randomisation to the script

GPC2 script programming for Titan Two. Code examples, questions, requests.

need help to add randomisation to the script

Postby Ne0 » Fri May 05, 2023 9:28 pm

I have this small script to afk weapon xp in mw2, do I have to update it with randomisation? if yes, please help .thanks in advance
Code: Select all
#pragma METAINFO("CODWARM", 1, 0, "Kot")
/*<cfgdesc>[]</cfgdesc>*/
#include <xb1.gph>
bool toggle;
main {
    if(event_active(XB1_RIGHT)) toggle = !toggle;
    if(toggle) combo_run(afk);
    else combo_stop(afk);
}
combo afk {
    set_val(BUTTON_16, 100); //space bar
    wait(1000);
    set_val(STICK_2_Y,100); //back
    wait(3000);
    set_val(STICK_2_Y,-100); //forward
    wait(3000);
    set_val(STICK_2_X,100); //right
    wait(1000);
    set_val(STICK_2_X,-100); //left
    wait(1000);
    set_val(BUTTON_7, 100); //grenade
    set_val(BUTTON_4, 100); //grenade 2
    wait(1000);
    set_val(BUTTON_5, 100); //fire
    wait(1000);
    set_val(BUTTON_7, 100); //grenade
    wait(1000);
   set_val(BUTTON_5, 100); //fire
    wait(1000);
    set_val(BUTTON_4, 100); //lethal
    wait(1000);
    set_val(BUTTON_5, 100); //fire
    wait(1000);
    set_val(BUTTON_7, 100); //grenade
    wait(1000);
 
}
User avatar
Ne0
First Sergeant
First Sergeant
 
Posts: 42
Joined: Tue Nov 14, 2017 7:15 am

Re: need help to add randomisation to the script

Postby turmoil_manpower » Mon May 08, 2023 3:12 am

Code: Select all
#pragma METAINFO("CODWARM", 1, 0, "Kot")
/*<cfgdesc>[]</cfgdesc>*/
#include <display.gph>
#define irand(a, b) (((int)(rand() * (fix32)(b+1 - a))) + a)
 
bool b_AFK;
 
main {
    if(event_active(BUTTON_13)) b_AFK = !b_AFK;
    if(b_AFK) combo_run(c_AFK);
    else combo_stop(c_AFK);
}
 
combo c_AFK {
    set_val(BUTTON_16, 100); //space bar
    wait(irand(1000, 1004));
    set_val(STICK_2_Y,100); //back
    wait(irand(3000, 3004));
    set_val(STICK_2_Y,-100); //forward
    wait(irand(3000, 3004));
    set_val(STICK_2_X,100); //right
    wait(irand(1000, 1004));
    set_val(STICK_2_X,-100); //left
    wait(irand(1000, 1004));
    set_val(BUTTON_7, 100); //grenade
    set_val(BUTTON_4, 100); //grenade 2
    wait(irand(1000, 1004));
    set_val(BUTTON_5, 100); //fire
    wait(irand(1000, 1004));
    set_val(BUTTON_7, 100); //grenade
    wait(irand(1000, 1004));
    set_val(BUTTON_5, 100); //fire
    wait(irand(1000, 1004));
    set_val(BUTTON_4, 100); //lethal
    wait(irand(1000, 1004));
    set_val(BUTTON_5, 100); //fire
    wait(irand(1000, 1004));
    set_val(BUTTON_7, 100); //grenade
    wait(irand(1000, 1004));
}
User avatar
turmoil_manpower
Staff Sergeant
Staff Sergeant
 
Posts: 11
Joined: Sat May 06, 2023 7:41 pm

Re: need help to add randomisation to the script

Postby Mad » Mon May 08, 2023 12:41 pm

That randomization wont pass as you're only adding at max an extra 4ms

Being an AFK the repeated button pattern is also detectable.
You could do irand(3, 16) instead of the BUTTON_* which would be a random button from BUTTON_4 to BUTTON_17
Lastly, the sticks and triggers going to 100 each time you could do irand(20, 100)
ConsoleTuner Support Team || ConsoleTuner Discord || InputSense Discord
Mad
Major General
Major General
 
Posts: 4536
Joined: Wed May 22, 2019 5:39 am

Re: need help to add randomisation to the script

Postby turmoil_manpower » Mon May 08, 2023 4:43 pm

Im not fully sure of how much variation would be needed so i just set it to an offset of 4ms, I changed it to be 100ms difference. Is this how you would implement the randomization on button presses or should it be setup to use #define?

edit: I realized its much easier to just do set_val(BUTTON_16, irand(80, 100));

Code: Select all
#pragma METAINFO("CODWARM", 1, 0, "Kot")
/*<cfgdesc>[]</cfgdesc>*/
#include <display.gph>
#define irand(a, b) (((int)(rand() * (fix32)(b+1 - a))) + a)
 
bool b_AFK;
 
int space_val = irand(20, 100); // Generate a random value for BUTTON_16
int back_val = irand(20, 100); // Generate a random value for STICK_2_Y when moving back
int forward_val = irand(-100, -20); // Generate a random value for STICK_2_Y when moving forward
int right_val = irand(-100, -20); // Generate a random value for STICK_2_X when moving right
int left_val = irand(20, 100); // Generate a random value for STICK_2_X when moving left
int grenade_val = irand(20, 100); //Generate a random value for the grenade buttons (BUTTON_7 and BUTTON_4)
int fire_val = irand(20, 100); // Generate a random value for the fire button (BUTTON_5)
int lethal_val = irand(20, 100); // Generate a random value for the lethal button (BUTTON_4)
 
main {
    if(event_active(BUTTON_13)) b_AFK = !b_AFK;
    if(b_AFK) combo_run(c_AFK);
    else combo_stop(c_AFK);
}
 
combo c_AFK {
    set_val(BUTTON_16, space_val); //Press space bar with the generated random value
    wait(irand(1000, 1100)); //Wait for a random duration between 1000 and 1100 milliseconds
    set_val(STICK_2_Y, back_val); //Move backwards with the generated random value
    wait(irand(3000, 3100)); //Wait for a random duration between 3000 and 3100 milliseconds
    set_val(STICK_2_Y, forward_val); //Move forwards with the generated random value
    wait(irand(3000, 3100)); //Wait for a random duration between 3000 and 3100 milliseconds
    set_val(STICK_2_X, right_val); //Move right with the generated random value
    wait(irand(1000, 1100)); //Wait for a random duration between 1000 and 1100 milliseconds
    set_val(STICK_2_X, left_val); //Move left with the generated random value
    wait(irand(1000, 1100)); //Wait for a random duration between 1000 and 1100 milliseconds
    set_val(BUTTON_7, grenade_val); //Press the grenade button with the generated random value
    set_val(BUTTON_4, grenade_val); //Press the second grenade button with the generated random value
    wait(irand(1000, 1100)); //Wait for a random duration between 1000 and 1100 milliseconds
    set_val(BUTTON_5, fire_val); //Fire weapon with the generated random value
    wait(irand(1000, 1100)); //Wait for a random duration between 1000 and 1100 milliseconds
    set_val(BUTTON_7, grenade_val); //Press the grenade button with the generated random value
    wait(irand(1000, 1100)); //Wait for a random duration between 1000 and 1100 milliseconds
    set_val(BUTTON_5, fire_val); //Fire weapon with the generated random value
    wait(irand(1000, 1100)); //Wait for a random duration between 1000 and 1100 milliseconds
    set_val(BUTTON_4, lethal_val); //Press the lethal button with the generated random value
    wait(irand(1000, 1100)); //Wait for a random duration between 1000 and 1100 milliseconds
    set_val(BUTTON_5, fire_val); //Fire weapon with the generated random value
    wait(irand(1000, 1100)); //Wait for a random duration between 1000 and 1100 milliseconds
    set_val(BUTTON_7, grenade_val); //Press the grenade button with the generated random value
    wait(irand(1000, 1100)); //Wait for a random duration between 1000 and 1100 milliseconds
}
User avatar
turmoil_manpower
Staff Sergeant
Staff Sergeant
 
Posts: 11
Joined: Sat May 06, 2023 7:41 pm

Re: need help to add randomisation to the script

Postby alanmcgregor » Tue May 09, 2023 1:28 am

Face buttons can go 0 to 100 because are digital, only triggers, sticks, gyro inputs and delays needs randomization.
User avatar
alanmcgregor
Major
Major
 
Posts: 995
Joined: Tue Mar 27, 2018 8:38 am

Re: need help to add randomisation to the script

Postby Ne0 » Wed May 10, 2023 2:22 pm

Thanks for the answers , so i can use the last code safely ?
User avatar
Ne0
First Sergeant
First Sergeant
 
Posts: 42
Joined: Tue Nov 14, 2017 7:15 am

Re: need help to add randomisation to the script

Postby turmoil_manpower » Wed May 10, 2023 4:11 pm

This should be better as Mad stated you could be detected from a repeated button pattern so I randomized some of the button inputs. I forgot to add it to the previous iteration. All the Delays, Random button inputs, Sticks, and Triggers have had randomization added. So the script should be safe to use.

Code: Select all
#pragma METAINFO("CODWARM", 1, 0, "Kot")
/*<cfgdesc>[]</cfgdesc>*/
 
/*
Credits
Mad
alanmcgregor
*/

 
#define irand(a, b) (((int)(rand() * (fix32)(b+1 - a))) + a)
 
bool b_AFK;
 
main {
    if(event_active(BUTTON_13)) b_AFK = !b_AFK;
    if(b_AFK) combo_run(c_AFK);
    else combo_stop(c_AFK);
}
 
combo c_AFK {
    set_val(BUTTON_16, 100); //Space Bar
    wait(irand(1000, 1100));
    set_val(STICK_2_Y, irand(20, 100)); //Stick Back
    wait(irand(3000, 3100));
    set_val(STICK_2_Y, irand(-100, -20)); //Stick Forward
    wait(irand(3000, 3100));
    set_val(STICK_2_X, irand(20, 100)); //Stick Right
    wait(irand(1000, 1100));
    set_val(STICK_2_X, irand(-100, -20)); //Stick Left
    wait(irand(1000, 1100));
    set_val(irand(3, 16), irand(20, 100)); //Random button from BUTTON_4 to BUTTON_17
    set_val(irand(3, 16), irand(20, 100)); //Random button from BUTTON_4 to BUTTON_17
    wait(irand(1000, 1100));
    set_val(BUTTON_5, irand(20, 100)); //Shoot
    wait(irand(1000, 1100));
    set_val(irand(3, 16), irand(20, 100)); //Random button from BUTTON_4 to BUTTON_17
    wait(irand(1000, 1100));
    set_val(BUTTON_5, irand(20, 100)); //Shoot
    wait(irand(1000, 1100));
    set_val(irand(3, 16), irand(20, 100)); //Random button from BUTTON_4 to BUTTON_17
    wait(irand(1000, 1100));
    set_val(BUTTON_5, irand(20, 100)); //Shoot
    wait(irand(1000, 1100));
    set_val(irand(3, 16), irand(20, 100)); //Random button from BUTTON_4 to BUTTON_17
    wait(irand(1000, 1100));
}
User avatar
turmoil_manpower
Staff Sergeant
Staff Sergeant
 
Posts: 11
Joined: Sat May 06, 2023 7:41 pm

Re: need help to add randomisation to the script

Postby Ne0 » Wed May 10, 2023 11:21 pm

THANKS!
User avatar
Ne0
First Sergeant
First Sergeant
 
Posts: 42
Joined: Tue Nov 14, 2017 7:15 am


Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 101 guests