Custom Plugin Keys and Warning Screen

Discussion in 'Plugins' started by Jeferson Richart, Nov 3, 2020.

  1. Jeferson Richart

    Jeferson Richart Registered

    Joined:
    Oct 23, 2013
    Messages:
    174
    Likes Received:
    34
    In the rFactor2 key assignment screen, we have 12 Custom Plugin key options. Would anyone know how to get the press of these keys in a plugin?

    Custom Plugin #1
    Custom Plugin #2
    Custom Plugin #3
    Custom Plugin #4
    Custom Plugin #5
    Custom Plugin #6
    Custom Plugin #7
    Custom Plugin #8
    Custom Plugin #9
    Custom Plugin #10
    Custom Plugin #11
    Custom Plugin #12

    Thanks
     
  2. Jeferson Richart

    Jeferson Richart Registered

    Joined:
    Oct 23, 2013
    Messages:
    174
    Likes Received:
    34
    Taking advantage of the topic, I have another doubt.
    Is it possible to control this warning screen by plugin, showing the message I want?

    [​IMG]
     
  3. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,382
    Likes Received:
    6,600
    You have to define the custom controls during boot (by populating some fields and returning true for each control, then returning false when done). You should see the relevant function in the header file, and the struct that gets passed in. I can't give specifics until I'm at my PC.

    You then detect it like any of the built in controls, I think a _ gets prepended to your control name, so that's what you test for.


    The caution text is partly customisable, might be in the session rules area, again not sure on details. Can be set per car.
     
  4. Jeferson Richart

    Jeferson Richart Registered

    Joined:
    Oct 23, 2013
    Messages:
    174
    Likes Received:
    34
    Thanks Lazza
    I've already built some plugins for rF2, but my knowledge of C ++ is not that great. I learned the language only for rF2.

    I took a look at the StockCar rules plugin example, but I wasn't able to understand if I can call the caution text at any time.
    I did some tests using TrackRulesV01, but I couldn't call the caution text.
    Let's take an example of what I would like.
    Could I show this caution text in green flag, to warn drivers that the pit window is open or closed?
    Or can this caution text only be shown on a yellow flag?
     
  5. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,382
    Likes Received:
    6,600
    I think it only appears during full course yellows. I can't say I tried to do anything else with it, but that's my understanding of the mechanism.

    Unfortunately the interface is only 80% useful in many aspects ('scoring' of a car is another example).
     
  6. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,382
    Likes Received:
    6,600
    Just to flesh out what I said earlier with a little example code...

    Initialising custom controls:

    Code:
    bool ExampleInternalsPlugin::InitCustomControl( CustomControlInfoV01 &info ) {
        static int count = 0;
        switch (count) {
        case 0:
            info.mRepeat = 0;
            strcpy_s(info.mUntranslatedName, "Telemetry Marker");
            count++;
            return true;
            break;
        case 1:
            info.mRepeat = 0;
            strcpy_s(info.mUntranslatedName, "DAMP Logging");
            count++;
            return true;
            break;
        default:
            return false;
        }
    }
    Detecting those custom controls:

    Code:
    bool ExampleInternalsPlugin::CheckHWControl( const char * const controlName, double &fRetVal ) {
        if (fRetVal == 1) {
            if (_stricmp("_Telemetry Marker", controlName) == 0) {
                SetMarkerInputPressed(true);
            }
            if (_stricmp("_DAMP Logging", controlName) == 0) {
                SetLoggingInputPressed(true);
            }
        }
        return false;
    }
    
    (obviously I'm calling my own routines in those cases)

    (also note I'm no pro programmer, so excuse my code)


    Looking over the InternalsPlugin header again, the TrackRulesV01 gets passed in with AccessTrackRules(), and I'm fairly sure that only happens when there's a caution. That struct has a global message you can customise (char mMessage; think that's the lucky dog message in your screenshot), then inside that struct is an array of mParticipant which itself contains a message for each driver (char mMessage; the "Please pass the safety car" in the screenshot).

    You could certainly test how often AccessTrackRules() gets called, and try changing the value of mYellowFlagState to see if you can force messages to appear, but even if you can fake it without changing any game functionality (keeping the SC in the pits, for example) it'll probably look very much like a full course caution to all the drivers, apart from your custom text. Depends what you're trying to do of course.
     
  7. Jeferson Richart

    Jeferson Richart Registered

    Joined:
    Oct 23, 2013
    Messages:
    174
    Likes Received:
    34
    Thank you again.

    I tried the options that my knowledge allowed me, and I was unable to make this caution text appear, even in a yellow flag.
    I will be hoping that someone who has already succeeded, can provide me with an example code.
    If that were possible, it would be possible to greatly improve communication by plugins. As I said, we can send pit window warnings, or some information from the race director.
    I currently send some plugin information via chat. But this caution text is much more elegant and better to view.
     

Share This Page