HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Function "mixing" possible?

06-04-2004, 05:16 PM#1
xGT4x
I need the stuff of 'A unit takes damage(WEU)' and 'A unit is attacked' mixed. What I want:
Activates when the unit takes damage.
Attacking unit
Attacked unit
Damage taken

Is that somehow possible with Jass? I tried but nothing worked...
Sry that I actually don't have the Jass names, forgot some...
06-04-2004, 06:19 PM#2
The Gearhead
Just add more events to your trigger.

You can have more than one.
06-04-2004, 07:55 PM#3
PitzerMike
I doubt it's possible. GetAttacker doesn't work for the damage event and DamageTaken doesn't work for the Attack event.

There might be workarounds but I can't think of anything right now.
06-04-2004, 09:00 PM#4
Vexorian
There is one crappy but most of the times effective workaround.

You have 2 triggers, one with the is attacked event and the other one with the takes damage (or you can have both of them in the same function and check EventIds )

In the fis attacked one you add the attacking unit to a group Handle Variable of the attacked unit

then in the damaged trigger you pick FirstOfGroup() of the group handle var, use it as the damaging unit, and then remove that unit from the group.

Anyways This spell kind of explains that well in a more graphic way
06-05-2004, 11:30 AM#5
xGT4x
Lol I know that spell, look who wrote the comments, I registered there when WC3Sear.ch wasn't the DL section of WC3Campaigns so I got a different name...But all accounts with GT4 in it are mine normally...
But I think that doesn't work always, example:
1.Unit A shoots
2.Unit B Shoots
3.Unit B Arrow hits first

I think then Unit A would be the first in the group...
06-05-2004, 06:24 PM#6
KaTTaNa
If you knew the projectile speed and backswing of the attacking unit, you could calculate when it will hit, and thereby the order in which the units will deal thier damage.
That seems almost impossible, but if you manage to create a good formula to calculate the time it should work.
06-06-2004, 10:39 AM#7
xGT4x
Backswing isn't needed, but the other one is needed(forogt name), backswing is after arrow is shooten...
06-07-2004, 09:58 PM#8
-={tWiStÄr}=-
Quote:
Originally Posted by KaTTaNa
If you knew the projectile speed and backswing of the attacking unit, you could calculate when it will hit, and thereby the order in which the units will deal thier damage.
That seems almost impossible, but if you manage to create a good formula to calculate the time it should work.
Ive got this, the formula is D/S=T where D = distance S = speed and T = time
the jass function is...
Code:
call TriggerSleepAction(GetDistanceBetweenTwoPoints{forgetactualfunction}(GetUnitLoc(GetAttackedUnit()), GetUnitLoc(GetAttackingUnit() \ {projectile speed})
its a little bit off but looks pretty good in game. If you take into acount some other attack stats like i guess backswing, animation time etc. you could get it practictly perfect.
06-08-2004, 11:56 AM#9
xGT4x
Very funny, 1. I knew that already and 2. that's useless for me because I can't get the units stats needed...
06-09-2004, 12:25 AM#10
Narwanza
There is one workaround that is much more simple than all of you are suggesting. In one trigger you have the unit is attacked event. Have whatever conditions you want. Then in the actions you add an event to another trigger using the unit - specific unit event. You may wonder why this is different, but with this you are able to use event responses like attacked unit takes damage. Since Warcraft tallies damage after the attack then you can set a variable equal to the damage taken in the trigger that you added the event to. A word of caution though, have a boolean that you set to true the first time you add the event or else you will have tons of events.
Code:
if (udg_myBool == false) then
    set udg_myBool = true
    call Trig.........
endif
06-09-2004, 12:16 PM#11
xGT4x
Hmm but there's a problem, I need varaibles which save the datas I want, but its problematic, I need a local varaible that works for both triggers, the one with attacked and the one with takes damage...
06-09-2004, 04:29 PM#12
Narwanza
Use the gamecache.
06-09-2004, 08:32 PM#13
KaTTaNa
Try something like this, I havn't tested it and I don't know if it compiles, but it might work if GetTick() works and the time formula works too.

Code:
function GetTick takes nothing returns integer
    return R2I(GetTimeOfDay()*GetTimeOfDayScale())
endfunction

function GetProjectileSpeed takes unit u returns real
    return 1000 // Hmm...
endfunction
function GetDistance takes unit A, unit B returns real
    local real x = GetUnitX(A)-GetUnitX(B)
    local real y = GetUnitY(A)-GetUnitY(B)
    return SquareRoot(x*x+y*y)
endfunction

function Handle2Int takes handle h returns integer
    return h
    return 0
endfunction
function Int2Unit takes integer i returns unit
    return u
    return 0
endfunction

function TerminateTrigger takes nothing returns nothing
    // Clean up
    call FlushStoredInteger(InitGameCache("jass_attackers.w3v"), "attacker"+I2S(Handle2Int(GetTriggeringTrigger())), "attacker")
    call FlushStoredInteger(InitGameCache("jass_attackers.w3v"), "attacker"+I2S(Handle2Int(GetTriggeringTrigger())), "time")
    call DestroyTrigger(GetTriggeringTrigger())
endfunction

function UnitDamagedCheckAttacker takes nothing returns boolean
    local gamecache gm = InitGameCache("jass_attackers.w3v")
    local integer time = GetStoredInteger(gm, "attacker"+I2S(Handle2Int(GetTriggeringTrigger())), "time")
    set gm = null
    if ( time < GetTick()) then
        call TerminateTrigger() // Hopefully this will never get run, but just to be sure it wont leak
    elseif ( time == GetTick()) then
        return true
    endif
    return false
endfunction

// Run in the Unit is Attacked event trigger
// set dmgCode to the code to be run when it gets damaged
function UnitAttacked takes unit attacker, unit target, code dmgCode returns nothing
    local gamecache gm = InitGameCache("jass_attackers.w3v")
    local trigger trg = CreateTrigger()
    local integer time = GetTick() + R2I(GetDistance(attacker, target)/GetProjectileSpeed(attacker))
    
    call TriggerRegisterUnitEvent(trg, target, EVENT_UNIT_DAMAGED)
    call TriggerAddCondition(trg, Condition(function UnitDamagedCheckAttacker))
    call TriggerAddAction(trg, dmgCode)
    call TriggerAddAction(trg, function TerminateTrigger)
    call StoreInteger(gm, "attacker" + I2S(Handle2Int(trg)), "time", time)
    call StoreInteger(gm, "attacker" + I2S(Handle2Int(trg)), "attacker", Handle2Int(attacker))
    
    set trg = null
    set gm = null
endfunction

// Call to get the damaging unit (maybe...)
function GetDamagingUnit takes nothing returns unit
    return Int2Unit(GetStoredInteger(InitGameCache("jass_attackers.w3v"), "attacker"+I2S(Handle2Int(GetTriggeringTrigger())), "attacker"))
endfunction
06-10-2004, 03:54 AM#14
Narwanza
Much to complicated and mine works fine.
06-10-2004, 06:54 AM#15
KaTTaNa
But how are you going to deal with this problem?
Quote:
Originally Posted by XIID.GT4
1.Unit A shoots
2.Unit B Shoots
3.Unit B Arrow hits first