Created
July 8, 2019 20:12
-
-
Save marth8880/16826e575d995c6d3a89af7a16353815 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- ************************************************************** | |
| -- TCW Damage Feedback Script | |
| -- Aaron Gilbert - Marth8880@gmail.com | |
| -- Copyright (c) 2018 Aaron Gilbert. All rights reserved. | |
| -- | |
| -- About: | |
| -- TODO: fill this in! | |
| -- | |
| -- Legal: | |
| -- REPRODUCTION OR TRANSMISSION OF ALL OR PART OF THIS COPYRIGHT WORK IN ANY MEDIUM OR BY ELECTRONIC MEANS WITHOUT THE WRITTEN PERMISSION OF AARON GILBERT IS PROHIBITED. | |
| -- THIS SCRIPT IS NOT MADE, DISTRIBUTED, OR SUPPORTED BY LUCASARTS, A DIVISION OF LUCASFILM ENTERTAINMENT COMPANY LTD. | |
| -- ************************************************************** | |
| local __SCRIPT_NAME = "TCW_DamageFeedback"; | |
| local debug = true; | |
| local function PrintLog(...) | |
| if debug == true then | |
| print("["..__SCRIPT_NAME.."]", unpack(arg)); | |
| end | |
| end | |
| PrintLog("Entered") | |
| --========================== | |
| -- INITIALIZE TABLES | |
| --========================== | |
| -- Vehicle ballistic weapons (for vehicles that any team can pilot). | |
| local ballisticWeapons_VEH = { | |
| "tur_weap_laser", | |
| "tur_weap_hoth_lasermortar_laser", | |
| "tur_weap_hoth_dishturret", | |
| "cis_weap_hover_aat_cannon", | |
| "cis_weap_hover_aat_launcher", | |
| "cis_weap_hover_mtt_cannon", | |
| "cis_weap_hover_stap_cannon", | |
| "cis_weap_walk_tridroid_laser", | |
| "cis_weap_walk_tridroid_recoilless", | |
| "rep_weap_hover_speederbike_cannon", | |
| "rep_weap_walk_atrt_laser", | |
| "rep_weap_walk_atte_laser", | |
| "rep_weap_walk_atte_turret_cannon", | |
| "rep_weap_walk_atte_rear_gun", | |
| "rep_weap_walk_oneman_atst_cannon", | |
| } | |
| local ballisticWeapons_REP = { | |
| -- Primary | |
| "rep_weap_inf_Z6", | |
| "rep_weap_inf_DC-15A", | |
| "rep_weap_inf_DC-15S", | |
| "rep_weap_inf_DC-17", | |
| "rep_weap_inf_DH-17", | |
| "rep_weap_inf_DLT-20A", | |
| "rep_weap_inf_rps_rocket_launcher", | |
| "rep_weap_bldg_chaingun_laser", | |
| -- Secondary | |
| "rep_weap_inf_detpack", | |
| "rep_weap_inf_EMP_grenade", | |
| "rep_weap_inf_thermaldetonator", | |
| } | |
| local ballisticWeapons_CIS = { | |
| -- Primary | |
| "cis_weap_inf_rifle", | |
| "cis_weap_inf_wrist_blaster", | |
| "cis_weap_inf_wrist_blaster_dual", | |
| "cis_weap_inf_repeater", | |
| "cis_weap_inf_sniper_rifle_BX", | |
| "rep_weap_inf_rps_rocket_launcher", | |
| "cis_weap_inf_electrostaff", | |
| -- Secondary | |
| "cis_weap_inf_thermaldetonator", | |
| "cis_weap_inf_wrist_rocket", | |
| } | |
| --========================== | |
| -- MERGE TABLES | |
| --========================== | |
| -- Merge the VEH table with each faction's table | |
| if table.getn(ballisticWeapons_VEH) > 0 then | |
| for i in ipairs(ballisticWeapons_VEH) do | |
| table.insert(ballisticWeapons_REP, ballisticWeapons_VEH[i]) | |
| table.insert(ballisticWeapons_CIS, ballisticWeapons_VEH[i]) | |
| end | |
| end | |
| --========================== | |
| -- FUNCTIONS | |
| --========================== | |
| --- | |
| -- Sets up the event responses for the hit marker sounds. | |
| -- | |
| function Init_HitMarkerSounds(data) | |
| PrintLog("Init_HitMarkerSounds: Entered") | |
| if not ScriptCB_InMultiplayer() then | |
| local stats = data.teamStats; | |
| local repUnitClasses = data.legion.unitClassOverrides or DefaultRepUnitClasses; | |
| local cisUnitClasses = DefaultCisUnitClasses; | |
| local b1fodderUnitClasses = DefaultB1fodderUnitClasses; | |
| local b1specialUnitClasses = DefaultB1specialUnitClasses; | |
| local Iamhuman = nil -- Pointer for human player. | |
| local bIsDamagerCorrectClass = false -- Is the damager the correct class? | |
| local damagerFaction = "none" -- Which faction is the damager from? | |
| --========================== | |
| -- LOCAL FUNCTIONS | |
| --========================== | |
| --- | |
| -- @param #string type The type of impact sounds to play ("armor" or "normal"). | |
| -- | |
| local function PlayDamageSound(type) | |
| -- PrintLog("Init_HitMarkerSounds.PlayDamageSound: Playing damage sound") | |
| ScriptCB_SndPlaySound("enemy_damaged_layered") | |
| --if bIsIncendiary == false then | |
| -- local randSnd = math.random(0,10) | |
| -- What is the surface type? | |
| -- if type == "armor" then | |
| --print("Playing armor sound") | |
| -- What is the weapon type? | |
| -- if weaponType == 2 then | |
| -- print("Weapon is sniper") | |
| -- ScriptCB_SndPlaySound("enemy_armor_sniper_impact") | |
| -- elseif weaponType == 3 then | |
| -- ScriptCB_SndPlaySound("enemy_armor_shotgun_impact") | |
| -- elseif weaponType == 4 then | |
| -- ScriptCB_SndPlaySound("enemy_armor_gps_impact_layered") | |
| -- else | |
| -- ScriptCB_SndPlaySound("enemy_damage_armor_layered_"..randSnd) | |
| -- end | |
| -- elseif type == "normal" then | |
| --print("Playing normal sound") | |
| -- if weaponType == 2 then | |
| -- print("Weapon is sniper") | |
| -- ScriptCB_SndPlaySound("enemy_normal_sniper_impact") | |
| -- elseif weaponType == 3 then | |
| -- ScriptCB_SndPlaySound("enemy_normal_shotgun_impact") | |
| -- elseif weaponType == 4 then | |
| -- ScriptCB_SndPlaySound("enemy_normal_gps_impact_layered") | |
| -- else | |
| -- ScriptCB_SndPlaySound("enemy_damage_normal_layered_"..randSnd) | |
| -- end | |
| -- end | |
| --end | |
| end | |
| --========================== | |
| -- EVENT RESPONSES | |
| --========================== | |
| -- When the player spawns | |
| local playerspawn = OnCharacterSpawn( | |
| function(player) | |
| if IsCharacterHuman(player) then | |
| --PrintLog("Init_HitMarkerSounds: Player spawned") | |
| Iamhuman = GetEntityPtr(GetCharacterUnit(player)) | |
| -- Reset class | |
| bIsDamagerCorrectClass = false | |
| end | |
| end | |
| ) | |
| -- When an enemy is damaged | |
| local enemydamage = OnObjectDamage( | |
| function(object, damager) | |
| -- Abort if the damager or object is nil | |
| if not damager then return end | |
| if not object then return end | |
| if GetCharacterUnit(damager) == nil then return end | |
| -- Was the damager the player? | |
| if IsCharacterHuman(damager) then | |
| --PrintLog("Init_HitMarkerSounds.enemydamage: Damager is the player") | |
| --local playerPtr = GetEntityPtr(GetCharacterUnit(damager)) -- Damager's pointer. | |
| --local playerClass = GetEntityClass(playerPtr) -- Damager's class. | |
| local damagerTeam = GetCharacterTeam(damager) -- Damager's team. | |
| local damagerWeapon = GetObjectLastHitWeaponClass(object) -- Damager's weapon class. | |
| local objectPtr = GetEntityPtr(object) -- Damaged object's pointer. | |
| local objectClass = GetEntityClass(objectPtr) -- Damaged object's class. | |
| -- local bIsObjectArmorClass = false -- Is the damaged object an armored class? | |
| -- Exit immediately if any fields are wrong | |
| if not damagerTeam then return end | |
| if damagerTeam <= 0 then return end | |
| if not damagerWeapon then return end | |
| if not objectClass then return end | |
| -- Which team is the damager from? | |
| if damagerTeam == CIS then | |
| --PrintLog("Init_HitMarkerSounds: Damager is from team CIS") | |
| --ShowMessageText("level.common.debug.damager_cis") | |
| -- For each weapon class | |
| for i=1, table.getn(ballisticWeapons_CIS) do | |
| -- Was the weapon used a valid ballistic weapon? | |
| if damagerWeapon == ballisticWeapons_CIS[i] then | |
| -- Play the player damage sound | |
| PlayDamageSound("normal") | |
| break | |
| end | |
| end | |
| elseif damagerTeam == REP then | |
| --PrintLog("Init_HitMarkerSounds: Damager is from team REP") | |
| --ShowMessageText("level.common.debug.damager_rep") | |
| -- For each weapon class | |
| for i=1, table.getn(ballisticWeapons_REP) do | |
| -- Was the weapon used a valid ballistic weapon? | |
| if damagerWeapon == ballisticWeapons_REP[i] then | |
| -- Play the player damage sound | |
| PlayDamageSound("normal") | |
| break | |
| end | |
| end | |
| end | |
| -- PlayDamageSound("normal") | |
| end | |
| end | |
| ) | |
| end | |
| end | |
| PrintLog("Exited") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment