Make level change triggers work in multiplayer? Created 1 year ago2022-08-06 18:13:51 UTC by JacksBestGaming JacksBestGaming

Created 1 year ago2022-08-06 18:13:51 UTC by JacksBestGaming JacksBestGaming

Posted 1 year ago2022-08-06 18:13:51 UTC Post #346762
You know when you play singleplayer, and you see LOADING while it loads the next map? In multiplayer, it doesn't do that. Does anybody know how to fix this?
Posted 1 year ago2022-08-06 20:15:19 UTC Post #346763
Coding is required for this to work, this is the only possible way i know.
Posted 1 year ago2022-08-06 20:43:43 UTC Post #346764
I have the code open and ready, but I don't know what to add to it to allow level load triggers to work in multiplayer. Do you know how to write the code I need?
Posted 1 year ago2022-08-07 22:11:22 UTC Post #346766
Sadly not, im also a beginner in coding. You can ask in the TWHL Discord, in #programming-help
Posted 1 year ago2022-08-09 09:05:35 UTC Post #346768
In triggers.cpp there are checks if the game is running in deathmatch mode when doing the level change. I'm not a coder but you can try removing it and see what happens.
Posted 1 year ago2022-08-11 12:03:08 UTC Post #346771
In triggers.cpp, roughly around line 1460, you'll see this:
void CChangeLevel :: ChangeLevelNow( CBaseEntity *pActivator )
{
    edict_t    *pentLandmark;
    LEVELLIST    levels[16];

    ASSERT(!FStrEq(m_szMapName, ""));

    // Don't work in deathmatch
    if ( g_pGameRules->IsDeathmatch() )
        return;

    // Some people are firing these multiple times in a frame, disable
    if ( gpGlobals->time == pev->dmgtime )
        return;

    pev->dmgtime = gpGlobals->time;
Simply removing these will NOT actually do it:
// Don't work in deathmatch
if ( g_pGameRules->IsDeathmatch() )
    return;
Instead, you should modify it like this:
// Yes, work in deathmatch
if ( g_pGameRules->IsDeathmatch() )
{
    CHANGE_LEVEL( m_szMapName, nullptr );
    return;
}
In singleplayer, it changes the level with regards to a landmark, equivalent to calling the changelevel2 console command.
This doesn't work in multiplayer, so for that, we pass nullptr to the landmark parameter, which is the same as using the changelevel console command. This means your player(s) will spawn at info_player_deathmatch points in the next map and won't actually carry over smoothly.

You can't do a smooth singleplayer-style transition in multiplayer, if that's what you're looking for.
Admer456 Admer456If it ain't broken, don't fox it!
Posted 1 year ago2022-08-13 04:03:49 UTC Post #346778
It works (Thank you!), but I just realized none of the weapons you gather carry over to the next level. Is there any way to add that?
Posted 1 year ago2022-08-13 14:51:12 UTC Post #346779
That'd be a bit more complicated. You'd need to keep weapon data on the serverside before the level change, and send it to players when they spawn in the next map. This would involve user messages (read: server-to-client messages) and some bookkeeping.
Admer456 Admer456If it ain't broken, don't fox it!
Posted 1 year ago2022-08-13 18:53:35 UTC Post #346780
Alright! I'll research it a bit. Thanks for your help!
You must be logged in to post a response.