public void PlayerConnected(int Id) { Log($"New player {Id} connected"); if (Id == ServerId) { RpcId(ServerId, nameof(RegisterNickname), Nickname); } if (Multiplayer.IsNetworkServer()) { foreach (int AlivePlayer in Alive) { if (AlivePlayer == Id) { continue; } var Plr = (ThirdPersonPlayer)RuntimeRoot.GetNode(AlivePlayer.ToString()); string Nickname = Nicknames[AlivePlayer]; RpcId(Id, nameof(NetSpawn), AlivePlayer, Nickname, Plr.GlobalTransform.origin, Plr.Rotation); Plr.RpcId(Id, nameof(ThirdPersonPlayer.NetSetSpectateWeapon), Plr.Holder.CurrentWeapon.Kind); } } }
public override void _Process(float Delta) { if (Multiplayer.IsNetworkServer()) { CurrentDripTime -= Delta; if (CurrentDripTime <= 0) { CurrentDripTime = (float)(Game.Rng.NextDouble() * (MaxDripTime - MinDripTime) + MinDripTime); Sfx.PlaySfxSpatially(SfxCatagory.DRIP, DripChooser.Choose(), GlobalTransform.origin, 0); } } base._Process(Delta); }
public void PlayerDisconnected(int Id) { if (Multiplayer.IsNetworkServer() && Nicknames.GetOrNull(Id) is String Identifier) { Log($"Registered player {Identifier} disconnected"); } else { Log($"Unregistered player {Id} disconnected"); } Alive.Remove(Id); Nicknames.Remove(Id); Node ThirdPerson = RuntimeRoot.GetNodeOrNull(Id.ToString()); if (ThirdPerson != null) { ThirdPerson.QueueFree(); } }
public void NetDie(int Killer) { Game.Alive.Remove(Id); if (Game.Self.Spectating == this) { if (Game.Alive.Count > 0) { Game.SpectateNextPlayer(); } else { Game.Self.Spectating = null; } } if (Multiplayer.IsNetworkServer()) { string Message = ""; if (Killer == -1) { Message = $"{Game.Nicknames[Id]} fell to their death"; } else if (Killer == Game.ServerId) { Message = $"{Game.Nicknames[Id]} was killed by the server"; } else { Message = $"{Game.Nicknames[Killer]} ended the life of {Game.Nicknames[Id]}"; } Game.Self.Rpc(nameof(Game.NetNotifyKillfeed), Message); } QueueFree(); }