GPC Learning

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

GPC Learning

Postby badrisuper » Tue Aug 22, 2017 8:07 am

Hi

I started learning to code GPC scripts thought it may help understand the device and usage much better. I like to get clarified below questions?

1. 'main' method will be running in loop?
2. Do we have a command to stop all running combo's?

Tried a small example.
Code: Select all
 
#pragma METAINFO("<badmn>", 1, 0, "")
#include <ps4.gph>
 
bool sprint = FALSE;
 
init {
    pmem_load();
    sprint = pmem_read(0);
}
 
main {
     if (event_active(STICK_2_Y) && get_val(STICK_2_Y)!=1.0) {
        sprint = TRUE;
        } else {
        sprint = FALSE;
        //need command to stop all combo
        combo_stop(AutoRun);
        }
    if(sprint) {
        combo_run(AutoRun);
        }
}
 
combo AutoRun{
    set_val(BUTTON_9, 100);
    wait(40);
    wait(40);
}
 


In the above example, do I need to set BUTTON-9 to 0 after event triggered?

Thanks
Badri M
User avatar
badrisuper
Sergeant First Class
Sergeant First Class
 
Posts: 16
Joined: Fri Aug 04, 2017 3:18 am

Re: GPC Learning

Postby Prototype » Sat Aug 26, 2017 3:14 pm

1.Yes
2.There is no command to stop all combos, you must stop each ones.
Console tuner since my 1st controller.
Scripting, a game in the game.
Believe or dare, It's Titanic! :smile0517:
User avatar
Prototype
Major General
Major General
 
Posts: 3252
Joined: Sun Dec 16, 2012 1:43 pm

Re: GPC Learning

Postby antithesis » Sat Aug 26, 2017 11:42 pm

There's rarely a need to stop a combo unless attempting to override it, for example, overriding a rapid-fire combo by holding a button.

In most use cases, if the button hold or press condition is no longer true for that combo, the combo will stop by itself. In other words, this isn't needed -

Code: Select all
 
else {
        sprint = FALSE;
        //need command to stop all combo
        combo_stop(AutoRun);
        }
 
Official Australian retailer for Titan One, Titan Two and XIM APEX at Mod Squad
User avatar
antithesis
Colonel
Colonel
 
Posts: 1912
Joined: Sat May 28, 2016 10:45 pm

Re: GPC Learning

Postby badrisuper » Mon Aug 28, 2017 9:11 am

Thanks prototype, antithesis. Need one more clarification.

I want to start an action on press of a button. But action has to be continued until another button press registered. Is this possible?

For example, I want to press 'w' button to move forward instead of holding it and stop it by pressing 's' button.
Here referring 'w' to keyboard mapped to move forward in stick and 's' to move backward.

Something similar like below will work?
Code: Select all
 
#pragma METAINFO("Badri M", 1, 0, "")
#include <ps4.gph>
 
bool moveForward;
bool moveBackward;
bool straffLeft;
bool straffRight;
 
main {   
    if(get_actual(STICK_2_X)>20.0 && get_prev(STICK_2_X)>20.0) {
        set_val(STICK_2_X, 0.0);
        set_val(STICK_2_Y, 0.0);
        moveBackward = FALSE;
        moveForward = FALSE;
        straffLeft = FALSE;
        straffRight = FALSE;
    }
 
    if(event_active(STICK_2_X) || moveForward || moveBackward) {
        if(event_active(STICK_2_X)) {
            if(get_actual(STICK_2_X)<-20.0) {
                /*moveForward = TRUE;
                moveBackward = FALSE;
                straffLeft = FALSE;
                straffRight = FALSE;*/

                setMoveForward();
            } else if(get_actual(STICK_2_X)>20.0) {
                /*moveForward = FALSE;
                moveBackward = TRUE;
                straffLeft = FALSE;
                straffRight = FALSE;*/

                setMoveBackward();
            }
        }
        if(moveForward) {
            /*moveBackward = FALSE;
            straffLeft = FALSE;
            straffRight = FALSE;*/

            setMoveForward();
            combo_run(moveUp);
        }
        if(moveBackward) {
            /*moveForward = FALSE;
            straffLeft = FALSE;
            straffRight = FALSE;*/

            setMoveBackward();
            combo_run(moveDown);
        }
    }
 
    if(event_active(STICK_2_Y) || straffLeft || straffRight) {
        if(event_active(STICK_2_Y)) {
            if(get_actual(STICK_2_Y)<-20.0) {
                /*straffRight = TRUE;
                straffLeft = FALSE;
                moveForward = FALSE;
                moveBackward = FALSE;*/

                setMoveRight();
            } else if(get_actual(STICK_2_Y)>20.0) {
                /*straffRight = FALSE;
                straffLeft = TRUE;
                moveForward = FALSE;
                moveBackward = FALSE;*/

                setMoveLeft();
            }
        }
        if(straffRight) {
            /*straffLeft = FALSE;
            moveForward = FALSE;
            moveBackward = FALSE;*/

            setMoveRight();
            combo_run(moveRight);
        }
        if(straffLeft) {
            /*straffRight = FALSE;
            moveForward = FALSE;
            moveBackward = FALSE;*/

            setMoveLeft();
            combo_run(moveLeft);
        }
    }
 
}
 
combo moveUp {
    set_val(STICK_2_X, -100.0);
}
 
combo moveDown {
    set_val(STICK_2_X, 100.0);
}
 
combo moveRight {
    set_val(STICK_2_Y, -100.0);
}
 
combo moveLeft {
    set_val(STICK_2_X, 100.0);
}
 
/*combo halt {
    set_val(STICK_2_X, 0.0);
}*/

 
void setMoveForward() {
    moveForward = TRUE;
    moveBackward = FALSE;
    straffLeft = FALSE;
    straffRight = FALSE;
}
 
void setMoveBackward() {
    moveForward = FALSE;
    moveBackward = TRUE;
    straffLeft = FALSE;
    straffRight = FALSE;
}
 
void setMoveRight() {
    straffRight = TRUE;
    straffLeft = FALSE;
    moveForward = FALSE;
    moveBackward = FALSE;
}
 
void setMoveLeft() {
    straffRight = FALSE;
    straffLeft = TRUE;
    moveForward = FALSE;
    moveBackward = FALSE;
}
 
 
 


Thanks
Badri M
User avatar
badrisuper
Sergeant First Class
Sergeant First Class
 
Posts: 16
Joined: Fri Aug 04, 2017 3:18 am

Re: GPC Learning

Postby sky418 » Mon Aug 28, 2017 11:45 am

I'm not shure it will work, can't test it, written in notepad
If don't work, i know what to do for make it working
Code: Select all
 #include "keyboard.gph"
int8 check_keycode_W;                                                             // W MAPED keys
int8 check_keycode_S;                                                             // S MAPED keys
uint8 keycode;                                                                    // Keys keycode check
int more_forward;
int more_backward;
init {
    check_keycode_W == 0;
    check_keycode_S == 0;
    const uint8 map[] = {
    KEY_W,             STICK_2_Y | KEYMAP_NEGATIVE,
    KEY_S,             STICK_2_Y,
    KEY_A,             STICK_2_X | KEYMAP_NEGATIVE,
    KEY_D,             STICK_2_X,
    };
    keymapping(map);
}
//=======================================================================================================================
main {
        if (check_keycode_W == 0  && more_forward == 0){
    if(key_status(KEY_W)){
    keycode = key_get();
    if(keycode) {
    check_keycode_W = 1;
    more_forward = 1;
    more_backward = 0;
            printf("more_forward: %d ", more_forward);                                                    // More fast  debug
            printf("more_backward: %d ", more_backward);                                                  // More fast debug
        }
    }
}
    else if(!key_status(KEY_W) && check_keycode_W == 1) {
            check_keycode_W = 0;                                                                          // Return check
    }
 
    if (check_keycode_S == 0 &&  more_backward == 0){
    if(key_status(KEY_S)){
    keycode = key_get();
    if(keycode) {
    check_keycode_S = 1;
    more_forward = 0;
    more_backward = 1;
            printf("more_forward: %d ", more_forward);                                                    // More fast  debug
            printf("more_backward: %d ", more_backward);                                                  // More fast debug
        }
    }
}
    else if(!key_status(KEY_S) && check_keycode_S == 1) {
            check_keycode_S = 0;                                                                          // Return check
    }
 
    if (more_forward == 1 || more_backward == 1) {
         move (STICK_2_Y, 100.0);
    }
    if(key_status(KEY_A) || key_status(KEY_D)) {
    more_forward = 0;
    more_backward = 0;
    }
}
//=======================================================================================================================
void move (uint8 move_l, fix32 val){
    if (more_forward == 1){
         set_val(move_l, val);
        }
    if (more_backward == 1){
         set_val(move_l, -val);
        }
    return;
}
Last edited by sky418 on Mon Aug 28, 2017 3:33 pm, edited 2 times in total.
User avatar
sky418
Command Sergeant Major
Command Sergeant Major
 
Posts: 124
Joined: Fri Nov 25, 2016 4:28 am

Re: GPC Learning

Postby badrisuper » Mon Aug 28, 2017 3:13 pm

Thanks sky418.

If I am not wrong above code inherits T2's keyboard translator.

My setup is xim4->T2->ps4. I want to simply loop the movement on single button press and stop the movement by pressing deactivation key.

Thanks
Badri M
User avatar
badrisuper
Sergeant First Class
Sergeant First Class
 
Posts: 16
Joined: Fri Aug 04, 2017 3:18 am

Re: GPC Learning

Postby sky418 » Mon Aug 28, 2017 3:59 pm

It can be done when you, in alternative settings, in XIM4 add one real keyboard button to two or three different DS4 buttons, and then in T2 script make rules for pressing this button to do something.
User avatar
sky418
Command Sergeant Major
Command Sergeant Major
 
Posts: 124
Joined: Fri Nov 25, 2016 4:28 am


Return to GPC2 Script Programming

Who is online

Users browsing this forum: midg3t2 and 211 guests