Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
pluginuniversaltemperaturesourceserver.c
Go to the documentation of this file.
1 class PluginUniversalTemperatureSourceServer extends PluginBase
2 {
3  const int INTERVAL = 1;
4  const float LOOKUP_RADIUS = 20;
5 
6  protected float m_AccuTime;
7  protected ref set<PlayerBase> m_ClientList;
8 
9  protected ref array<ref UTemperatureSourceDebug> m_UTemperatureSourceDebugs;
10 
11  void PluginUniversalTemperatureSourceServer()
12  {
13  m_ClientList = new set<PlayerBase>();
14  m_UTemperatureSourceDebugs = new array<ref UTemperatureSourceDebug>();
15  }
16 
17  override void OnUpdate(float delta_time)
18  {
19  if (m_ClientList.Count() > 0)
20  {
21  m_AccuTime += delta_time;
22 
23  if (m_AccuTime > INTERVAL)
24  {
25  m_AccuTime = 0;
26  SendDebug();
27  }
28  }
29  }
30 
31  void GatherTemperatureSources(PlayerBase player)
32  {
33  m_UTemperatureSourceDebugs.Clear();
34 
35  if (!player)
36  return;
37 
38  vector playerPos = player.GetPosition();
39  array<Object> nearestObjects = new array<Object>();
40 
41  GetGame().GetObjectsAtPosition(playerPos, LOOKUP_RADIUS, nearestObjects, null);
42 
43  UTemperatureSource uts;
44  UTemperatureSourceDebug utsd;
45 
46  foreach (Object nearestObject : nearestObjects)
47  {
48  EntityAI ent = EntityAI.Cast(nearestObject);
49  if (ent && ent.IsUniversalTemperatureSource() && ent != player)
50  {
51  uts = ent.GetUniversalTemperatureSource();
52  utsd = new UTemperatureSourceDebug();
53  utsd.AddHeader(ent.GetType());
54  utsd.Add("position", uts.GetPosition().ToString(false));
55  utsd.Add("fullrange", uts.GetFullRange().ToString());
56  utsd.Add("maxrange", uts.GetMaxRange().ToString());
57  utsd.Add("temperature", uts.GetTemperature().ToString());
58  utsd.Add("temperatureraw", uts.GetTemperatureRaw().ToString());
59  utsd.Commit();
60 
61  m_UTemperatureSourceDebugs.Insert(utsd);
62  }
63  }
64 
65  if (player.GetItemInHands() && player.GetItemInHands().IsUniversalTemperatureSource())
66  {
67  uts = player.GetItemInHands().GetUniversalTemperatureSource();
68  utsd = new UTemperatureSourceDebug();
69  utsd.AddHeader(player.GetItemInHands().GetType());
70  utsd.Add("position", uts.GetPosition().ToString(false));
71  utsd.Add("fullrange", uts.GetFullRange().ToString());
72  utsd.Add("maxrange", uts.GetMaxRange().ToString());
73  utsd.Add("temperature", uts.GetTemperature().ToString());
74  utsd.Add("temperatureraw", uts.GetTemperatureRaw().ToString());
75  utsd.Commit();
76 
77  m_UTemperatureSourceDebugs.Insert(utsd);
78  }
79  }
80 
81  void SendDebug()
82  {
83  int clientCount = m_ClientList.Count();
84  foreach (PlayerBase player : m_ClientList)
85  {
86  if (player)
87  {
88  GatherTemperatureSources(player);
89  ScriptRPC rpc = new ScriptRPC();
90  rpc.Write(m_UTemperatureSourceDebugs);
91  rpc.Send(player, ERPCs.DEV_UTS_DEBUG_DATA, true, player.GetIdentity());
92  }
93  else
94  m_ClientList.RemoveItem(player);
95  }
96  }
97 
98  void OnRequestReceived(PlayerBase player, bool enable)
99  {
100  int index = m_ClientList.Find(player);
101 
102  if (enable)
103  {
104  m_ClientList.Insert(player);
105  }
106  else if (index != -1 && m_ClientList.Count() > 0)
107  {
108  m_ClientList.Remove(index);
109  }
110  }
111 
112  void OnRPC(ParamsReadContext ctx, PlayerBase player)
113  {
114  bool enable;
115  ctx.Read(enable);
116 
117  OnRequestReceived(player, enable);
118  }
119 }
GetGame
proto native CGame GetGame()
PluginBase
Definition: pluginadminlog.c:1
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
OnRPC
void OnRPC(ParamsReadContext ctx)
Definition: displaystatus.c:216
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
OnUpdate
proto native void OnUpdate()
Definition: tools.c:349
ScriptRPC
Definition: gameplay.c:104
Object
Definition: objecttyped.c:1
array< ref UTemperatureSourceDebug >
ERPCs
ERPCs
Definition: erpcs.c:1
EntityAI
Definition: building.c:5