UnrealScript Tips

UScript Tutorials

« Back

Executing code when a player joins the server

Using Tick() and Level.Game.CurrentID (Thanks to OwYeaW)

This method checks for new players on every tick. Level.Game.CurrentID is a counter incremented when a new player joins. It's not decremented when a player leaves, however, so you can use it to check if it has been incremented since the last tick.

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
        }
    }
}