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?
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.
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
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 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.
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.
var int LastPlayerID;
function DetectPlayers() //Done to detect any pawn holding a PlayerReplicationInfo
{
local Pawn P;
if ( Level.Game.CurrentID > LastPlayerID ) //Quick reject, no cost.
{
for ( P=Level.PawnList; P!=None; P=P.nextPawn )
if ( P.PlayerReplicationInfo != None )
{
if ( P.PlayerReplicationInfo.PlayerID <= LastPlayerID )
break;
else
{
//INITIALIZE THIS PLAYER
}
}
LastPlayerID = Level.Game.CurrentID;
}
}