• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Taking Damage

Status
Not open for further replies.
Level 10
Joined
Jan 21, 2007
Messages
576
I need to know if there is a way to tell how much damage is taken when a unit (set by a variable) takes damage. It would work if i did this:
~Unit~ takes Damage
Set [Variable]DamageTaken to - Damage Taken.
BUT thats under specific unit, as in it has to be there when the game starts and cant be a variable unit, any way to do this? Jass maybe?
 
JASS:
function AnyUnitTakesDamage takes nothing returns nothing
// your actions here
// Sample Damage display:
// call BJDebugMsg( "Damage: " + R2S(GetEventDamage()) )
endfunction
// part 1
function AddDamageTriggers takes nothing returns nothing
local trigger takedamage = CreateTrigger()
call TriggerRegisterUnitEvent(takedamage,GetTriggerUnit(),EVENT_UNIT_DAMAGED)
call AttachObject(takedamage,"action",TriggerAddAction(takedamage,function AnyUnitTakesDamage))
call AttachObject(GetTriggerUnit(),"TakeDamageTrigger",takedamage)
endfunction
// part 2
function RemoveDamageTriggers takes nothing returns nothing
local unit u = GetTriggerUnit()
local trigger me = GetAttachedTrigger(GetTriggerUnit(),"TakeDamageTrigger")
local string t = GetAttachmentTable(me)
local boolean revived = false
if not IsUnitType(u,UNIT_TYPE_HERO) then
loop
set revived = (GetWidgetLife(u)>0.405)
exitwhen revived or GetUnitTypeId(u)==0
call TriggerSleepAction(0)
endloop
endif
if not revived then
// delete action and trigger
call TriggerRemoveAction(me,GetTableTriggerAction(t,"action"))
call DestroyTable(t)
call DestroyTrigger(me)
endif
set me = null
set u = null
endfunction
// part 3
function InitTrig_AddDmg takes nothing returns nothing
local trigger entermap = CreateTrigger()
local group startingunits = CreateGroup()
local unit u
local trigger takedamage
local trigger upondeath = CreateTrigger()
call GroupEnumUnitsInRect(startingunits,bj_mapInitialPlayableArea,null)
loop
set u = FirstOfGroup(startingunits)
exitwhen u == null
set takedamage = CreateTrigger()
call TriggerRegisterUnitEvent(takedamage,u,EVENT_UNIT_DAMAGED)
call AttachObject(takedamage,"action",TriggerAddAction(takedamage,function AnyUnitTakesDamage))
call AttachObject(u,"TakeDamageTrigger",takedamage)
call GroupRemoveUnit(startingunits,u)
endloop
set takedamage = null
// unit enters the map/revives
call TriggerRegisterAnyUnitEventBJ(entermap ,EVENT_PLAYER_HERO_REVIVE_FINISH)
call TriggerRegisterEnterRectSimple(entermap, bj_mapInitialPlayableArea)
call TriggerAddAction(entermap,function AddDamageTriggers)
// unit dies
call TriggerRegisterAnyUnitEventBJ(upondeath,EVENT_PLAYER_UNIT_DEATH)
call TriggerAddAction(upondeath,function RemoveDamageTriggers)
endfunction
from http://www.wc3jass.com/viewtopic.php?t=2608 this one destroys a trigger after a unit is dead.
 
Level 10
Joined
Jan 21, 2007
Messages
576
I have this code

JASS:
function AnyUnitTakesDamage takes nothing returns nothing
call TriggerExecute(gg_trg_Hinder_Effect)
// Sample Damage display:
// call BJDebugMsg( "Damage: " + R2S(GetEventDamage()) )
endfunction
// part 1
function AddDamageTriggers takes nothing returns nothing
local trigger takedamage = CreateTrigger()
call TriggerRegisterUnitEvent(takedamage,GetTriggerUnit(),EVENT_UNIT_DAMAGED)
call AttachObject(takedamage,"action",TriggerAddAction(takedamage,function AnyUnitTakesDamage))
call AttachObject(GetTriggerUnit(),"TakeDamageTrigger",takedamage)
endfunction
// part 2
function RemoveDamageTriggers takes nothing returns nothing
local unit u = GetTriggerUnit()
local trigger me = GetAttachedTrigger(GetTriggerUnit(),"TakeDamageTrigger")
local string t = GetAttachmentTable(me)
local boolean revived = false
if not IsUnitType(u,UNIT_TYPE_HERO) then
loop
set revived = (GetWidgetLife(u)>0.405)
exitwhen revived or GetUnitTypeId(u)==0
call TriggerSleepAction(0)
endloop
endif
if not revived then
// delete action and trigger
call TriggerRemoveAction(me,GetTableTriggerAction(t,"action"))
call DestroyTable(t)
call DestroyTrigger(me)
endif
set me = null
set u = null
endfunction
// part 3
function InitTrig_AddDmg takes nothing returns nothing
local trigger entermap = CreateTrigger()
local group startingunits = CreateGroup()
local unit u
local trigger takedamage
local trigger upondeath = CreateTrigger()
call GroupEnumUnitsInRect(startingunits,bj_mapInitialPlayableArea,null)
loop
set u = FirstOfGroup(startingunits)
exitwhen u == null
set takedamage = CreateTrigger()
call TriggerRegisterUnitEvent(takedamage,u,EVENT_UNIT_DAMAGED)
call AttachObject(takedamage,"action",TriggerAddAction(takedamage,function AnyUnitTakesDamage))
call AttachObject(u,"TakeDamageTrigger",takedamage)
call GroupRemoveUnit(startingunits,u)
endloop
set takedamage = null
// unit enters the map/revives
call TriggerRegisterAnyUnitEventBJ(entermap ,EVENT_PLAYER_HERO_REVIVE_FINISH)
call TriggerRegisterEnterRectSimple(entermap, bj_mapInitialPlayableArea)
call TriggerAddAction(entermap,function AddDamageTriggers)
// unit dies
call TriggerRegisterAnyUnitEventBJ(upondeath,EVENT_PLAYER_UNIT_DEATH)
call TriggerAddAction(upondeath,function RemoveDamageTriggers)
endfunction

And it diables it do to errors such as, expecting function name, expected expression, expected variable. I have VERY minimul jass knowledge and frankly, dont know whats wrong so if you could fix it....
 
To implement, place the CS Cache script under the map header in the trigger editor. after that, create a new trigger called AddDmg, convert it to JASS, and replace the script with the damage take script.
How to use it:
look at the top of the take damage script.
JASS:
function AnyUnitTakesDamage takes nothing returns nothing
call TriggerExecute(gg_trg_Hinder_Effect)
// Sample Damage display:
// call BJDebugMsg( "Damage: " + R2S(GetEventDamage()) )
endfunction
This runs the trigger called Hinder Effect, whenever a unit takes damage
what you can do would be making a new trigger called Hinder Effect.
  • Events
  • Conditions
  • Actions
  • //add actions here.
The trigger above will run whenever a unit takes damage.

Hope this solves your problem.
 
Last edited:
Level 10
Joined
Jan 21, 2007
Messages
576
Thanks your awsome!
EDIT: is there a way in

JASS:
function AnyUnitTakesDamage takes nothing returns nothing
call TriggerExecute(gg_trg_Hinder_Effect)
// Sample Damage display:
// call BJDebugMsg( "Damage: " + R2S(GetEventDamage()) )
endfunction

To check if the unit that took damage is the unit i have set as (unit variable) Caster_Hinder?

EDIT2: And i copy and pasted CScache and when i enable it (or save map) it disables it and gives me expected end of line error and expected a name (see attachment for pic of error).
 

Attachments

  • Error.JPG
    Error.JPG
    49.8 KB · Views: 143
to check if the unit who took damage is your "variable unit" do this
  • Actions
  • If - (DamagedUnit is <variableUnit>
  • then
  • //actions here for the Var unit
  • else
  • //else actions.
EDIT2: And i copy and pasted CScache and when i enable it (or save map) it disables it and gives me expected end of line error and expected a name (see attachment for pic of error).
Hard to say what's wrong, WE's normal syntax checker sucks..
try placing the CSCache script in the map header or post it here for us to see what's wrong.
 
Level 10
Joined
Jan 21, 2007
Messages
576
Here it is, attached in text doc due to its length.
 

Attachments

  • CSCache.txt
    72.3 KB · Views: 114
ah...you are using the newest CSCache which uses grimoire, jasshelper, etc. Well, then you first of all need to download JassNewGenPack or WE Helper from wc3c for it to work.
by the way, i think i found the bug in the script
JASS:
function Trig_CSCache_Actions takes nothing returns nothing
endfunction
//===========================================================================
function InitTrig_CSCache takes nothing returns nothing
set gg_trg_CSCache = CreateTrigger( )
call TriggerAddAction( gg_trg_CSCache, function Trig_CSCache_Actions )
endfunction
library CSCache initializer InitCSCache
//***************************************************************************
//* *
//* CSCache 14.3 [url]http://wc3campaigns.net/vexorian[/url] *
//* ¯¯¯¯¯¯¯ *
//* From attach variables to Dynamic Arrays, not forgetting the tables, *
//* CSData and the Pools, this is a pack of storage options *
//* *
//***************************************************************************
no need for the upper part, so if you cut some of it away, it will look like this:
JASS:
library CSCache initializer InitCSCache
//***************************************************************************
//* *
//* CSCache 14.3 [url]http://wc3campaigns.net/vexorian[/url] *
//* ¯¯¯¯¯¯¯ *
//* From attach variables to Dynamic Arrays, not forgetting the tables, *
//* CSData and the Pools, this is a pack of storage options *
//* *
//***************************************************************************
 
Level 10
Joined
Jan 21, 2007
Messages
576
You have been a insane help, and have stayed here to help me for quite awhile. As you can see i have only 2 rep so i cant rep you. But i feel that you should get repped because not a lot of people would have put up with question for so long that your probably think are trvial and blow throw like pie every day. So im gonna see i can request a admin or what' not to rep you.
 
Level 10
Joined
Jan 21, 2007
Messages
576
Dr super good you misssunderstood i ment "So im gonna see i can request a admin or whatnot, to rep you."
 
Status
Not open for further replies.
Top