open.mp forum
С++ / How to terminate further function calls? - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: General (https://forum.open.mp/forumdisplay.php?fid=19)
--- Forum: Programming (https://forum.open.mp/forumdisplay.php?fid=56)
--- Thread: С++ / How to terminate further function calls? (/showthread.php?tid=3069)



С++ / How to terminate further function calls? - punkochel - 2025-02-10

Hi everyone! How can I complete a sequence of function calls if I already got the desired result?
Let's say not call onPlayerSpawn in Test2 if I already got what I wanted in Test1? Only if?


Code:
class Test1 : public PlayerSpawnEventHandler
{

public:
    void onPlayerSpawn(IPlayer &player) override
    {
        player.sendClientMessage(Colour::Cyan(), "Hello from the test class...");
    }
};

class Test2 : public PlayerSpawnEventHandler
{

public:
    void onPlayerSpawn(IPlayer &player) override
    {
        player.sendClientMessage(Colour::Cyan(), "Hello from the test2 class...");
    }
};

void Gamemode::onLoad(ICore* c)
{
    core_ = c;
    c->getPlayers().getPlayerConnectDispatcher().addEventHandler(this);
    c->getPlayers().getPlayerSpawnDispatcher().addEventHandler(this);
    c->getPlayers().getPlayerTextDispatcher().addEventHandler(this);

    test1_ = new Test1;
    c->getPlayers().getPlayerSpawnDispatcher().addEventHandler(test1_);

    test2_ = new Test2;
    c->getPlayers().getPlayerSpawnDispatcher().addEventHandler(test2_);
}