need help with this script

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

need help with this script

Postby alencroat » Fri Dec 16, 2022 8:16 pm

Hello so what I have been trying to create a code that when I press x button on xbox and hold it, would do this: every second that I hold the button down the rapid x will speed up or increase. So base starting from 1 click per second and increasing by 100 millisecond each second I hold the x button. how would that code look like
User avatar
alencroat
Lieutenant
Lieutenant
 
Posts: 320
Joined: Sun Oct 15, 2017 5:58 pm

Re: need help with this script

Postby Scachi » Sat Dec 17, 2022 9:29 pm

Example:
Code: Select all
 
#define rfireDef 1000 // default rapid fire wait time
#define rfireMax 100 // max speed (minimum wait time)
 
uint32 rfireMod; // modification time based on xbox X button hold time / 1000
uint16 rfireSpeed; // the resulting rapid fire wait time
 
main {
    // reset on new press of X
    if (event_active(BUTTON_17)) rfireMod = 0;
    // speed increase while hold every 1 second
    if (elapsed_time() && get_actual(BUTTON_17)) {
        rfireMod = time_active(BUTTON_17) / 1000; // current press time / 1000
        rfireSpeed = rfireDef - (rfireMod * 100); // def speed - mod * 100
        rfireSpeed = clamp(rfireSpeed, rfireMax, rfireDef); // limit to max, def
        if (mod((fix32)time_active(BUTTON_17), 1000f) == 0.0) printf("rfirespeed: %d", rfireSpeed); // print out every 1sec
    }
}
 
 

Example output:
GVM Output: rfirespeed: 1000
GVM Output: rfirespeed: 900
GVM Output: rfirespeed: 800
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: need help with this script

Postby alencroat » Sun Dec 18, 2022 7:16 pm

thank you Scachi :smile0517:
User avatar
alencroat
Lieutenant
Lieutenant
 
Posts: 320
Joined: Sun Oct 15, 2017 5:58 pm


Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 112 guests