Custom Trade controller

  • Server version
    3.10.5
    Game client version
    0.15.5
    Client log file
    codepaste.sp-tarkov.com/?378f6…AhkEoU3h5pe5H6azvB176iDwS
    BepInEx log file
    codepaste.sp-tarkov.com/?378f6…AhkEoU3h5pe5H6azvB176iDwS
    Server log file
    codepaste.sp-tarkov.com/?378f6…AhkEoU3h5pe5H6azvB176iDwS
    Have you read the FAQ?
    Yes
    Where did you download your game from?
    official website i guess
    List of used mods
    Croupier
    Bluehead's AIO trader
    Skulltag's Personal Trainer
    etc

    Some mods (for example, my mod or this one) need such functionality:
    1) The user (player) buys something from a trader
    2) Instead of delivering the item the trader messages the player, or increases player's EXP, or puts a quest item into his quest stash, etc

    To achieve this all such mods have a class extending the spt TradeController, with a method that usually looks like this:

    Code
    confirmTrading(pmcData, body, sessionID) {
        if (body.tid == TRADER_ID) {
            // do stuff we want, return what we want 
        }
    
        // IMPORTANT: if body.tid (trader's id) is not our trader, return standart confirmTrading
        return super.confirmTrading(pmcData, body, sessionID);
    }

    and register it like this:

    Code
    container.register("CustomTradeController", CustomTradeController_1.CustomTradeController);
    container.register("TradeController", { useToken: "CustomTradeController" });

    --

    So essentially it replaces the entire TradeController implementation in the container. So if another mod tries the same thing, only one can win. Whichever mod is loaded last will be the only one that actually overrides TradeController.

    Another option could be intercepting /client/game/profile/items/moving via staticRouterModService.registerStaticRouter, but it's when the trade happened and items were already added/removed - which doesn't work for my case.

    Is there any other option to intercept standart trading, and either run my custom logic or pass it forward, without damaging other mods functionality?

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!