‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
demo_shared.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\system_shared;
4 
5 #insert scripts\shared\shared.gsh;
6 
7 #namespace demo;
8 
9 ‪REGISTER_SYSTEM( "demo", &‪__init__, undefined )
10 
11 function ‪__init__()
12 {
13  level thread ‪watch_actor_bookmarks();
14 }
15 
16 function ‪initActorBookmarkParams( killTimesCount, killTimeMsec, killTimeDelay )
17 {
18  level.actor_bookmark_kill_times_count = killTimesCount;
19  level.actor_bookmark_kill_times_msec = killTimeMsec;
20  level.actor_bookmark_kill_times_delay = killTimeDelay;
21 
22  level.actorbookmarkParamsInitialized = true;
23 }
24 
25 function ‪bookmark( type, time, mainClientEnt, otherClientEnt, eventPriority, inflictorEnt, overrideEntityCamera, actorEnt )
26 {
27  mainClientNum = -1;
28  otherClientNum = -1;
29  inflictorEntNum = -1;
30  inflictorEntType = 0;
31  inflictorBirthTime = 0;
32  actorEntNum = undefined;
33  scoreEventPriority = 0;
34 
35  if ( isdefined( mainClientEnt ) )
36  {
37  mainClientNum = mainClientEnt getEntityNumber();
38  }
39 
40  if ( isdefined( otherClientEnt ) )
41  {
42  otherClientNum = otherClientEnt getEntityNumber();
43  }
44 
45  if ( isdefined( eventPriority ) )
46  {
47  scoreEventPriority = eventPriority;
48  }
49 
50  if ( isdefined( inflictorEnt ) )
51  {
52  inflictorEntNum = inflictorEnt getEntityNumber();
53  inflictorEntType = inflictorEnt getEntityType();
54 
55  if ( isdefined( inflictorEnt.birthTime ) )
56  {
57  inflictorBirthTime = inflictorEnt.birthTime;
58  }
59  }
60 
61  if ( !isdefined( overrideEntityCamera ) )
62  {
63  overrideEntityCamera = false;
64  }
65 
66  if ( isdefined( actorEnt ) )
67  {
68  actorEntNum = actorEnt getEntityNumber();
69  }
70 
71  addDemoBookmark( type, time, mainClientNum, otherClientNum, scoreEventPriority, inflictorEntNum, inflictorEntType, inflictorBirthTime, overrideEntityCamera, actorEntNum );
72 }
73 
74 function ‪gameResultBookmark( type, winningTeamIndex, losingTeamIndex )
75 {
76  mainClientNum = -1;
77  otherClientNum = -1;
78  scoreEventPriority = 0;
79  inflictorEntNum = -1;
80  inflictorEntType = 0;
81  inflictorBirthTime = 0;
82  overrideEntityCamera = false;
83  actorEntNum = undefined;
84 
85  if ( isdefined( winningTeamIndex ) )
86  {
87  mainClientNum = winningTeamIndex;
88  }
89 
90  if ( isdefined( losingTeamIndex ) )
91  {
92  otherClientNum = losingTeamIndex;
93  }
94 
95  // We reuse mainClientNum and otherClientNum for the winning and losing teamIndex
96  addDemoBookmark( type, gettime(), mainClientNum, otherClientNum, scoreEventPriority, inflictorEntNum, inflictorEntType, inflictorBirthTime, overrideEntityCamera, actorEntNum );
97 }
98 
100 {
101  if ( !isDefined( level.actorbookmarkParamsInitialized ) )
102  {
103  return;
104  }
105 
106  if ( !IsDefined( self.actor_bookmark_kill_times ) )
107  {
108  self.actor_bookmark_kill_times = [];
109  self.ignore_actor_kill_times = 0;
110  }
111 
112  for ( i = 0; i < level.actor_bookmark_kill_times_count; i++ )
113  {
114  self.actor_bookmark_kill_times[i] = 0;
115  }
116 }
117 
118 
120 {
121  if ( !isDefined( level.actorbookmarkParamsInitialized ) )
122  return;
123 
124  now = gettime();
125  if ( now <= self.ignore_actor_kill_times )
126  {
127  return;
128  }
129 
130  oldest_index = 0;
131  oldest_time = now + 1;
132 
133  for ( i = 0; i < level.actor_bookmark_kill_times_count; i++ )
134  {
135  if ( !self.actor_bookmark_kill_times[i] )
136  {
137  oldest_index = i;
138  break;
139  }
140  else if ( oldest_time > self.actor_bookmark_kill_times[i] )
141  {
142  oldest_index = i;
143  oldest_time = self.actor_bookmark_kill_times[i];
144  }
145  }
146 
147  self.actor_bookmark_kill_times[oldest_index] = now;
148 }
149 
150 
152 {
153  while ( true )
154  {
155  if ( !isDefined( level.actorbookmarkParamsInitialized ) )
156  {
157  wait( 0.5 );
158  continue;
159  }
160 
162  waittillframeend;
163 
164  now = gettime();
165  oldest_allowed = now - level.actor_bookmark_kill_times_msec;
166  players = GetPlayers();
167  for ( player_index = 0; player_index < players.size; player_index++ )
168  {
169  player = players[player_index];
170 
171  for ( time_index = 0; time_index < level.actor_bookmark_kill_times_count; time_index++ )
172  {
173  if ( !IsDefined( player.actor_bookmark_kill_times ) || !player.actor_bookmark_kill_times[time_index] )
174  {
175  break;
176  }
177  else if ( oldest_allowed > player.actor_bookmark_kill_times[time_index] )
178  {
179  player.actor_bookmark_kill_times[time_index] = 0;
180  break;
181  }
182  }
183 
184  if ( time_index >= level.actor_bookmark_kill_times_count ) // all times slots were within the needed range
185  {
186  ‪bookmark( "actor_kill", gettime(), player );
188  player.ignore_actor_kill_times = now + level.actor_bookmark_kill_times_delay;
189  }
190  }
191  }
192 }
‪reset_actor_bookmark_kill_times
‪function reset_actor_bookmark_kill_times()
Definition: demo_shared.gsc:99
‪gameResultBookmark
‪function gameResultBookmark(type, winningTeamIndex, losingTeamIndex)
Definition: demo_shared.gsc:74
‪add_actor_bookmark_kill_time
‪function add_actor_bookmark_kill_time()
Definition: demo_shared.gsc:119
‪REGISTER_SYSTEM
‪#define REGISTER_SYSTEM(__sys, __func_init_preload, __reqs)
Definition: shared.gsh:204
‪bookmark
‪function bookmark(type, time, mainClientEnt, otherClientEnt, eventPriority, inflictorEnt, overrideEntityCamera, actorEnt)
Definition: demo_shared.gsc:25
‪initActorBookmarkParams
‪function initActorBookmarkParams(killTimesCount, killTimeMsec, killTimeDelay)
Definition: demo_shared.gsc:16
‪__init__
‪function __init__()
Definition: demo_shared.gsc:11
‪watch_actor_bookmarks
‪function watch_actor_bookmarks()
Definition: demo_shared.gsc:151
‪WAIT_SERVER_FRAME
‪#define WAIT_SERVER_FRAME
Definition: shared.gsh:265