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

[vJASS] Instantly retrieving the last created Illusion

Status
Not open for further replies.
Hey guys,

I'm trying to instantly retrieve the pointer for the illusion last created.

I've tried a trigger, dynamic triggering, and grouping, but it seems that there is a tiny casting delay that is ruining everything for me.

here's what I currently have (after trigger and dynamic triggers failed):

JASS:
    private function illusionF takes nothing returns boolean
        local unit filter=GetFilterUnit()
        if IsUnitIllusion(filter) then
            set lastCreatedIllusion=filter
        endif
        set filter=null
        return false
    endfunction
    
    public function addIllusion takes unit source, real duration returns unit
        local unit dummy=addDummy(GetUnitX(source),GetUnitY(source),GetPlayerId(GetOwningPlayer(source)))
        call UnitAddAbility(dummy,ILLUSIONID)
        call IssueTargetOrderById(dummy,ILLUSIONORDER,source)
        call UnitAddAbility(dummy,'Aloc')
        call GroupEnumUnitsInRange(grp,GetUnitX(source),GetUnitY(source),500.,Filter(function illusionF))
        call UnitApplyTimedLife(lastCreatedIllusion,'BTLF',duration)
        set dummy=null
        return lastCreatedIllusion
    endfunction

Thanks in advance
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
Use EVENT_PLAYER_UNIT_SUMMON to catch the summoned illusion unit. It shouldn't mess up as long as your dummy unit can cast the spell instantly.
Ex:
JASS:
// xe sys: [url]http://www.wc3c.net/showthread.php?t=101150[/url]
// RegisterPlayerUnitEvent: [url]http://www.hiveworkshop.com/forums/jass-resources-412/snippet-registerplayerunitevent-203338/index10.html[/url]
library IllusionSys initializer Init requires xecast, RegisterPlayerUnitEvent

    globals
        private unit lastCreatedIllusion = null
        private boolean active = false // Used for the summon event so that it will only respond to illusions created by this system.
    endglobals
    
    function GetLastCreatedIllusion takes nothing returns unit
        return lastCreatedIllusion
    endfunction
    
    function CreateIllusion takes unit u, player owner, integer abilID returns unit
        local xecast xc = xecast.createBasicA(abilID, 852274, owner)
        set active = true
        call xc.castOnTarget(u)
        set active = false
        return lastCreatedIllusion
    endfunction
    
    private function RegisterSummonedIllusion takes nothing returns nothing
        if active then
            // Don't need an IsUnitIllusion(GetTriggerUnit()) check since it the summon event should fire instantly.
            set lastCreatedIllusion = GetTriggerUnit()
        endif
    endfunction            
    
    private function Init takes nothing returns nothing
        call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SUMMON, function RegisterSummonedIllusion)
    endfunction
    
endlibrary
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
The dummy unit should definitely have Art - Animation - Cast Backswing and Art - Animation - Cast Point set to 0. Not sure if having the movement speed equal to 0 do anything. From the looks of it, a movement speed of 0 is also required.

I usually end up just copying xe's dummy unit. You could also look at this which creates a dummy unit that can cast spells instantly.
 
Pseudo code to cast any spell instantly:

JASS:
u = CreateUnit(Player(12), dummyId, x, y, 0)
UnitAddAbility(u, ILLUSIONID)
IssueTargetOrderById(u, ILLUSIONORDER, source)
UnitRemoveAbility(u, ILLUSIONID)
UnitApplyTimedLife(u, 'BTLF', 0.01)
u = null

The key difference between my code and yours is that I'm removing the ability after I ordered it to be cast.
This way, it casts instantly.
Alain.Mark once posted code in which he did this and Bribe discovered it.
 
Pseudo code to cast any spell instantly:

JASS:
u = CreateUnit(Player(12), dummyId, x, y, 0)
UnitAddAbility(u, ILLUSIONID)
IssueTargetOrderById(u, ILLUSIONORDER, source)
UnitRemoveAbility(u, ILLUSIONID)
UnitApplyTimedLife(u, 'BTLF', 0.01)
u = null

The key difference between my code and yours is that I'm removing the ability after I ordered it to be cast.
This way, it casts instantly.
Alain.Mark once posted code in which he did this and Bribe discovered it.

This will work even if the dummy does not have a zero casting backswing point?
 
Status
Not open for further replies.
Top