DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
AnalyticsManagerServer.c
Go to the documentation of this file.
2{
3 const string STAT_DISTANCE = "dist";
4 const string STAT_PLAYTIME = "playtime";
5 const string STAT_PLAYERS_KILLED = "players_killed";
6 const string STAT_INFECTED_KILLED = "infected_killed";
7 const string STAT_LONGEST_SURVIVOR_HIT = "longest_survivor_hit";
8
9 void OnPlayerConnect( Man player )
10 {
11 player.StatRegister( STAT_DISTANCE );
12 player.StatRegister( STAT_PLAYTIME );
13 player.StatRegister( STAT_PLAYERS_KILLED );
14 player.StatRegister( STAT_INFECTED_KILLED );
15 player.StatRegister( STAT_LONGEST_SURVIVOR_HIT );
16
17 //player.StatSyncToClient();
18 }
19
20 void OnPlayerDisconnect( Man player )
21 {
22 player.StatUpdateByPosition( STAT_DISTANCE );
23 player.StatUpdateByTime( STAT_PLAYTIME );
24
25 /*
26 Print("");
27 Print("-------------");
28 Print( STAT_DISTANCE + " " + player.StatGet( STAT_DISTANCE ).ToString() );
29 Print( STAT_PLAYTIME + " " + player.StatGet( STAT_PLAYTIME ).ToString() );
30 Print( STAT_PLAYERS_KILLED + " " + player.StatGet( STAT_PLAYERS_KILLED ).ToString() );
31 Print( STAT_INFECTED_KILLED + " " + player.StatGet( STAT_INFECTED_KILLED ).ToString() );
32 Print( STAT_LONGEST_SURVIVOR_HIT + " " + player.StatGet( STAT_LONGEST_SURVIVOR_HIT ).ToString() );
33 Print("-------------");
34 Print("");
35 */
36
37 //player.StatSyncToClient();
38 }
39
40 //Entity-Entity hit
41 void OnEntityHit( EntityAI source, Man target )
42 {
43 if (source)
44 {
45 Man survivor = source.GetHierarchyRootPlayer();
46 if ( survivor && source.IsWeapon() )
47 {
48 OnPlayerToPlayerHit( survivor, target );
49 }
50 }
51 }
52
53 protected void OnPlayerToPlayerHit( Man shooter, Man target )
54 {
55 //calculate distance
56 float longest_hit_dist = shooter.StatGet( STAT_LONGEST_SURVIVOR_HIT );
57 float current_dist = vector.Distance( shooter.GetPosition(), target.GetPosition() );
58 float dist_update;
59
60 if ( longest_hit_dist < current_dist )
61 {
62 dist_update = current_dist - longest_hit_dist;
63 }
64
65 /*
66 Print("");
67 Print("-------------");
68 Print(shooter.GetDisplayName() + " hit " + target.GetDisplayName() + " from " + longest_hit_dist.ToString() + " m" );
69 Print("-------------");
70 Print("");
71 */
72
73 //update stat
74 shooter.StatUpdate( STAT_LONGEST_SURVIVOR_HIT, dist_update );
75 }
76
77 //Entity-Entity kill
78 void OnEntityKilled( Object killer, EntityAI target )
79 {
80 EntityAI killer_entity = EntityAI.Cast( killer );
81 if ( killer_entity )
82 {
83 Man killer_survivor = killer_entity.GetHierarchyRootPlayer();
84 if ( killer_survivor )
85 {
86 if ( target.IsPlayer() )
87 {
88 OnPlayerKilled( killer_survivor, target );
89 }
90 else if ( target.IsZombie() )
91 {
92 OnInfectedKilled( killer_survivor, target );
93 }
94 }
95 }
96 }
97
98 protected void OnPlayerKilled( Man killer, EntityAI target )
99 {
100 /*
101 Print("");
102 Print("-------------");
103 Print(killer.GetDisplayName() + " killed player " + target.GetDisplayName() );
104 Print("-------------");
105 Print("");
106 */
107
108 //update stat
109 killer.StatUpdate( STAT_PLAYERS_KILLED, 1 );
110// killer.StatSyncToClient();
111 }
112
113 protected void OnInfectedKilled( Man killer, EntityAI target )
114 {
115 /*
116 Print("");
117 Print("-------------");
118 Print(killer.GetDisplayName() + " killed infected " + target.GetDisplayName() );
119 Print("-------------");
120 Print("");
121 */
122
123 //update stat
124 killer.StatUpdate( STAT_INFECTED_KILLED, 1 );
125// killer.StatSyncToClient();
126 }
127}
protected void OnPlayerKilled(Man killer, EntityAI target)
protected void OnInfectedKilled(Man killer, EntityAI target)
void OnEntityHit(EntityAI source, Man target)
void OnEntityKilled(Object killer, EntityAI target)
void OnPlayerDisconnect(Man player)
protected void OnPlayerToPlayerHit(Man shooter, Man target)
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.