Jump to content
EleTD.com
Sign in to follow this  
Guest cohadar

Upgrading OnDamage system

Recommended Posts

That is exactly the kind of thing I was hoping to do with registering Undead/Mechanical. Thanks again for your help.

Share this post


Link to post

I tried to apply this to Undead as well because I did not want to have 30*8 triggers in wait for 5 seconds. I got it all working except the damn move order. Regardless of TSA(even no TSA) the move order never gets executed.

library UndeadReincarnate uses PUI

globals
    private trigger array PUI_Trigger
endglobals

//===========================================================================
private function Revive takes nothing returns boolean
    local integer id = GetPlayerId(udg_CreepOwner[GetUnitUserData(GetTriggerUnit())])
    local unit u = GetTriggerUnit()
    
    //if GetUnitAbilityLevel(u,'A00U') > 0 then
        call UnitRemoveAbility(u,'A00U')
        call SetUnitLifePercentBJ(u,33.33)
        call TriggerSleepAction(0.1)
        call IssuePointOrder(u,"move",udg_LeakX[id],udg_LeakY[id])
    //endif
    
    set u = null
    return false
endfunction

//===========================================================================
public function Register takes unit whichUnit returns nothing
    local integer index  = GetUnitIndex(whichUnit)
  
    if PUI_Trigger[index] != null then
        call DestroyTrigger(PUI_Trigger[index])
    endif
    set PUI_Trigger[index] = CreateTrigger()

    call TriggerRegisterUnitStateEvent(PUI_Trigger[index], whichUnit, UNIT_STATE_LIFE, GREATER_THAN_OR_EQUAL, 0.405)
    call TriggerAddCondition(PUI_Trigger[index], Condition(function Revive))
endfunction

endlibrary

Share this post


Link to post
Guest cohadar

You cannot handle undeads that way.

I really think it is better you do with undeads as I described on TH.

Share this post


Link to post
Guest cohadar
library TTWait initializer Init uses TT

globals
    private unit array Units
    private integer array Ticks
    private real array X
    private real array Y
    private integer N = 0
    
    private constant real WAIT = 1.0
endglobals

//===========================================================================
public function Register takes unit whichUnit, real x, real y returns nothing
    set Units[N] = whichUnit
    set Ticks[N] = R2I(WAIT / TT_PERIOD)
    set X[N] = x
    set Y[N] = y
    set N = N + 1
endfunction

//===========================================================================
private function Handle takes nothing returns boolean
    local integer i = N - 1
    loop
        exitwhen i < 0
        set Ticks[i] = Ticks[i] - 1
        if Ticks[i] <= 0 then
            call IssuePointOrder(Units[i], "move", X[i], Y[i])
            // remove unit from array:
            set N = N  - 1
            set Units[i] = Units[N]
            set Ticks[i] = Ticks[N]
            set X[i] = X[N]
            set Y[i] = Y[N]
        endif
    endloop
    return false
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    call TT_Start(function Handle, 0)
endfunction

endlibrary

Share this post


Link to post
Guest cohadar
scope UndeadReincarnation initializer Init 

globals
    // based on 'AIrs'
    // set Number of Corpses to 1
    // set Area of Effect to 0
    private constant integer AID_resurrection = 'A004'
    private constant real REINCARNATION_DELAY = 5.0
    private constant string FX = "Abilities\\Spells\\Orc\\Reincarnation\\ReincarnationTarget.mdl"
endglobals

//===========================================================================
private function Conditions takes nothing returns boolean
    if IsUnitType(GetTriggerUnit(), UNIT_TYPE_UNDEAD) then
            return true
    endif
    return false
endfunction

//===========================================================================
private function Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    //local integer i = GetPlayerId(udg_CreepOwner[GetUnitUserData(u)])
    local effect eff = AddSpecialEffect(FX, x, y)
    
    call TriggerSleepAction(REINCARNATION_DELAY)
    
    call DestroyEffect(eff)
    // create dummy unit on position of dead unit
    call Dummy_create(u, AID_resurrection, 1, 0.0)
    // cast resurrection
    call IssueImmediateOrderById(bj_lastCreatedUnit, OID_resurrection) // 852283
    
    // issue move order here
    call IssuePointOrderById(u, OID_move, 0.0, 0.0) // 851986
    //call IssuePointOrder(u, "move", udg_LeakX[id],udg_LeakY[id])
    
    
    set u = null
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    //call TriggerRegisterCreepEventBJ(trig, EVENT_PLAYER_UNIT_DEATH) <-----<<
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction

endscope

Share this post


Link to post
Guest cohadar

Q: Why is this better than previous wait method?

A: Because with native reincarnation there is a 5 sec spell timer + your custom wait 0.0

With custom reincarnation there is only custom 5 sec wait

Share this post


Link to post

I've decided to use your dynamic handling of events using actions instead of conditions so I can get the pause in. In place of TSA I am now trying a timer. Here is the code:

library UndeadReincarnate uses PUI

globals
    private trigger array PUI_Trigger
    private unit array Unit
    private integer    Index   = 0
    private timer      Timer   = CreateTimer()
endglobals


//===========================================================================
private function Order takes nothing returns nothing
    local integer i
    local integer index = 0
    loop
        exitwhen index >= Index
        set i = GetPlayerId(udg_CreepOwner[GetUnitUserData(Unit[index])])
        call IssuePointOrder(Unit[index],"move",udg_LeakX[i],udg_LeakY[i])
        set index = index + 1
    endloop
    set Index = 0
    call PauseTimer(Timer)
endfunction

//===========================================================================
private function Revive takes nothing returns nothing
    local unit u = GetTriggerUnit()
    
    if GetUnitAbilityLevel(u,'A00U') > 0 then
        call UnitRemoveAbility(u,'A00U')
        call SetUnitLifePercentBJ(u,33.33)
    
        if Index == 0 then
            call TimerStart(Timer, .0, false, function Order)
        endif
    
        set Unit[Index] = u
        set Index = Index + 1
    endif
    
    set u = null
endfunction

//===========================================================================
public function Register takes unit whichUnit returns nothing
    local integer index  = GetUnitIndex(whichUnit)
  
    if PUI_Trigger[index] != null then
        call DestroyTrigger(PUI_Trigger[index])
    endif
    set PUI_Trigger[index] = CreateTrigger()

    call TriggerRegisterUnitStateEvent(PUI_Trigger[index], whichUnit, UNIT_STATE_LIFE, GREATER_THAN_OR_EQUAL, 0.405)
    call TriggerAddAction(PUI_Trigger[index],function Revive)
endfunction

endlibrary

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...