HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Attack function help

03-23-2006, 04:53 AM#1
Linera
I'm working on a custom attack system.
For the most part it works but some things like animation and unit dying and stuff isn't working just right.

Here is the code:
Collapse JASS:
function Trig_Untitled_Trigger_001_Func001Func004A takes nothing returns nothing
    call RemoveUnit( GetEnumUnit() )
endfunction

function Trig_Untitled_Trigger_001_Func001Func009A takes nothing returns nothing
    call RemoveUnit( GetEnumUnit() )
endfunction

function attacks takes integer p, unit AttackingUnit, unit AttackedUnit returns nothing
    if GetPlayerController(GetOwningPlayer(AttackingUnit)) == MAP_CONTROL_USER then
        loop
         exitwhen udg_Moves[p] == true
        call PolledWait(udg_Main_Attack_Speed[p])
        call StartTimerBJ( udg_CombatCheckTimer[GetConvertedPlayerId(GetOwningPlayer(AttackingUnit))], false, 3.00 )
        set udg_InCombat[GetConvertedPlayerId(GetOwningPlayer(AttackingUnit))] = true
        call IssueTargetOrderBJ( AttackedUnit, "banish", AttackingUnit )
        call SetUnitAnimation(AttackedUnit, "Attack" )
        call UnitDamageTargetBJ( AttackingUnit, AttackedUnit, 5.00, ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL )
        call PolledWait(0.50)
        call SetUnitAnimation(AttackedUnit, "Stand" )
        call ForGroupBJ( GetUnitsOfPlayerAndTypeId(ConvertedPlayer(GetConvertedPlayerId(GetOwningPlayer(AttackingUnit))), 'o001'), function Trig_Untitled_Trigger_001_Func001Func009A )
        endloop
    else
        loop
         exitwhen udg_Moves[p] == true
        call PolledWait(2.00)
        call StartTimerBJ( udg_CombatCheckTimer[GetConvertedPlayerId(GetOwningPlayer(AttackedUnit))], false, 3.00 )
        set udg_InCombat[GetConvertedPlayerId(GetOwningPlayer(AttackedUnit))] = true
        call SetUnitAnimation(AttackedUnit, "Attack" )
        call UnitDamageTargetBJ( AttackingUnit, AttackedUnit, 5.00, ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL )
        call PolledWait(0.50)
        call SetUnitAnimation(AttackedUnit, "Stand" )
        call ForGroupBJ( GetUnitsOfPlayerAndTypeId(ConvertedPlayer(GetConvertedPlayerId(GetOwningPlayer(AttackedUnit))), 'o001'), function Trig_Untitled_Trigger_001_Func001Func004A )
        endloop
    endif
set udg_Moves[p] = false
endfunction
03-23-2006, 03:59 PM#2
phyrex1an
You can use SetUnitAnimation on units that are dead, so if a unit dies of the UnitDamageTargetBJ, 0.5 sec after that you will set its animation to "stand".

Simply add a check if the unit is dead before you set the animation.
03-23-2006, 05:58 PM#3
Linera
I had killed a unit and that dying unit continued to attack me as he faded away.

Here is my new code, sadly its still not working right.
When unit dies death animation is not instant and enemy unit is playing attack animation but my hero is. I want this to be as smooth just like the attack thats built in. Reason I need my own attack system done by triggers is cause I'm using a special formula to figure out damage and also I need to trigger dodge, parry and crit into it as certain spells can only be cast after certain events like dodge.

Collapse JASS:
function Trig_Untitled_Trigger_001_Func001Func004A takes nothing returns nothing
    call RemoveUnit( GetEnumUnit() )
endfunction

function Trig_Untitled_Trigger_001_Func001Func009A takes nothing returns nothing
    call RemoveUnit( GetEnumUnit() )
endfunction

function attacks takes integer p, unit AttackingUnit, unit AttackedUnit returns nothing
    if GetPlayerController(GetOwningPlayer(AttackingUnit)) == MAP_CONTROL_USER then
        loop
          if GetUnitStateSwap(UNIT_STATE_LIFE, AttackedUnit) == 0.00 then
          call IssueImmediateOrderBJ(AttackingUnit, "stop" )
          call IssueImmediateOrderBJ(AttackedUnit, "death" )
          set udg_Moves[p] = true
          endif
          if GetUnitStateSwap(UNIT_STATE_LIFE, AttackingUnit) == 0.00 then
          call IssueImmediateOrderBJ(AttackingUnit, "death" )
          call IssueImmediateOrderBJ(AttackedUnit, "stop" )
          set udg_Moves[p] = true
          endif
         exitwhen udg_Moves[p] == true
        call StartTimerBJ( udg_CombatCheckTimer[GetConvertedPlayerId(GetOwningPlayer(AttackingUnit))], false, 3.00 )
        set udg_InCombat[GetConvertedPlayerId(GetOwningPlayer(AttackingUnit))] = true
        call IssueTargetOrderBJ( AttackedUnit, "banish", AttackingUnit )
        call SetUnitAnimation(AttackedUnit, "Attack" )
        call UnitDamageTargetBJ( AttackingUnit, AttackedUnit, 5.00, ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL )
        call SetUnitAnimation(AttackedUnit, "Stand" )
        call ForGroupBJ( GetUnitsOfPlayerAndTypeId(ConvertedPlayer(GetConvertedPlayerId(GetOwningPlayer(AttackingUnit))), 'o001'), function Trig_Untitled_Trigger_001_Func001Func009A )
        call PolledWait(udg_Main_Attack_Speed[p])
        endloop
    set udg_Moves[p] = false
    else
        loop
          if GetUnitStateSwap(UNIT_STATE_LIFE, AttackedUnit) == 0.00 then
          call IssueImmediateOrderBJ(AttackingUnit, "stop" )
          call IssueImmediateOrderBJ(AttackedUnit, "death" )
          set udg_Moves[p] = true
          endif
          if GetUnitStateSwap(UNIT_STATE_LIFE, AttackingUnit) == 0.00 then
          call IssueImmediateOrderBJ(AttackingUnit, "death" )
          call IssueImmediateOrderBJ(AttackedUnit, "stop" )
          set udg_Moves[p] = true
          endif
         exitwhen udg_Moves[p] == true
        call StartTimerBJ( udg_CombatCheckTimer[GetConvertedPlayerId(GetOwningPlayer(AttackedUnit))], false, 3.00 )
        set udg_InCombat[GetConvertedPlayerId(GetOwningPlayer(AttackedUnit))] = true
        call SetUnitAnimation(AttackingUnit, "Attack" )
        call UnitDamageTargetBJ( AttackingUnit, AttackedUnit, 5.00, ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL )
        call SetUnitAnimation(AttackingUnit, "Stand" )
        call ForGroupBJ( GetUnitsOfPlayerAndTypeId(ConvertedPlayer(GetConvertedPlayerId(GetOwningPlayer(AttackedUnit))), 'o001'), function Trig_Untitled_Trigger_001_Func001Func004A )
        call PolledWait(2.00)
        endloop
    set udg_Moves[p] = false
    endif
endfunction
Trigger:
Melee
Collapse Events
Unit - A unit Starts the effect of an ability
Collapse Conditions
(Ability being cast) Equal to Attack
Collapse Actions
Game - Display to (Player group((Owner of (Casting unit)))) the text: Attacks
Set AttackingUnit = (Casting unit)
Set AttackedUnit = (Target unit of ability being cast)
Custom script: call attacks(GetConvertedPlayerId(GetOwningPlayer(udg_AttackingUnit)), udg_AttackingUnit, udg_AttackedUnit)
03-23-2006, 08:33 PM#4
Linera
updated last post