Execute code when a player joins - via ServerActor only?

Discussions about Coding and Scripting

Execute code when a player joins - via ServerActor only?

Postby Dizzy » Sun Jan 06, 2019 5:11 am

What's the most elegant way to execute some code when a new player joins the server, using only a ServerActor and no client-side stuff such as a custom GameInfo class?

The only way I'm aware of was provided to me by OwYeaW (below) but I guess there are other ways, which might not rely on the Tick function?

Code: Select all
var int CurrentID;

function tick(float DeltaTime)
{
    CheckForNewPlayer();
    Super.tick(DeltaTime);
}

function CheckForNewPlayer()
{
    local Pawn P;

    if(Level.Game.CurrentID > CurrentID)
    {
        for(P = Level.PawnList; P != None; P = P.NextPawn)
            if(P.PlayerReplicationInfo.PlayerID == CurrentID)
                break;
        CurrentID++;

        if(PlayerPawn(P) != None && P.bIsPlayer)
        {
            //P.EXECUTE STUFF HERE
        }
    }
}
Image
Join our UT Discord chat server: https://www.bunnytrack.net/discord
User avatar
Dizzy
Experienced
 
Posts: 99
Joined: Tue May 21, 2013 3:57 pm
Personal rank: Oaf

Re: Execute code when a player joins - via ServerActor only?

Postby JackGriffin » Sun Jan 06, 2019 8:06 am

It depends on what you want to do. As long as it all remains server side I'd just use a mutator that monitors the NumPlayers value for changes. If you really wanted to get elegant you could hook ModifyPlayer to let the server know someone just joined/respawned and to check the NumPlayers again for a change. There's a lot of ways to avoid having another timer always running.
"You damn kids, back in my time we made the items, maps and games ourselves with an unwieldy engine using counter-intuitive crash-prone tools and we liked it so much we built communities around this which nowadays look like cults because they're quasi-parallel societies based on the same old games." -Hellkeeper
User avatar
JackGriffin
Godlike
 
Posts: 3751
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: Hack coder

Re: Execute code when a player joins - via ServerActor only?

Postby Barbie » Sun Jan 06, 2019 10:36 am

Polling as seen in your code snippet is in most cases the worst solution. I'd suggest using a Mutator's ModifyLogin() function. Depending on what the code does the client may not need the mutator.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
Barbie
Godlike
 
Posts: 1648
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Execute code when a player joins - via ServerActor only?

Postby Dizzy » Sun Jan 06, 2019 5:44 pm

Barbie wrote:Polling as seen in your code snippet is in most cases the worst solution. I'd suggest using a Mutator's ModifyLogin() function. Depending on what the code does the client may not need the mutator.

I want the code to display a message to the client as soon as they connect/log in.

I suspect this could all be done (detecting logins AND displaying a message) via the functionality Nexgen exposes, but honestly I haven't got a clue how to start hooking in to other packages via my own code, especially trying to keep everything server-side.
Image
Join our UT Discord chat server: https://www.bunnytrack.net/discord
User avatar
Dizzy
Experienced
 
Posts: 99
Joined: Tue May 21, 2013 3:57 pm
Personal rank: Oaf

Re: Execute code when a player joins - via ServerActor only?

Postby Barbie » Sun Jan 06, 2019 10:25 pm

Dizzy wrote:I suspect this could all be done (detecting logins AND displaying a message) via the functionality Nexgen exposes, but honestly I haven't got a clue how to start hooking in to other packages via my own code
I don't know neither, but what I have seen in the code you have to subclass Nexgen's class NexgenPlugin.

Concerning your message box you may inspect the code of NexgenWarn112 what can be found at http://ut-files.com/index.php?dir=Nexgen/ for example.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
Barbie
Godlike
 
Posts: 1648
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Execute code when a player joins - via ServerActor only?

Postby JackGriffin » Sun Jan 06, 2019 10:58 pm

Server logo. By far the easiest way to do what you want.
"You damn kids, back in my time we made the items, maps and games ourselves with an unwieldy engine using counter-intuitive crash-prone tools and we liked it so much we built communities around this which nowadays look like cults because they're quasi-parallel societies based on the same old games." -Hellkeeper
User avatar
JackGriffin
Godlike
 
Posts: 3751
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: Hack coder


Return to Coding, Scripting

Who is online

Users browsing this forum: No registered users and 2 guests