‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_teargrenades.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\util_shared;
4 
5 #insert scripts\shared\shared.gsh;
6 
7 #using scripts\mp\gametypes\_perplayer;
8 
9 #using scripts\mp\_util;
10 
11 function ‪main()
12 {
13  level.tearradius = 170;
14  level.tearheight = 128;
15  level.teargasfillduration = 7; // time until gas fills the area specified
16  level.teargasduration = 23; // duration gas remains in area
17  level.tearsufferingduration = 3; // (duration after leaving area of effect)
18 
19  level.teargrenadetimer = 4; // should match time to appearance of effect
20 
22  ‪perplayer::enable(fgmonitor);
23 }
24 
26 {
27  self thread ‪monitorTearUsage();
28 }
29 function ‪stopMonitoringTearUsage(disconnected)
30 {
31  self notify("stop_monitoring_tear_usage");
32 }
33 
35 {
36  self endon("stop_monitoring_tear_usage");
37 
38  wait .05;
39 
40  weapon = GetWeapon( "tear_grenade" );
41  if (!self hasWeapon( weapon ))
42  return;
43 
44  // when this player's tear grenade ammo goes down, assume the nearest "grenade" entity is a tear grenade.
45 
46  prevammo = self getammocount( weapon );
47  while(1)
48  {
49  ammo = self getammocount( weapon );
50  if (ammo < prevammo)
51  {
52  num = prevammo - ammo;
53  for (i = 0; i < num; i++)
54  {
55  grenades = getEntArray("grenade", "classname");
56  bestdist = undefined;
57  bestg = undefined;
58  for (g = 0; g < grenades.size; g++)
59  {
60  if (!isdefined(grenades[g].teargrenade))
61  {
62  dist = distance(grenades[g].origin, self.origin + (0,0,48));
63  if (!isdefined(bestdist) || dist < bestdist)
64  {
65  bestdist = dist;
66  bestg = g;
67  }
68  }
69  }
70  if (isdefined(bestdist))
71  {
72  grenades[bestg].teargrenade = true;
73  grenades[bestg] thread ‪tearGrenade_think(self.team);
74  }
75  }
76  }
77  prevammo = ammo;
78  wait .05;
79  }
80 }
81 
82 function ‪tearGrenade_think(team)
83 {
84  // wait for death
85 
86  // (grenade doesn't actually die until finished smoking)
87  wait level.teargrenadetimer;
88 
89  ent = spawnstruct();
90  ent thread ‪tear(self.origin);
91 }
92 
93 function ‪tear(pos)
94 {
95  trig = ‪spawn("trigger_radius", pos, 0, level.tearradius, level.tearheight);
96 
97  starttime = gettime();
98 
99  self thread ‪teartimer();
100  self endon("tear_timeout");
101 
102  while(1)
103  {
104  trig waittill("trigger", player);
105 
106  if (player.sessionstate != "playing")
107  continue;
108 
109  time = (gettime() - starttime) / 1000;
110 
111  currad = level.tearradius;
112  curheight = level.tearheight;
113  if (time < level.teargasfillduration) {
114  currad = currad * (time / level.teargasfillduration);
115  curheight = curheight * (time / level.teargasfillduration);
116  }
117 
118  offset = (player.origin + (0,0,32)) - pos;
119  offset2d = (offset[0], offset[1], 0);
120  if (lengthsquared(offset2d) > currad*currad)
121  continue;
122  if (player.origin[2] - pos[2] > curheight)
123  continue;
124 
125  player.teargasstarttime = gettime(); // purposely overriding old value
126  if (!isdefined(player.teargassuffering))
127  player thread ‪teargassuffering();
128  }
129 }
130 function ‪teartimer()
131 {
132  wait level.teargasduration;
133  self notify("tear_timeout");
134 }
135 
137 {
138  self endon("death");
139  self endon("disconnect");
140 
141  self.teargassuffering = true;
142 
143  if ( self ‪util::mayApplyScreenEffect() )
144  self shellshock("teargas", 60);
145 
146  while(1)
147  {
148  if (gettime() - self.teargasstarttime > level.tearsufferingduration * 1000)
149  break;
150 
151  wait 1;
152  }
153 
154  self shellshock("teargas", 1);
155 
156  if ( self ‪util::mayApplyScreenEffect() )
157  self.teargassuffering = undefined;
158 }
159 
‪enable
‪function enable(handler)
Definition: _perplayer.gsc:54
‪main
‪function main()
Definition: _teargrenades.gsc:11
‪spawn
‪function spawn(v_origin=(0, 0, 0), v_angles=(0, 0, 0))
Definition: struct.csc:23
‪teartimer
‪function teartimer()
Definition: _teargrenades.gsc:130
‪stopMonitoringTearUsage
‪function stopMonitoringTearUsage(disconnected)
Definition: _teargrenades.gsc:29
‪tearGrenade_think
‪function tearGrenade_think(team)
Definition: _teargrenades.gsc:82
‪monitorTearUsage
‪function monitorTearUsage()
Definition: _teargrenades.gsc:34
‪init
‪function init()
Definition: struct.csc:1
‪tear
‪function tear(pos)
Definition: _teargrenades.gsc:93
‪teargassuffering
‪function teargassuffering()
Definition: _teargrenades.gsc:136
‪mayApplyScreenEffect
‪function mayApplyScreenEffect()
Definition: util_shared.gsc:2613
‪startMonitoringTearUsage
‪function startMonitoringTearUsage()
Definition: _teargrenades.gsc:25