InjuryEffectScript

Scripts

14 years
edited 8 years
Injury Effect Script
By moyack. 2009

Ok, after revising this old resource, I took the freedom to develop something much more stable, configurable, clean and effective.

This script requires Jass New Gen Pack, and Table (Check related resources) to work properly.

Installation:


  • Create a new Trigger
  • Call it properly. like "Injury Effect Script"
  • Convert it to custom text
  • Remove the code posted.
  • Paste the code above
  • Save the map.
  • Voila!!! now it works.

As is, it only will use a single effect per race. If you want to add more FXs to any race, you can use this function:

[lcode=jass]call SetDamageEffectPath(YOUR_RACE, "your\\effect\\path")[/lcode]



New feature!!

Now you set custom effects per unit type. To do that, these are the commands:


  • [lcode=jass]AddBloodType("FX\\Path", "attach,point") // returns an integer which will identify that Blood type[/lcode]
  • [lcode=jass]SetUnitTypeBlood('Unit_ID', BLOOD_TYPE_INDEX) // sets the Blood type for the unit type[/lcode]
  • [lcode=jass]RemoveUnitTypeBlood('Unit_ID') // removes the Blood type for the unit type[/lcode]


Library Code.

Code (jass) Select
library InjuryEffectScript initializer init requires Table

//* configuration part
globals
    private constant real   dt          = 0.5 // check & effect rate...
    private constant real   Percentage  = 0.3 // when unit reach 30% of its hitpoints, it will show blood
    private constant string AttachPoint = "chest" // defines where's the attachment point of the effects for units
    private constant string MechEffect  = "Abilities\\Weapons\\FlyingMachine\\FlyingMachineImpact.mdl" // sets the "blood" model effect for mechanical units...
endglobals
//* End configuration part.
// Do NOT CHANGE THIS... unless you know what are you doing...
globals
    //! textmacro SetGlobals takes Race
    private          string array $Race$Blood
    private          integer $Race$Index = 0
    //! endtextmacro
    //! runtextmacro SetGlobals("HUMAN")
    //! runtextmacro SetGlobals("ORC")
    //! runtextmacro SetGlobals("UNDEAD")
    //! runtextmacro SetGlobals("NIGHTELF")
    //! runtextmacro SetGlobals("DEMON")
    //! runtextmacro SetGlobals("OTHER")
    private          group G = CreateGroup()
    private          rect  R = null
endglobals

private struct BloodType
    static Table T
    string FX
    string AttPoint
    static method Add takes string FX, string AP returns integer
        local BloodType BT = BloodType.allocate()
        set BT.FX = FX
        set BT.AttPoint = AP
        return integer(BT)
    endmethod
    static method SetBlood takes integer id, integer BloodT returns nothing
        set BloodType.T[id] = BloodT
    endmethod
    static method RemoveBlood takes integer id returns nothing
        call BloodType.T.flush(id)
    endmethod
endstruct

private function DoEffect takes nothing returns boolean
    local unit u = GetFilterUnit()
    if GetWidgetLife(u) / GetUnitState(u, UNIT_STATE_MAX_LIFE) <= Percentage and GetWidgetLife(u) > 0.405 then
        if IsUnitType(u, UNIT_TYPE_MECHANICAL) == true then
            call DestroyEffect(AddSpecialEffectTarget(MechEffect, u, "chest"))
            return false
        endif
        if BloodType.T.exists(GetUnitTypeId(u)) then
            call DestroyEffect(AddSpecialEffectTarget(BloodType(BloodType.T[GetUnitTypeId(u)]).FX, u, BloodType(BloodType.T[GetUnitTypeId(u)]).AttPoint))
            return false
        endif
        //! textmacro DoConds takes Race
        if GetUnitRace(u) == RACE_$Race$ then
            call DestroyEffect(AddSpecialEffectTarget($Race$Blood[GetRandomInt(0,$Race$Index)], u, AttachPoint))
            return false
        endif
        //! endtextmacro
        //! runtextmacro DoConds("HUMAN")
        //! runtextmacro DoConds("ORC")
        //! runtextmacro DoConds("UNDEAD")
        //! runtextmacro DoConds("NIGHTELF")
        //! runtextmacro DoConds("DEMON")
        //! runtextmacro DoConds("OTHER")
    endif
    return false
endfunction

private function Check takes nothing returns nothing
    call GroupEnumUnitsInRect(G, R, Condition(function DoEffect))
endfunction

//* Public functions
//* Sets the damage effect for a specific race
function SetDamageEffectPath takes race r, string path returns nothing
    //! textmacro DoCond takes Race
    if r == RACE_$Race$ then
        set $Race$Index = $Race$Index + 1
        set $Race$Blood[$Race$Index] = path
        return
    endif
    //! endtextmacro
    //! runtextmacro DoCond("HUMAN")
    //! runtextmacro DoCond("ORC")
    //! runtextmacro DoCond("UNDEAD")
    //! runtextmacro DoCond("NIGHTELF")
    //! runtextmacro DoCond("DEMON")
    //! runtextmacro DoCond("OTHER")
endfunction
//* Adds a new and custom Blood type effect to the database... it returns the Blood Type index
function AddBloodType takes string fx, string attachpoint returns integer
    return BloodType.Add(fx, attachpoint)
endfunction
//* Sets a custom blood effect for a specific unit type...
function SetUnitTypeBlood takes integer uid, integer bloodtype returns nothing
    call BloodType.SetBlood(uid, bloodtype)
endfunction
//* Removes to an specific unit type the custom Blood types, it will use instead the ones defined by race...
function RemoveUnitTypeBlood takes integer uid returns nothing
    call BloodType.RemoveBlood(uid)
endfunction
//* End public functions

private function init takes nothing returns nothing
    set BloodType.T = Table.create()
    set R = GetWorldBounds()
    call SetDamageEffectPath(RACE_HUMAN   , "Objects\\Spawnmodels\\Other\\HumanBloodCinematicEffect\\HumanBloodCinematicEffect.mdl")
    call SetDamageEffectPath(RACE_ORC     , "Objects\\Spawnmodels\\Other\\OrcBloodCinematicEffect\\OrcBloodCinematicEffect.mdl")
    call SetDamageEffectPath(RACE_UNDEAD  , "Objects\\Spawnmodels\\Undead\\UndeadBlood\\UndeadBloodAbomination.mdl")
    call SetDamageEffectPath(RACE_NIGHTELF, "Objects\\Spawnmodels\\NightElf\\NightElfBlood\\NightElfBloodArcher.mdl")
    call SetDamageEffectPath(RACE_DEMON   , "Abilities\\Spells\\NightElf\\Immolation\\ImmolationDamage.mdl")
    call SetDamageEffectPath(RACE_OTHER   , "Objects\\Spawnmodels\\Undead\\UndeadBlood\\UndeadBloodNecromancer.mdl")
    call TimerStart(CreateTimer(), dt, true, function Check)
endfunction
endlibrary


Usage example for custom blood types:

Code (jass,9,10) Select
scope TestingTime initializer init

globals
    private integer BLOOD_TYPE_NAGA // this global variable will store the index of this type of blood
endglobals
//===========================================================================
private function init takes nothing returns nothing
    //* Creates a custom blood type, in this case one for nagas
    set BLOOD_TYPE_NAGA = AddBloodType("Objects\\Spawnmodels\\Demon\\DemonBlood\\DemonBloodPitlord.mdl", "origin")
    call SetUnitTypeBlood('nwgs', BLOOD_TYPE_NAGA)
    call SetUnitTypeBlood('nnmg', BLOOD_TYPE_NAGA)
    call SetUnitTypeBlood('nnsw', BLOOD_TYPE_NAGA)
    call SetUnitTypeBlood('nsnp', BLOOD_TYPE_NAGA)
    call SetUnitTypeBlood('nmyr', BLOOD_TYPE_NAGA)
    call SetUnitTypeBlood('nnrg', BLOOD_TYPE_NAGA)
    call SetUnitTypeBlood('nhyc', BLOOD_TYPE_NAGA)
    call SetUnitTypeBlood('nmpe', BLOOD_TYPE_NAGA)
    call SetUnitTypeBlood('Hvsh', BLOOD_TYPE_NAGA)
endfunction

endscope


Changelog:


  • (23/03/2009): First Release
  • (24/03/2009): now it works with all the races defined by the WC3 engine. Added a function to add more effects to any race. simplified the code and now it doesn't requires additional libraries.
  • (05/04/2009): Added the possibility to set a custom blood type per unit type, check the new functions you can use here. Now it requires Table.