-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cs
84 lines (60 loc) · 2.28 KB
/
Main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using System.Timers;
using SpaceEngineers.Game.ModAPI;
using Sandbox.ModAPI;
using Sandbox.Game;
using Sandbox.Game.Entities;
using Sandbox.Game.Entities.Cube;
using VRage.Game;
using VRage.Game.Entity;
using VRage.Game.ModAPI;
using VRage.Game.Components;
using VRage.Utils;
using VRageMath;
[MySessionComponentDescriptor(MyUpdateOrder.NoUpdate)]
public class Main : MySessionComponentBase {
private Logger logger;
public override void Init(MyObjectBuilder_SessionComponent sessionComponent) {
base.Init(sessionComponent);
logger = Logger.getLogger("AlwaysSpawnWithoutHydrogen");
/* Add Listener */
MyVisualScriptLogicProvider.PlayerSpawned += PlayerSpawned;
logger.WriteLine("Initialized");
}
protected override void UnloadData() {
base.UnloadData();
MyVisualScriptLogicProvider.PlayerSpawned -= PlayerSpawned;
if (logger != null) {
logger.WriteLine("Unloaded");
logger.Close();
}
}
private void PlayerSpawned(long playerId) {
//logger.WriteLine("Request of Player "+ playerId);
IMyIdentity playerIdentity = Player(playerId);
//logger.WriteLine("Found Identity " + playerId);
if (playerIdentity != null) {
//logger.WriteLine("Player is " + playerIdentity.DisplayName);
var playerList = new List<IMyPlayer>();
MyAPIGateway.Players.GetPlayers(playerList, p => p != null && p.IdentityId == playerIdentity.IdentityId);
var player = playerList.FirstOrDefault();
if (player != null)
MyVisualScriptLogicProvider.SetPlayersHydrogenLevel(playerIdentity.IdentityId, 0);
}
}
private IMyIdentity Player(long entityId) {
try {
List<IMyIdentity> listIdentities = new List<IMyIdentity>();
MyAPIGateway.Players.GetAllIdentites(listIdentities,
p => p != null && p.DisplayName != "" && p.IdentityId == entityId);
if (listIdentities.Count == 1)
return listIdentities[0];
return null;
} catch (Exception e) {
logger.WriteLine("Error on getting Player Identity " + e);
return null;
}
}
}