• 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.

[JASS] Help Customizing a Damage Detection

Status
Not open for further replies.
Level 4
Joined
Aug 17, 2007
Messages
36
I've been looking forever for a damage detection system for a generic unit and found a guide here at:

http://www.hiveworkshop.com/forums/showthread.php?t=33123

My problem is, I've never really tried jass before. It's one of those things that I just never had enough time to learn. So I need help converting the final code he displayed in the tutorial to my own trigger. I would like it to do the following functions, as well as make it so only units who attack Player 12 will be effected by this trigger.

JASS:
    call AdjustPlayerStateBJ( ( R2I([B]GetEventDamage[/B]()) / 5 ), GetOwningPlayer(GetAttacker()), PLAYER_STATE_RESOURCE_GOLD )
    call CreateTextTagUnitBJ( ( "+" + I2S(( R2I([B]GetEventDamage[/B]()) / 5 )) ), GetAttacker(), 0, 10, 100, 100, 0.00, 0 )
    call ShowTextTagForceBJ( false, GetLastCreatedTextTag(), GetPlayersAll() )
    call ShowTextTagForceBJ( true, GetLastCreatedTextTag(), GetPlayersMatching(Condition(function Trig_Bounty_Func005003001)) )
    call SetTextTagPermanentBJ( GetLastCreatedTextTag(), false )
    call SetTextTagLifespanBJ( GetLastCreatedTextTag(), 0.50 )

The GetEventDamage would be however much damage is taken away. I'm guessing my trigger would look something like this, but I'm not sure. Anyone with jass experience, please help as I'm at a loss when it comes to this stuff.

JASS:
function AttackTrigger_Conditions takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetAttackedUnitBJ()) == Player(11) ) ) then
return false
    endif
    return true
endfunction

function Trig_AttackTrigger_Func005003001 takes nothing returns boolean
    return ( GetOwningPlayer(GetAttacker()) == GetFilterPlayer() )
endfunction

function AttackTrigger_Conditions takes nothing returns boolean
    return GetHandleTrigger(GetAttacker(), "DamageTrig") == null and GetUnitAbilityLevel(GetAttacker(), 'A000') > 0
endfunction

function DamageTrigger_Conditions takes nothing returns boolean
    return GetEventDamageSource() == GetHandleUnit(GetTriggeringTrigger(), "Attacker")
endfunction

function DamageTrigger_Actions takes nothing returns nothing
    local unit AttackedUnit = GetTriggerUnit()
local unit AttackingUnit = GetEventDamageSource()
    local trigger DamageTrigger = GetTriggeringTrigger()
    call FlushHandleLocals(DamageTrigger)
    call DestroyTrigger(DamageTrigger)
    call SetHandleHandle(AttackingUnit, "DamageTrig", null)
    //Here come the actions you want originally with the attacked/attacking unit.
    call AdjustPlayerStateBJ( ( R2I(GetEventDamage()) / 5 ), GetOwningPlayer(GetAttacker()), PLAYER_STATE_RESOURCE_GOLD )
    call CreateTextTagUnitBJ( ( "+" + I2S(( R2I(GetEventDamage()) / 5 )) ), GetAttacker(), 0, 10, 100, 100, 0.00, 0 )
    call ShowTextTagForceBJ( false, GetLastCreatedTextTag(), GetPlayersAll() )
    call ShowTextTagForceBJ( true, GetLastCreatedTextTag(), GetPlayersMatching(Condition(function Trig_AttackTrigger005003001)) )
    call SetTextTagPermanentBJ( GetLastCreatedTextTag(), false )
    call SetTextTagLifespanBJ( GetLastCreatedTextTag(), 0.50 )
    set DamageTrigger = null
    set AttackingUnit = null
    set AttackedUnit = null
endfunction

function AttackTrigger_Actions takes nothing returns nothing
    local unit AttackingUnit = GetAttacker() //We store the attacking unit
    local unit AttackedUnit = GetTriggerUnit() //We store the attacked unit - this one will take the damage
    local trigger DamageTrigger = CreateTrigger() //We create the damage trigger
    call SetHandleHandle(AttackingUnit, "DamageTrig", DamageTrigger)
    call SetHandleHandle(DamageTrigger, "Attacker", AttackingUnit)
call TriggerRegisterUnitEvent(DamageTrigger, AttackedUnit, EVENT_UNIT_DAMAGED)
    call TriggerAddCondition(DamageTrigger, Condition(function DamageTrigger_Conditions))
    call TriggerAddAction(DamageTrigger, function DamageTrigger_Actions)
    call TriggerSleepAction( ( ( ( ( 0.50 - 0.10 ) / ( 10.00 - 70.00 ) ) * I2R(GetHeroStatBJ(bj_HEROSTAT_AGI, GetAttacker(), true)) ) + ( 0.50 - ( ( ( 0.50 - 0.10 ) / ( 10.00 - 70.00 ) ) * 10.00 ) ) ) )
    call FlushHandleLocals(DamageTrigger)
    call DestroyTrigger(DamageTrigger)
    call SetHandleHandle(AttackingUnit, "DamageTrig", null)
    set DamageTrigger = null
    set AttackingUnit = null
    set AttackingUnit = null
endfunction

function InitTrig_AttackDamageDetection takes nothing returns nothing
    local trigger AttackTrigger = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(AttackTrigger, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(AttackTrigger, Condition( function AttackTrigger_Conditions))
    call TriggerAddAction(AttackTrigger, function AttackTrigger_Actions)
    set AttackTrigger = null
endfunction


JASS:
function AttackTrigger_Conditions takes nothing returns boolean
    if ( not ( GetOwningPlayer(GetAttackedUnitBJ()) == Player(11) ) ) then
        return false
    endif
    return true
endfunction




function AttackTrigger_Conditions takes nothing returns boolean
    return GetHandleTrigger(GetAttacker(), "DamageTrig") == null and GetUnitAbilityLevel(GetAttacker(), 'A000') > 0
endfunction

function DamageTrigger_Conditions takes nothing returns boolean
    return GetEventDamageSource() == GetHandleUnit(GetTriggeringTrigger(), "Attacker")
endfunction

function DamageTrigger_Actions takes nothing returns nothing
    local unit AttackedUnit = GetTriggerUnit()
local unit AttackingUnit = GetEventDamageSource()
    local trigger DamageTrigger = GetTriggeringTrigger()
    call FlushHandleLocals(DamageTrigger)
    call DestroyTrigger(DamageTrigger)
    call SetHandleHandle(AttackingUnit, "DamageTrig", null)
    //Here come the actions you want originally with the attacked/attacking unit.
    call UnitDamageTarget(AttackingUnit, AttackedUnit, GetEventDamage(), true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL, null)
    set DamageTrigger = null
    set AttackingUnit = null
    set AttackedUnit = null
endfunction

function AttackTrigger_Actions takes nothing returns nothing
    local unit AttackingUnit = GetAttacker() //We store the attacking unit
    local unit AttackedUnit = GetTriggerUnit() //We store the attacked unit - this one will take the damage
    local trigger DamageTrigger = CreateTrigger() //We create the damage trigger
    call SetHandleHandle(AttackingUnit, "DamageTrig", DamageTrigger)
    call SetHandleHandle(DamageTrigger, "Attacker", AttackingUnit)
call TriggerRegisterUnitEvent(DamageTrigger, AttackedUnit, EVENT_UNIT_DAMAGED)
    call TriggerAddCondition(DamageTrigger, Condition(function DamageTrigger_Conditions))
    call TriggerAddAction(DamageTrigger, function DamageTrigger_Actions)





    call AdjustPlayerStateBJ( ( R2I(GetEventDamage()) / 5 ), GetOwningPlayer(GetAttacker()), PLAYER_STATE_RESOURCE_GOLD )
    call CreateTextTagUnitBJ( ( "+" + I2S(( R2I(GetEventDamage()) / 5 )) ), GetAttacker(), 0, 10, 100, 100, 0.00, 0 )
    call ShowTextTagForceBJ( false, GetLastCreatedTextTag(), GetPlayersAll() )
    call ShowTextTagForceBJ( true, GetLastCreatedTextTag(), GetPlayersMatching(Condition(function Trig_AttackTrigger005003001)) )
    call SetTextTagPermanentBJ( GetLastCreatedTextTag(), false )
    call SetTextTagLifespanBJ( GetLastCreatedTextTag(), 0.50 )





    call TriggerSleepAction( ( ( ( ( 0.50 - 0.10 ) / ( 10.00 - 70.00 ) ) * I2R(GetHeroStatBJ(bj_HEROSTAT_AGI, GetAttacker(), true)) ) + ( 0.50 - ( ( ( 0.50 - 0.10 ) / ( 10.00 - 70.00 ) ) * 10.00 ) ) ) )
    call FlushHandleLocals(DamageTrigger)
    call DestroyTrigger(DamageTrigger)
    call SetHandleHandle(AttackingUnit, "DamageTrig", null)
    set DamageTrigger = null
    set AttackingUnit = null
    set AttackingUnit = null
endfunction

function InitTrig_AttackDamageDetection takes nothing returns nothing
    local trigger AttackTrigger = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(AttackTrigger, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(AttackTrigger, Condition( function AttackTrigger_Conditions))
    call TriggerAddAction(AttackTrigger, function AttackTrigger_Actions)
    set AttackTrigger = null
endfunction

Any help would be appreciated.

Thanks for taking the time to read my problem!

[EDIT: I updated the trigger. The old trigger is in the spoiler box and the new trigger is shown.
 
Last edited:
Level 4
Joined
Aug 17, 2007
Messages
36
JASS:
1function AttackTrigger_Conditions takes nothing returns boolean
2    if ( not ( GetOwningPlayer(GetAttackedUnitBJ()) == Player(11) ) ) then
3return false
4    endif
5    return true
6endfunction
7
8function Trig_AttackTrigger_Func005003001 takes nothing returns boolean
9    return ( GetOwningPlayer(GetAttacker()) == GetFilterPlayer() )
10endfunction
11
12function AttackTrigger_Conditions takes nothing returns boolean
13    return GetHandleTrigger(GetAttacker(), "DamageTrig") == null and GetUnitAbilityLevel(GetAttacker(), 'A000') > 0
14endfunction
15
16function DamageTrigger_Conditions takes nothing returns boolean
17    return GetEventDamageSource() == GetHandleUnit(GetTriggeringTrigger(), "Attacker")
18endfunction
19
20function DamageTrigger_Actions takes nothing returns nothing
21    local unit AttackedUnit = GetTriggerUnit()
22local unit AttackingUnit = GetEventDamageSource()
23    local trigger DamageTrigger = GetTriggeringTrigger()
24    call FlushHandleLocals(DamageTrigger)
25    call DestroyTrigger(DamageTrigger)
26    call SetHandleHandle(AttackingUnit, "DamageTrig", null)
27    //Here come the actions you want originally with the attacked/attacking unit.
28    call AdjustPlayerStateBJ( ( R2I(GetEventDamage()) / 5 ), GetOwningPlayer(GetAttacker()), PLAYER_STATE_RESOURCE_GOLD )
29    call CreateTextTagUnitBJ( ( "+" + I2S(( R2I(GetEventDamage()) / 5 )) ), GetAttacker(), 0, 10, 100, 100, 0.00, 0 )
30    call ShowTextTagForceBJ( false, GetLastCreatedTextTag(), GetPlayersAll() )
31    call ShowTextTagForceBJ( true, GetLastCreatedTextTag(), GetPlayersMatching(Condition(function Trig_AttackTrigger005003001)) )
32    call SetTextTagPermanentBJ( GetLastCreatedTextTag(), false )
33    call SetTextTagLifespanBJ( GetLastCreatedTextTag(), 0.50 )
34    set DamageTrigger = null
35    set AttackingUnit = null
35    set AttackedUnit = null
36endfunction
37
38function AttackTrigger_Actions takes nothing returns nothing
39    local unit AttackingUnit = GetAttacker() //We store the attacking unit
40    local unit AttackedUnit = GetTriggerUnit() //We store the attacked unit - this one will take the damage
41    local trigger DamageTrigger = CreateTrigger() //We create the damage trigger
42    call SetHandleHandle(AttackingUnit, "DamageTrig", DamageTrigger)
43    call SetHandleHandle(DamageTrigger, "Attacker", AttackingUnit)
44call TriggerRegisterUnitEvent(DamageTrigger, AttackedUnit, EVENT_UNIT_DAMAGED)
45    call TriggerAddCondition(DamageTrigger, Condition(function DamageTrigger_Conditions))
46    call TriggerAddAction(DamageTrigger, function DamageTrigger_Actions)
47    call TriggerSleepAction( ( ( ( ( 0.50 - 0.10 ) / ( 10.00 - 70.00 ) ) * I2R(GetHeroStatBJ(bj_HEROSTAT_AGI, GetAttacker(), true)) ) + ( 0.50 - ( ( ( 0.50 - 0.10 ) / ( 10.00 - 70.00 ) ) * 10.00 ) ) ) )
48    call FlushHandleLocals(DamageTrigger)
49    call DestroyTrigger(DamageTrigger)
50    call SetHandleHandle(AttackingUnit, "DamageTrig", null)
51    set DamageTrigger = null
52    set AttackingUnit = null
53    set AttackingUnit = null
54endfunction
55
56function InitTrig_AttackDamageDetection takes nothing returns nothing
57    local trigger AttackTrigger = CreateTrigger()
58    call TriggerRegisterAnyUnitEventBJ(AttackTrigger, EVENT_PLAYER_UNIT_ATTACKED)
59    call TriggerAddCondition(AttackTrigger, Condition( function AttackTrigger_Conditions))
60    call TriggerAddAction(AttackTrigger, function AttackTrigger_Actions)
61    set AttackTrigger = null
62endfunction

So, I tested the trigger out in JassCraft and get the following errors. Any help?

Line 12: Symbol AttackTrigger_Conditions multiply defined
Line 13: Undeclared function GetHandleTrigger
Line 17: Undeclared function GetHandleUnit
Line 24: Undeclared function FlushHandleLocals
Line 26: Undeclared function SetHandleHandle
Line 31: Undefined function.
Line 43: Undeclared function SetHandleHandle
Line 44: Undeclared function SetHandleHandle
Line 49: Undeclared function FlushHandleLocals
Line 51: Undeclared function SetHandleHandle
 
Level 17
Joined
Apr 13, 2008
Messages
1,608
Okay, I haven't used JassCraft much but as far as I know it doesn't have a vJass syntax checker. JassCraft doesn't know about Kattana's HandleVars.
Download NewGenPack. Every Warcraft3 map maker should use NewGen anyways.
Player 12 is Player(11) in JASS, since in programming languages we index from 0.

I've just glimpsed through the code and I must say that it's written very inefficiently.
The thing you want to achieve could be achieved by around 10-12 lines of JASS, you don't even need HandleVars or anything complex. I would do it for you but a lesser storm is coming this way and I don't want to let a thunder fry my computer.
 
Level 4
Joined
Aug 17, 2007
Messages
36
Thanks for the info--NewGen is quite helpful; I don't know how I ever lived without it.

As for the trigger, it compiles but doesn't work. I just copied the damage detection engine trigger posted in the tutorial section and tried to add my own flare to it; however, I do have a version of this trigger coded in GUI that has slight bugs.

The one thing that would fix the bugs is if I had a way to determine how much damage was taken away within the trigger itself. I've tried using

call TriggerRegisterPlayerUnitEventSimple( gg_trg_Bounty2, Player(11), EVENT_PLAYER_UNIT_ATTACKED )

as the event and

GetEventDamage()

within the trigger itself, but it doesn't work. Any ideas? Is there a generic unit event such as EVENT_PLAYER_UNIT_DAMAGED or would I have to do it some other way?
 
Status
Not open for further replies.
Top