14 years
edited 8 years
Injury Effect Script
By moyack. 2009
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:
call SetDamageEffectPath(YOUR_RACE, "your\\effect\\path")
New feature!!
Now you set custom effects per unit type. To do that, these are the commands:
- AddBloodType("FX\\Path", "attach,point") // returns an integer which will identify that Blood type
- SetUnitTypeBlood('Unit_ID', BLOOD_TYPE_INDEX) // sets the Blood type for the unit type
- RemoveUnitTypeBlood('Unit_ID') // removes the Blood type for the unit type
Library Code.
1 library InjuryEffectScript initializer init requires Table
2 3 //* configuration part4 globals5 private constant real dt = 0.5 // check & effect rate...
6 private constant real Percentage = 0.3 // when unit reach 30% of its hitpoints, it will show blood
7 private constant string AttachPoint = "chest" // defines where's the attachment point of the effects for units
8 private constant string MechEffect = "Abilities\\Weapons\\FlyingMachine\\FlyingMachineImpact.mdl" // sets the "blood" model effect for mechanical units...
9 endglobals10 //* End configuration part.11 // Do NOT CHANGE THIS... unless you know what are you doing...12 globals13 //! textmacro SetGlobals takes Race14 private string array $Race$Blood
15 private integer $Race$Index = 0
16 //! endtextmacro17 //! runtextmacro SetGlobals("HUMAN")18 //! runtextmacro SetGlobals("ORC")19 //! runtextmacro SetGlobals("UNDEAD")20 //! runtextmacro SetGlobals("NIGHTELF")21 //! runtextmacro SetGlobals("DEMON")22 //! runtextmacro SetGlobals("OTHER")23 private group G = CreateGroup()
24 private rect R = null
25 endglobals26 27 private struct BloodType
28 static Table T29 string FX
30 string AttPoint
31 static method Add takes string FX, string AP returns integer
32 local BloodType BT = BloodType.allocate()
33 set BT.FX = FX
34 set BT.AttPoint = AP
35 return integer(BT)
36 endmethod37 static method SetBlood takes integer id, integer BloodT returns nothing
38 set BloodType.T[id] = BloodT
39 endmethod40 static method RemoveBlood takes integer id returns nothing
41 call BloodType.T.flush(id)
42 endmethod43 endstruct44 45 private function DoEffect takes nothing returns boolean
46 local unit u = GetFilterUnit()
47 if GetWidgetLife(u) / GetUnitState(u, UNIT_STATE_MAX_LIFE) <= Percentage and GetWidgetLife(u) > 0.405 then
48 if IsUnitType(u, UNIT_TYPE_MECHANICAL) == true then
49 call DestroyEffect(AddSpecialEffectTarget(MechEffect, u, "chest"))
50 return false
51 endif52 if BloodType.T.exists(GetUnitTypeId(u)) then
53 call DestroyEffect(AddSpecialEffectTarget(BloodType(BloodType.T[GetUnitTypeId(u)]).FX, u, BloodType(BloodType.T[GetUnitTypeId(u)]).AttPoint))
54 return false
55 endif56 //! textmacro DoConds takes Race57 if GetUnitRace(u) == RACE_$Race$ then
58 call DestroyEffect(AddSpecialEffectTarget($Race$Blood[GetRandomInt(0,$Race$Index)], u, AttachPoint))
59 return false
60 endif61 //! endtextmacro62 //! runtextmacro DoConds("HUMAN")63 //! runtextmacro DoConds("ORC")64 //! runtextmacro DoConds("UNDEAD")65 //! runtextmacro DoConds("NIGHTELF")66 //! runtextmacro DoConds("DEMON")67 //! runtextmacro DoConds("OTHER")68 endif69 return false
70 endfunction 71 72 private function Check takes nothing returns nothing
73 call GroupEnumUnitsInRect(G, R, Condition(function DoEffect))
74 endfunction75 76 //* Public functions77 //* Sets the damage effect for a specific race78 function SetDamageEffectPath takes race r, string path returns nothing
79 //! textmacro DoCond takes Race80 if r == RACE_$Race$ then
81 set $Race$Index = $Race$Index + 1
82 set $Race$Blood[$Race$Index] = path
83 return84 endif85 //! endtextmacro86 //! runtextmacro DoCond("HUMAN")87 //! runtextmacro DoCond("ORC")88 //! runtextmacro DoCond("UNDEAD")89 //! runtextmacro DoCond("NIGHTELF")90 //! runtextmacro DoCond("DEMON")91 //! runtextmacro DoCond("OTHER")92 endfunction93 //* Adds a new and custom Blood type effect to the database... it returns the Blood Type index94 function AddBloodType takes string fx, string attachpoint returns integer
95 return BloodType.Add(fx, attachpoint)
96 endfunction97 //* Sets a custom blood effect for a specific unit type...98 function SetUnitTypeBlood takes integer uid, integer bloodtype returns nothing
99 call BloodType.SetBlood(uid, bloodtype)
100 endfunction101 //* Removes to an specific unit type the custom Blood types, it will use instead the ones defined by race...102 function RemoveUnitTypeBlood takes integer uid returns nothing
103 call BloodType.RemoveBlood(uid)
104 endfunction105 //* End public functions106 107 private function init takes nothing returns nothing
108 set BloodType.T = Table.create()
109 set R = GetWorldBounds()
110 call SetDamageEffectPath(RACE_HUMAN , "Objects\\Spawnmodels\\Other\\HumanBloodCinematicEffect\\HumanBloodCinematicEffect.mdl")
111 call SetDamageEffectPath(RACE_ORC , "Objects\\Spawnmodels\\Other\\OrcBloodCinematicEffect\\OrcBloodCinematicEffect.mdl")
112 call SetDamageEffectPath(RACE_UNDEAD , "Objects\\Spawnmodels\\Undead\\UndeadBlood\\UndeadBloodAbomination.mdl")
113 call SetDamageEffectPath(RACE_NIGHTELF, "Objects\\Spawnmodels\\NightElf\\NightElfBlood\\NightElfBloodArcher.mdl")
114 call SetDamageEffectPath(RACE_DEMON , "Abilities\\Spells\\NightElf\\Immolation\\ImmolationDamage.mdl")
115 call SetDamageEffectPath(RACE_OTHER , "Objects\\Spawnmodels\\Undead\\UndeadBlood\\UndeadBloodNecromancer.mdl")
116 call TimerStart(CreateTimer(), dt, true, function Check)
117 endfunction118 endlibrary
Usage example for custom blood types:
9 scope TestingTime initializer init
10 11 globals12 private integer BLOOD_TYPE_NAGA // this global variable will store the index of this type of blood
13 endglobals14 //===========================================================================15 private function init takes nothing returns nothing
16 //* Creates a custom blood type, in this case one for nagas17 set BLOOD_TYPE_NAGA = AddBloodType("Objects\\Spawnmodels\\Demon\\DemonBlood\\DemonBloodPitlord.mdl", "origin")
18 call SetUnitTypeBlood('nwgs', BLOOD_TYPE_NAGA)
19 call SetUnitTypeBlood('nnmg', BLOOD_TYPE_NAGA)
20 call SetUnitTypeBlood('nnsw', BLOOD_TYPE_NAGA)
21 call SetUnitTypeBlood('nsnp', BLOOD_TYPE_NAGA)
22 call SetUnitTypeBlood('nmyr', BLOOD_TYPE_NAGA)
23 call SetUnitTypeBlood('nnrg', BLOOD_TYPE_NAGA)
24 call SetUnitTypeBlood('nhyc', BLOOD_TYPE_NAGA)
25 call SetUnitTypeBlood('nmpe', BLOOD_TYPE_NAGA)
26 call SetUnitTypeBlood('Hvsh', BLOOD_TYPE_NAGA)
27 endfunction28 29 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.