DK22Pac / plugin-sdk

An SDK for developing ASI/CLEO plugins for GTA San Andreas, GTA Vice City and GTA III
zlib License
427 stars 116 forks source link

Is it possible to remove events? #109

Closed crwn1337 closed 3 years ago

crwn1337 commented 3 years ago

For example:

plugin::Events::gameProcessEvent += [] {
    Command<Commands::PRINT_NOW>("IN_VEH", 150, 0);
};

and then somewhere later remove the event?

Megasware128 commented 3 years ago

Not really sure about C++ but in .NET you would -= to remove an event. You could try putting the lamda in a variable then use += and -=. Purely a theoretical suggestion, haven't tried in practice.

crwn1337 commented 3 years ago

It does work!

For future reference:

void process() {
    if (plugin::Command<plugin::Commands::IS_PLAYER_PLAYING>(0)) {
        plugin::Command<plugin::Commands::PRINT_NOW>("IN_VEH", 150, 0);
    }
}

plugin::Events::processScriptsEvent += process; // add it
plugin::Events::processScriptsEvent -= process; // remove it
Megasware128 commented 3 years ago

Ah yes, I was overthinking it needing to put a lambda in a variable. Making a function as a much simpler solution 😅