-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathME5_Weapons.lua
More file actions
518 lines (423 loc) · 17.3 KB
/
ME5_Weapons.lua
File metadata and controls
518 lines (423 loc) · 17.3 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
-----------------------------------------------------------------
-----------------------------------------------------------------
-- MASS EFFECT: UNIFICATION Template Script by Aaron Gilbert
-- Build 80219/07
-- Screen Names: Marth8880, GT-Marth8880, [GT] Marth8880
-- E-Mail: Marth8880@gmail.com
-- Copyright (c) 2021, Aaron Gilbert All rights reserved.
--
-- About:
-- Scripted weapons.
--
--
-- Legal:
-- This script is licensed under the BSD 3-Clause License. A copy of this license (as LICENSE.md) should have been included
-- with this script. If it wasn't, it can also be found here: https://www.w3.org/Consortium/Legal/2008/03-bsd-license.html
--
-- THIS SCRIPT IS NOT MADE, DISTRIBUTED, OR SUPPORTED BY LUCASARTS, A DIVISION OF LUCASFILM ENTERTAINMENT COMPANY LTD.
-----------------------------------------------------------------
-----------------------------------------------------------------
local __SCRIPT_NAME = "ME5_Weapons";
local debug = true;
local function PrintLog(...)
if debug == true then
print("["..__SCRIPT_NAME.."]", unpack(arg));
end
end
PrintLog("Entered");
function Init_Weapon_Charge()
PrintLog("Init_Weapon_Charge: Entered")
local chargeShieldRegenDivisor = 3 -- Divisor for percentage of max shields to regen
local enemyDamageHandler = OnObjectDamage(
function(object, damager)
-- Exit immediately if there are incorrect values
if not object then return end
if not damager then return end
if not GetObjectLastHitWeaponClass(object) then return end
local hitByCorrectWeapon = false
local hitByBanshee = false
if string.ends(GetObjectLastHitWeaponClass(object), "charge") then
hitByCorrectWeapon = true
end
if string.ends(GetObjectLastHitWeaponClass(object), "banshee_charge") then
hitByBanshee = true
end
if hitByCorrectWeapon == true then
local charPtr = GetCharacterUnit(damager)
local objectPtr = GetEntityPtr(object)
if not charPtr then return end
if not objectPtr then return end
if GetObjectTeam(object) ~= GetObjectTeam(charPtr)
and GetObjectTeam(object) ~= 0 then
local teleEffect = CreateEffect("com_sfx_biotic_charge_tele")
SetEffectMatrix(teleEffect, GetEntityMatrix(charPtr))
-- get start and end coordinates
local xStart, yStart, zStart = GetWorldPosition(charPtr)
local xEnd, yEnd, zEnd = GetWorldPosition(objectPtr)
-- position deltas - create the vector
local dX = xEnd - xStart
local dY = yEnd - yStart
local dZ = zEnd - zStart
local distance = math.sqrt(dX * dX + dY * dY + dZ * dZ)
local objLocation = GetEntityMatrix(objectPtr)
-- create temporary other turret so we can calculate its rotation
tempturret = CreateEntity("com_bldg_chargedummy", CreateMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, objLocation), "temp_turret")
local xTemp, yTemp, zTemp = GetWorldPosition(tempturret)
DeleteEntity(tempturret)
tempturret = nil
--calculate angle (y-axis rotation)
local adjacent = xTemp - xEnd
local opposite = zTemp - zEnd
local hypotenuse = math.sqrt(((xTemp - xEnd) * (xTemp - xEnd)) + ((zTemp - zEnd) * (zTemp - zEnd)))
local phi = math.acos(adjacent / hypotenuse)
--correct the angle
-- this was a pain in the ass
if opposite < 0 then
phi = phi + (math.pi) / 2
else
phi = -(phi - (math.pi) / 2)
end
local newMatrix = CreateMatrix(phi - math.pi, 0.0, 1.0, 0.0, xStart + (dX), yStart + (dY - 0.5), zStart + (dZ + 0.5), nil)
SetEntityMatrix(charPtr, newMatrix)
-- PrintLog("newMatrix", newMatrix)
-- Don't recharge the user's shields if it's a Banshee
if hitByBanshee == false then
local curShields, maxShields = GetObjectShield(charPtr)
local newShields = curShields + (maxShields / chargeShieldRegenDivisor)
-- Don't let the shields spill over
if newShields > maxShields then
newShields = maxShields
end
SetProperty(charPtr, "CurShield", newShields)
end
if IsCharacterHuman(damager) and not ScriptCB_InMultiplayer() then
ScriptCB_SndPlaySound("biotic_charge_exp_2D")
-- ShowMessageText("level.common.debug.damager_ssv")
end
else
-- PrintLog("Object team doesn't match")
end
end
end
)
end
---
-- Sets up the event responses for ordnance that applies damage over time (DOT). Specifically, whenever an object is damaged by a weapon that's
-- supposed to have DOT ammo or a power that's supposed to have DOT effects (like Incinerate), an invisible
-- auto-turret that fires an EmitterOrdnance is spawned at the object's matrix and then immediately self-destructs.
--
function Init_Weapon_DOT()
PrintLog("Init_Weapon_DOT(): Entered")
if not ScriptCB_InMultiplayer() then
-- List of terms that incendiary weapons contain, these are used with string.sub(a,b,c) where a=[1], b=[2], c=[3]
local dotWeapons = {
{"incendiary", "com_bldg_incendiaryord_turret", -10, -1},
{"incinerate", "com_bldg_incendiaryord_turret", -10, -1},
{"incinerationblast", "com_bldg_incendiaryord_turret", -17, -1},
{"scorch", "com_bldg_incendiaryord_turret", -6, -1},
{"reave", "com_bldg_reaveord_turret", -5, -1},
}
-- Whenever an object is damaged
local targetdamage = OnObjectDamage(
function(object, damager)
-- Exit immediately if any values are incorrect
if not object then return end
if not damager then return end
local objectTeam = GetObjectTeam(object)
local damagerTeam = GetCharacterTeam(damager)
if (not objectTeam) or (objectTeam <= 0) then return end
if (not damagerTeam) or (damagerTeam <= 0) then return end
-- Are the object and damager on different teams?
if objectTeam ~= damagerTeam then
-- Figure out the damager's weapon (and exit if it's nil)
local damagerWeapon = GetObjectLastHitWeaponClass(object)
if not damagerWeapon then return end
-- Is the weapon DOT?
local bIsDot = false
local weaponIdx
for i in ipairs(dotWeapons) do
if string.sub(damagerWeapon, dotWeapons[i][3], dotWeapons[i][4]) == dotWeapons[i][1] then
bIsDot = true
weaponIdx = i
break
end
end
-- Exit if the weapon isn't DOT, or continue if it is
if bIsDot == false then
return
else
-- Spawn the DOT ordnance turret
gDotOrdTurretEntity = CreateEntity(dotWeapons[weaponIdx][2], GetEntityMatrix(object))
--PrintLog("Weapon ("..damagerWeapon..") is DOT")
end
end
end
)
end
end
function Init_Weapon_Cannibalize()
PrintLog("Init_Weapon_Cannibalize(): Entered")
gNumCorpsesAlive = 0 -- harr harr :P
local function OnReaperDeath(object, killer)
-- In order to prevent cases of corpses piling up out-of-bounds (for example),
-- only spawn a corpse if the unit was killed by another unit
if not killer then return end
if gNumCorpsesAlive >= MAX_CANNIBALIZE_CORPSE_COUNT then
else
if ScriptCB_random() <= CANNIBALIZE_CORPSE_DROP_CHANCE then
local corpsePos = GetEntityMatrix(object)
CreateEntity("rpr_bldg_cannibalize_unbuilt", corpsePos, "cannibalize_sofuckingstupid")
gNumCorpsesAlive = gNumCorpsesAlive + 1
end
end
end
local cannibalDeathHandler = OnObjectKillClass(OnReaperDeath, "rpr_inf_cannibal")
local marauderDeathHandler = OnObjectKillClass(OnReaperDeath, rpr_inf_marauder)
local ravagerDeathHandler = OnObjectKillClass(OnReaperDeath, "rpr_inf_ravager")
local bruteDeathHandler = OnObjectKillClass(OnReaperDeath, "rpr_inf_brute")
local bansheeDeathHandler = OnObjectKillClass(OnReaperDeath, rpr_inf_banshee)
local onCannibalizeHandler = OnObjectKillClass(
function(object, killer)
-- There needs to be a killer
if not killer then return end
gNumCorpsesAlive = gNumCorpsesAlive - 1
if GetObjectLastHitWeaponClass(object) == "rpr_weap_inf_cannibalize" then
PrintLog("Cannibal consumed a corpse!")
SetProperty(GetCharacterUnit(killer), "CurHealth", CANNIBALIZE_HEALTH_MAX)
SetProperty(GetCharacterUnit(killer), "MaxHealth", CANNIBALIZE_HEALTH_MAX)
end
end,
"rpr_bldg_cannibalize_unbuilt"
)
end
function Init_Weapon_AcidDrop()
PrintLog("Init_Weapon_AcidDrop(): Entered")
gNumAcidTurretsAlive = 0
local ravagerDeathHandler = OnObjectKillClass(
function(object, killer)
-- In order to prevent cases of corpses piling up out-of-bounds (for example),
-- only spawn a corpse if the unit was killed by another unit
if not killer then return end
if gNumAcidTurretsAlive < MAX_RAVAGER_ACID_COUNT then
if ScriptCB_random() <= RAVAGER_ACID_DROP_CHANCE then
local turretPos = GetEntityMatrix(object)
local newTurret = CreateEntity("rpr_weap_inf_ravager_acid_bldg", turretPos, "acidturret_sofuckingstupid")
gNumAcidTurretsAlive = gNumAcidTurretsAlive + 1
SetObjectTeam(newTurret, CIS)
local newAvoidanceTurret = CreateEntity("rpr_weap_inf_ravager_acid_avoidance_bldg", turretPos, "avoidanceturret_sofuckingstupid")
end
end
end,
"rpr_inf_ravager"
)
local acidTurretDeathHandler = OnObjectKillClass(
function(object, killer)
gNumAcidTurretsAlive = gNumAcidTurretsAlive - 1
end,
"rpr_weap_inf_ravager_acid_bldg"
)
end
function Init_Weapon_DispenseSeekers()
PrintLog("Init_Weapon_DispenseSeekers(): Entered")
if ME5_SideVar ~= 2 and ME5_SideVar ~= 4 then return end
gColCaptainsSpawned = {}
local onColCaptainSpawn = OnCharacterSpawnTeam(
function(player)
if GetCharacterClass(player) == 2 then
-- This Captain is new, so it hasn't spawned any Seekers yet
gColCaptainsSpawned[GetCharacterUnit(player)] = false
end
end,
CIS
)
local onColCaptainDie = OnObjectKill(
function(object, killer)
if not object then return end
if GetEntityClass(GetEntityPtr(object)) == FindEntityClass("col_inf_captain") or
GetEntityClass(GetEntityPtr(object)) == FindEntityClass("col_inf_captain_shield") then
-- Remove the Captain from the registry
if gColCaptainsSpawned[object] ~= nil then
gColCaptainsSpawned[object] = nil
end
end
end
)
local onDispenseSeekersHandler = OnCharacterDispenseControllableTeam(
function(character, controlled)
if GetEntityClass(controlled) == GetEntityClassPtr("col_weap_inf_captain_seekers_ord") then
-- Has this Captain spawned Seekers yet? Can only do so once per lifetime
if gColCaptainsSpawned[GetCharacterUnit(character)] == false then
gColCaptainsSpawned[GetCharacterUnit(character)] = true
local numSpawned = 0
local teamSize = GetTeamSize(SeekerTeam)
for i = 0, teamSize - 1 do
local characterIndex = GetTeamMember(SeekerTeam, i)
local charUnit = GetCharacterUnit(characterIndex)
if not charUnit then
local destination = GetEntityMatrix(GetCharacterUnit(character))
SpawnCharacter(characterIndex, destination)
numSpawned = numSpawned + 1
if numSpawned >= NUM_SEEKERS_PER_CAPTAIN then
break
end
end
end
else
-- PrintLog("This Captain has already spawned Seekers!")
end
end
end,
CIS
)
local onSeekerDie = OnObjectKill(
function(object, killer)
if not object then return end
-- Guarantee an "explosion" every time a Seeker dies
if GetEntityClass(GetEntityPtr(object)) == FindEntityClass("col_inf_seekers") then
local seekerExpPfx = CreateEffect("com_sfx_seekers_exp")
SetEffectMatrix(seekerExpPfx, GetEntityMatrix(object))
SetEntityMatrix(object, CreateMatrix(0, 0, 0, 0, 0, -1000, 0, GetEntityMatrix(object)))
end
end
)
end
function Init_Weapon_SeekerSuicide()
PrintLog("Init_Weapon_SeekerSuicide(): Entered")
if ME5_SideVar ~= 2 and ME5_SideVar ~= 4 then return end
-- Whenever an object is damaged
local onSeekerSuicideHit = OnObjectDamage(
function(object, damager)
-- Exit immediately if any values are incorrect
if not object then return end
if not damager then return end
if GetCharacterUnit(damager) == nil then return end
local objectTeam = GetObjectTeam(object)
local damagerTeam = GetCharacterTeam(damager)
if (not objectTeam) or (objectTeam <= 0) then return end
if (not damagerTeam) or (damagerTeam <= 0) then return end
-- Are the object and damager on different teams?
if objectTeam ~= damagerTeam then
-- Figure out the damager's weapon (and exit if it's nil)
local damagerWeapon = GetObjectLastHitWeaponClass(object)
if not damagerWeapon then return end
if damagerWeapon == "col_weap_inf_seekers_suicide" then
PrintLog("Init_Weapon_SeekerSuicide: Trying to kill user")
KillObject(GetCharacterUnit(damager))
end
end
end
)
end
function Init_Weapon_DispenseSwarmers()
PrintLog("Init_Weapon_DispenseSwarmers(): Entered")
if ME5_SideVar ~= 5 then return end
gRavagersSpawned = {}
local onRavagerSpawn = OnCharacterSpawnTeam(
function(player)
if GetCharacterClass(player) == 2 then
-- This Ravager is new, so it hasn't spawned any Swarmers yet
gRavagersSpawned[GetCharacterUnit(player)] = false
end
end,
CIS
)
local onRavagerDie = OnObjectKill(
function(object, killer)
if not object then return end
if GetEntityClass(GetEntityPtr(object)) == FindEntityClass("rpr_inf_ravager") then
-- Remove the Ravager from the registry
if gRavagersSpawned[object] ~= nil then
gRavagersSpawned[object] = nil
end
end
end
)
local onDispenseSwarmersHandler = OnCharacterDispenseControllableTeam(
function(character, controlled)
if GetEntityClass(controlled) == GetEntityClassPtr("rpr_weap_inf_ravager_swarmers_ord") then
-- Has this Ravager spawned Swarmers yet? Can only do so once per lifetime
if gRavagersSpawned[GetCharacterUnit(character)] == false then
gRavagersSpawned[GetCharacterUnit(character)] = true
local numSpawned = 0
local teamSize = GetTeamSize(SwarmerTeam)
for i = 0, teamSize - 1 do
local characterIndex = GetTeamMember(SwarmerTeam, i)
local charUnit = GetCharacterUnit(characterIndex)
if not charUnit then
local destination = GetEntityMatrix(GetCharacterUnit(character))
SpawnCharacter(characterIndex, destination)
numSpawned = numSpawned + 1
if numSpawned >= NUM_SWARMERS_PER_RAVAGER then
break
end
end
end
else
-- PrintLog("This Ravager has already spawned Swarmers!")
end
end
end,
CIS
)
local onSwarmerDie = OnObjectKill(
function(object, killer)
if not object then return end
-- Guarantee an "explosion" every time a Swarmer dies
if GetEntityClass(GetEntityPtr(object)) == FindEntityClass("rpr_inf_swarmer") then
local seekerExpPfx = CreateEffect("com_sfx_swarmer_exp")
SetEffectMatrix(seekerExpPfx, GetEntityMatrix(object))
SetEntityMatrix(object, CreateMatrix(0, 0, 0, 0, 0, -1000, 0, GetEntityMatrix(object)))
end
end
)
end
function Init_Weapon_SwarmerSuicide()
PrintLog("Init_Weapon_SwarmerSuicide(): Entered")
if ME5_SideVar ~= 5 then return end
-- Whenever an object is damaged
local onSwarmerSuicideHit = OnObjectDamage(
function(object, damager)
-- Exit immediately if any values are incorrect
if not object then return end
if not damager then return end
local objectTeam = GetObjectTeam(object)
local damagerTeam = GetCharacterTeam(damager)
if (not objectTeam) or (objectTeam <= 0) then return end
if (not damagerTeam) or (damagerTeam <= 0) then return end
-- Are the object and damager on different teams?
if objectTeam ~= damagerTeam then
-- Figure out the damager's weapon (and exit if it's nil)
local damagerWeapon = GetObjectLastHitWeaponClass(object)
if not damagerWeapon then return end
if damagerWeapon == "rpr_weap_inf_swarmer_suicide" then
KillObject(GetCharacterUnit(damager))
end
end
end
)
end
function Init_Weapon_ShieldPylon()
PrintLog("Init_Weapon_ShieldPylon(): Entered")
if ME5_SideVar ~= 6 then return end
-- Whenever an object is damaged
local onShieldPylonRegenHit = OnObjectDamage(
function(object, damager)
-- Exit immediately if any values are incorrect
if not object then return end
-- Figure out the damager's weapon (and exit if it's nil)
local damagerWeapon = GetObjectLastHitWeaponClass(object)
if not damagerWeapon then return end
if damagerWeapon == "cer_weap_bldg_shieldpylon_regen" then
local shieldRestoreAmount = 100
local objShieldCur, objShieldMax = GetObjectShield(object)
-- don't play the effect on units with full shields
if objShieldCur >= objShieldMax - 1 then return end
local newShield = math.clamp(objShieldCur + shieldRestoreAmount, 0, objShieldMax)
SetProperty(object, "CurShield", newShield)
local regenPfx = CreateEffect("com_sfx_shieldpylon_regen")
AttachEffectToMatrix(regenPfx, GetEntityMatrix(object))
end
end
)
end
PrintLog("Exited");