Warcraft 3 documentation
vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

InjuryEffectScript No New Posts Codes & Snippets

Started by
moyack

0 Members and 1 Guest are viewing this topic.

InjuryEffectScript
on: December 28, 2011, 08:24:44 AM
Category: Effect
Language: vJASS

Related Topics or Resources



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:

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.

Code: jass
  1. library InjuryEffectScript initializer init requires Table
  2.  
  3. //* configuration part
  4. globals
  5.     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. endglobals
  10. //* End configuration part.
  11. // Do NOT CHANGE THIS... unless you know what are you doing...
  12. globals
  13.     //! textmacro SetGlobals takes Race
  14.     private          string array $Race$Blood
  15.     private          integer $Race$Index = 0
  16.     //! endtextmacro
  17.     //! 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. endglobals
  26.  
  27. private struct BloodType
  28.     static Table T
  29.     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.     endmethod
  37.     static method SetBlood takes integer id, integer BloodT returns nothing
  38.         set BloodType.T[id] = BloodT
  39.     endmethod
  40.     static method RemoveBlood takes integer id returns nothing
  41.         call BloodType.T.flush(id)
  42.     endmethod
  43. endstruct
  44.  
  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.         endif
  52.         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.         endif
  56.         //! textmacro DoConds takes Race
  57.         if GetUnitRace(u) == RACE_$Race$ then
  58.             call DestroyEffect(AddSpecialEffectTarget($Race$Blood[GetRandomInt(0,$Race$Index)], u, AttachPoint))
  59.             return false
  60.         endif
  61.         //! endtextmacro
  62.         //! runtextmacro DoConds("HUMAN")
  63.         //! runtextmacro DoConds("ORC")
  64.         //! runtextmacro DoConds("UNDEAD")
  65.         //! runtextmacro DoConds("NIGHTELF")
  66.         //! runtextmacro DoConds("DEMON")
  67.         //! runtextmacro DoConds("OTHER")
  68.     endif
  69.     return false
  70. endfunction
  71.  
  72. private function Check takes nothing returns nothing
  73.     call GroupEnumUnitsInRect(G, R, Condition(function DoEffect))
  74. endfunction
  75.  
  76. //* Public functions
  77. //* Sets the damage effect for a specific race
  78. function SetDamageEffectPath takes race r, string path returns nothing
  79.     //! textmacro DoCond takes Race
  80.     if r == RACE_$Race$ then
  81.         set $Race$Index = $Race$Index + 1
  82.         set $Race$Blood[$Race$Index] = path
  83.         return
  84.     endif
  85.     //! endtextmacro
  86.     //! runtextmacro DoCond("HUMAN")
  87.     //! runtextmacro DoCond("ORC")
  88.     //! runtextmacro DoCond("UNDEAD")
  89.     //! runtextmacro DoCond("NIGHTELF")
  90.     //! runtextmacro DoCond("DEMON")
  91.     //! runtextmacro DoCond("OTHER")
  92. endfunction
  93. //* Adds a new and custom Blood type effect to the database... it returns the Blood Type index
  94. function AddBloodType takes string fx, string attachpoint returns integer
  95.     return BloodType.Add(fx, attachpoint)
  96. endfunction
  97. //* 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. endfunction
  101. //* 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. endfunction
  105. //* End public functions
  106.  
  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. endfunction
  118. endlibrary

Usage example for custom blood types:

Code: jass
  1. scope TestingTime initializer init
  2.  
  3. globals
  4.     private integer BLOOD_TYPE_NAGA // this global variable will store the index of this type of blood
  5. endglobals
  6. //===========================================================================
  7. private function init takes nothing returns nothing
  8.     //* Creates a custom blood type, in this case one for nagas
  9.     set BLOOD_TYPE_NAGA = AddBloodType("Objects\\Spawnmodels\\Demon\\DemonBlood\\DemonBloodPitlord.mdl", "origin")
  10.     call SetUnitTypeBlood('nwgs', BLOOD_TYPE_NAGA)
  11.     call SetUnitTypeBlood('nnmg', BLOOD_TYPE_NAGA)
  12.     call SetUnitTypeBlood('nnsw', BLOOD_TYPE_NAGA)
  13.     call SetUnitTypeBlood('nsnp', BLOOD_TYPE_NAGA)
  14.     call SetUnitTypeBlood('nmyr', BLOOD_TYPE_NAGA)
  15.     call SetUnitTypeBlood('nnrg', BLOOD_TYPE_NAGA)
  16.     call SetUnitTypeBlood('nhyc', BLOOD_TYPE_NAGA)
  17.     call SetUnitTypeBlood('nmpe', BLOOD_TYPE_NAGA)
  18.     call SetUnitTypeBlood('Hvsh', BLOOD_TYPE_NAGA)
  19. endfunction
  20.  
  21. 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.
« Last Edit: December 21, 2017, 10:16:45 AM by moyack »



 

Vivir aprendiendo.co - A place for learning stuff, in Spanish   Chaos Realm - The world of Game modders and wc3 addicts   Diplo, a gaming community   Power of Corruption, an altered melee featuring Naga and Demon. Play it now!!!   WC3JASS.com - The JASS Vault + vJASS and Zinc   Jetcraft - A Starcraft II mod   WormTastic Clan (wTc)   Warcraft RESOURCES Reforged: Modelos, mapas, proyectos y mas...