Warcraft III: MapsModelsSkinsIconsCode SnippetsSpellsToolsTutorials

Welcome

Welcome to the community where modding your favorite game can be possible, and supported by a nice and warm community. Here you will find resources which will help you to develop your projects faster. Additionally you can show your projects and share with a growing community, even be part of the Blizzard Modding Network, which aims to gather all the projects and clans around this game.

Please enjoy your stance here.

Warcraft III Spells & systems

Illusion Editor v1.2b [vJass + GUI Support]


By AGD

ILLUSION EDITOR



This system provides users with helpful utilities with regards to creation of illusions as well as the manipulation of many of their aspects.
With this system, you can now create illusions of any type as easily as creating units. This even allows you to create permanent illusions.
Read the script header for more details.

Please give credits to the following people if you use this resource in your map.

Credits:
    - Written by AGD
    - Looking_For_Help (PDDS)
    - TriggerHappy (UnitDex)
    - Bribe (table)
    - Magtheridon96 (RegisterPlayerUnitEvent)

Main Script
Code: jass  [Select]
  1. library IllusionEditor /*
  2.  
  3.  
  4.   */requires /*
  5.  
  6.   */UnitDex /*
  7.         [http://www.hiveworkshop.com/threads/system-unitdex-unit-indexer.248209/]
  8.  
  9.   */DamageEvent /*
  10.         [http://www.hiveworkshop.com/threads/system-physical-damage-detection.228456/]
  11.  
  12.   */Table /*
  13.         [http://www.hiveworkshop.com/threads/snippet-new-table.188084/]
  14.  
  15.   */optional RegisterPlayerUnitEvent /*
  16.         [http://blizzardmodding.info/4907/snippet-registerplayerunitevent/]
  17.  
  18.  
  19. *///! novjass
  20.  
  21.      _______________________
  22.     |                       |
  23.     | Illusion Editor v1.2b |
  24.     |    Written by AGD     |
  25.     |_______________________|
  26. /*
  27.     This system gives you freedom and ease in creating illusions. With this, you
  28.     can now create illusions of any type as easily as creating units or make an
  29.     illusion copy from an already existing unit, with the ability to change many
  30.     of their aspects (such as duration, damage dealt, damage recieved, deathSFX,
  31.     and hero level) dynamically.
  32.  
  33.  
  34.     Hint:
  35.         - Use zero or any negative value for duration to make a permanent illusion
  36.         - Setting a hero illusion's level might cause a change to its proper name
  37.  
  38.     To Import:
  39.         - Copy all the neccessary Object Editor data or alternatively use the object merger
  40.         - Copy this trigger/trigger category together with the requirements
  41.         - Configure the configurable object rawcodes
  42. */
  43.     |=======|
  44.     |  API  |
  45.     |=======|
  46.  
  47.         function CreateIllusion takes player whichPlayer, integer ID, real dur, real damageDealt, real damageReceived, real x, real y, real angle returns unit/*
  48.         - Creates an illusion of type <ID>
  49.  
  50.       */function CopyUnit takes player whichPlayer, unit u, real dur, real damageDealt, real damageReceived, real x, real y, real angle returns unit/*
  51.         - Creates an illusion copy of a unit which possesses the same abilities and items as the original unit
  52.  
  53.       */function SetIllusionLevel takes unit u, integer level, boolean showEyeCandy returns boolean/*
  54.         - Sets the level of the illusion to a desired value and returns boolean value depending on the success of the operation
  55.           (Only works if the illusion is a hero and if it was created using this system)
  56.  
  57.       */function SetIllusionDuration takes unit u, real time returns boolean/*
  58.         - Sets the duration of the illusion and returns a boolean value depending on the success of the operation
  59.           (This only works for illusions created by this system)
  60.  
  61.       */function AddIllusionDuration takes unit u, real extraTime returns boolean/*
  62.         - Adds an extra duration to an illusion's timed life and returns a boolean value depending on the success of the operation
  63.           (This only works for illusions created by this system)
  64.  
  65.       */function SetIllusionDamageFactor takes unit u, real factor returns boolean/*
  66.         - Sets the damagedealt factor of the illusion and returns a boolean value depending on the success of the operation
  67.           (This only works for illusions created by this system)
  68.  
  69.       */function SetIllusionReceiveFactor takes unit u, real factor returns boolean/*
  70.         - Sets the damagereceivefactor of the illusion and returns a boolean value depending on the success of the operation
  71.           (This only works for illusions created by this system)
  72.  
  73.       */function ShowIllusionDeathEffect takes unit u, boolean flag returns boolean/*
  74.         - Sets the illusion's death animation ON/OFF and returns a boolean value depending on the success of the operation
  75.           (This only works for illusions created by this system)
  76.  
  77.       */function SetIllusionDeathEffect takes unit u, string model returns boolean/*
  78.         - Sets the death animation of the illusion and returns a boolean value depending on the success of the operation
  79.           (This only works for illusions created by this system)
  80.  
  81.       */function GetIllusionRemainingDuration takes unit u returns real/*
  82.         - Returns the remaining duration of the illusion
  83.           (This will return 0 for illusions not created by this system)
  84.  
  85.       */function GetIllusionTotalDuration takes unit u returns real/*
  86.         - Returns the duration of the illusion
  87.           (This will return 0 for illusions not created by this system)
  88.  
  89.       */function GetIllusionDamageFactor takes unit u returns real/*
  90.         - Returns the damagedealt factor of the illusion
  91.           (This will return 0 for illusions not created by this system)
  92.  
  93.       */function GetIllusionReceiveFactor takes unit u returns real/*
  94.         - Returns the damagereceive factor of the illusion
  95.           (This will return 0 for illusions not created by this system)
  96.  
  97.       */function GetLastIllusion takes nothing returns unit/*
  98.         - Returns the last illusion created using this system
  99.  
  100.       */function GetIllusionFlag takes unit u returns boolean/*
  101.         - Checks if the illusion is created by this system or not
  102.  
  103. *///! endnovjass
  104.  
  105.     globals
  106.  
  107.         ///////////////////////////
  108.         // Configuration Section //
  109.         ///////////////////////////
  110.  
  111.         /////////////////////////////////////////////////////
  112.         // Rawcode of the item used for creating illusions //
  113.         /////////////////////////////////////////////////////
  114.         private constant integer ITEM_ID = 'I000'
  115.         /////////////////////////////////////////////////////
  116.         // Rawcode of the dummy caster                     //
  117.         /////////////////////////////////////////////////////
  118.         private constant integer DUMMY_ID = 'i001'
  119.         /////////////////////////////////////////////////////
  120.         // Illusion timed life check interval              //
  121.         /////////////////////////////////////////////////////
  122.         private constant real LOOP_INTERVAL = 0.03125
  123.         /////////////////////////////////////////////////////
  124.         // Synchronize this value with the duration of     //
  125.         // illusions produced by the the item in the       //
  126.         // object editor so that this system will be able  //
  127.         // to make the neccessary adjustments.             //
  128.         // It would be better to set this value to 3600    //
  129.         // which is the maximum duration you can put in    //
  130.         // the object editor. But always be reminded that  //
  131.         // everytime you change this value, change also    //
  132.         // that of the object editor's!                    //
  133.         /////////////////////////////////////////////////////
  134.         private constant real ITEM_DUR_LIMIT = 5.00
  135.         /////////////////////////////////////////////////////
  136.         // The remaining time of the illusion before it    //
  137.         // would be replaced with another one in case the  //
  138.         // desired duration of the illusion is greater     //
  139.         // than what the item could provide                //
  140.         /////////////////////////////////////////////////////
  141.         private constant real REPLACE_TIME_ALLOWANCE = 0.10
  142.         /////////////////////////////////////////////////////
  143.         // The default death animation of the illusions    //
  144.         /////////////////////////////////////////////////////
  145.         private constant string DEFAULT_DEATH_SFX = "Abilities\\Spells\\Orc\\MirrorImage\\MirrorImageDeathCaster.mdl"
  146.         /////////////////////////////////////////////////////
  147.         // The owning player of the dummy unit             //
  148.         /////////////////////////////////////////////////////
  149.         private constant player DUMMY_OWNER = Player(15)
  150.         /////////////////////////////////////////////////////
  151.         // The prefix of the operation error message when  //
  152.         // debug mode is enabled                           //
  153.         /////////////////////////////////////////////////////
  154.         private constant string PREFIX = "Operation Failed: "
  155.  
  156.         //////////////////////////
  157.         // End of Configuration //
  158.         //////////////////////////
  159.  
  160.     endglobals
  161.  
  162.  
  163.     //===== Do not change anything below this line if you're not so sure on what you're doing =====//
  164.  
  165.  
  166.     globals
  167.  
  168.         private HashTable hash
  169.         private group tempGroup         = CreateGroup()
  170.         private trigger deathEvent      = CreateTrigger()
  171.         private integer index           = 0
  172.         private integer tempInt         = 0
  173.         private integer usedDeathEvent  = 0
  174.         private unit illusion
  175.         private unit U
  176.         private unit dummyCaster
  177.         private item casterItem
  178.  
  179.         // These variables are used to store unit specific data for
  180.         // each illusion created using this system
  181.         private integer array maxTargeterCount
  182.         private integer array order
  183.         private integer array orderType
  184.         private boolean array flag
  185.         private boolean array check
  186.         private boolean array showDeath
  187.         private real array targPointX
  188.         private real array targPointY
  189.         private unit array orderTarget
  190.         private timer array lifeTimer
  191.         private real array elapsed
  192.         private real array duration
  193.         private real array damageFactor
  194.         private real array receiveFactor
  195.         private real array X
  196.         private real array Y
  197.         private real array facing
  198.         private player array owner
  199.         private unit array summon
  200.         private string array deathSFX
  201.  
  202.     endglobals
  203.  
  204.     static if DEBUG_MODE then
  205.         private function Debug takes string msg returns nothing
  206.             call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 30, "|CFFFFCC00[Illusion Editor]|R  " + msg )
  207.         endfunction
  208.     endif
  209.  
  210.     private keyword Copy
  211.  
  212.     ///////////////////////////////////////////////////
  213.     // These three functions caches the order of the //
  214.     // expiring illusion units to be passed to their //
  215.     // replacements. Similarly when the expiring     //
  216.     // illusion is targeted with an order, the order //
  217.     // will be redirected to its replacement as well.//
  218.     ///////////////////////////////////////////////////
  219.     private function ReIssueTargetOrder takes nothing returns boolean
  220.         local unit u = GetOrderedUnit()
  221.         local unit t = GetOrderTargetUnit()
  222.         local integer i = GetUnitId( u )
  223.         local integer tDex = GetUnitId( t )
  224.         local integer key = GetHandleId( t )
  225.         if check[i] then
  226.             set orderType[i] = 1
  227.             set orderTarget[i] = t
  228.         endif
  229.         if check[tDex] then
  230.             set order[i] = GetUnitCurrentOrder( u )
  231.             if not flag[i] then
  232.                 loop
  233.                     set maxTargeterCount[tDex] = maxTargeterCount[tDex] + 1
  234.                     if hash[key].unit[maxTargeterCount[tDex]] == null then
  235.                         set hash[key].unit[maxTargeterCount[tDex]] = u
  236.                         set flag[i] = true
  237.                         break
  238.                     endif
  239.                 endloop
  240.             endif
  241.         endif
  242.         set u = null
  243.         set t = null
  244.         return false
  245.     endfunction
  246.  
  247.     private function ReIssuePointOrder takes nothing returns boolean
  248.         local integer i = GetUnitId( GetOrderedUnit() )
  249.         if check[i] then
  250.             set orderType[i] = 2
  251.             set targPointX[i] = GetOrderPointX()
  252.             set targPointY[i] = GetOrderPointY()
  253.         endif
  254.         set flag[i] = false
  255.         return false
  256.     endfunction
  257.  
  258.     private function ReIssueOrder takes nothing returns boolean
  259.         local integer i = GetUnitId( GetOrderedUnit() )
  260.         if check[i] then
  261.             set orderType[i] = 3
  262.         endif
  263.         set flag[i] = false
  264.         return false
  265.     endfunction
  266.  
  267.  
  268.     /////////////////////////////////////////////////
  269.     // This function controls the duration of the  //
  270.     // illusions as well as replacing them in case //
  271.     // their hardcoded lifetime expires before     //
  272.     // meeting the duration desired for them       //
  273.     /////////////////////////////////////////////////
  274.     private function AdjustTimedLife takes nothing returns nothing
  275.         local timer t            = GetExpiredTimer()
  276.         local integer timerKey   = GetHandleId( t )
  277.         local unit u             = hash[timerKey].unit[0]
  278.         local integer key        = GetHandleId( u )
  279.         local integer i          = GetUnitId( u )
  280.         local integer lastOrder
  281.         local unit new
  282.         local real toAdd
  283.         if not IsUnitType( u, UNIT_TYPE_DEAD ) and u != null then
  284.             set elapsed[i] = elapsed[i] + LOOP_INTERVAL
  285.             if duration[i] < ITEM_DUR_LIMIT and duration[i] > 0 and elapsed[i] >= duration[i] then
  286.                 call hash.remove( timerKey )
  287.                 call RemoveUnit( u )
  288.                 call DestroyTimer( t )
  289.             elseif elapsed[i] >= ITEM_DUR_LIMIT - REPLACE_TIME_ALLOWANCE then
  290.                 set toAdd = duration[i] - ( ITEM_DUR_LIMIT - REPLACE_TIME_ALLOWANCE )
  291.                 if toAdd < 0 then
  292.                     set toAdd = 0
  293.                 endif
  294.                 set lastOrder = GetUnitCurrentOrder( u )
  295.                 set new = Copy.evaluate( owner[i], u, toAdd, damageFactor[i], receiveFactor[i], GetUnitX( u ), GetUnitY( u ), GetUnitFacing( u ) )
  296.                 //! textmacro REDIRECTDATA takes KEY, NEWLIFE, NEWMANA
  297.                 call ShowUnit( u, false )
  298.                 call SetWidgetLife( new, $NEWLIFE$ )
  299.                 call SetUnitState( new, UNIT_STATE_MANA, $NEWMANA$ )
  300.                 set index = 0
  301.                 loop
  302.                     set index = index + 1
  303.                     set U = hash[$KEY$].unit[index]
  304.                     set tempInt = GetUnitId( U )
  305.                     if U != null and flag[tempInt] then
  306.                         set flag[tempInt] = false
  307.                         call IssueTargetOrderById( U, order[tempInt], new )
  308.                     endif
  309.                     exitwhen index > maxTargeterCount[i]
  310.                 endloop
  311.                 if orderType[i] == 1 then
  312.                     call IssueTargetOrderById( new, lastOrder, orderTarget[i] )
  313.                 elseif orderType[i] == 2 then
  314.                     call IssuePointOrderById( new, lastOrder, targPointX[i], targPointY[i] )
  315.                 elseif orderType[i] == 3 then
  316.                     call IssueImmediateOrderById( new, lastOrder )
  317.                 endif
  318.                 if IsUnitSelected( u, GetLocalPlayer() ) then
  319.                     call SelectUnit( new, true )
  320.                 endif
  321.                 set maxTargeterCount[i] =  0
  322.                 set index = GetUnitId( new )
  323.                 set deathSFX[index] = deathSFX[i]
  324.                 set showDeath[index] = showDeath[i]
  325.                 //! endtextmacro
  326.                 //! runtextmacro REDIRECTDATA( "key", "GetWidgetLife( u )", "GetUnitState( u, UNIT_STATE_MANA )" )
  327.                 call hash.remove( timerKey )
  328.                 set showDeath[i] = false
  329.                 call RemoveUnit( u )
  330.                 call DestroyTimer( t )
  331.                 if u == illusion then
  332.                     set illusion = new
  333.                 endif
  334.                 set new = null
  335.             endif
  336.         else
  337.             call hash.remove( timerKey )
  338.             call RemoveUnit( u )
  339.             call DestroyTimer( t )
  340.         endif
  341.         set t = null
  342.         set u = null
  343.     endfunction
  344.  
  345.  
  346.     ////////////////////
  347.     // After Creation //
  348.     ////////////////////
  349.     private function OnSummon takes nothing returns boolean
  350.         local integer i
  351.         local integer uDex
  352.         if GetSummoningUnit() == dummyCaster then
  353.             set i = GetUnitId( dummyCaster )
  354.             set U = GetTriggerUnit()
  355.             set uDex = GetUnitId( U )
  356.             set check[uDex] = true
  357.             set showDeath[uDex] = true
  358.             set duration[uDex] = duration[i]
  359.             set damageFactor[uDex] = damageFactor[i]
  360.             set receiveFactor[uDex] = receiveFactor[i]
  361.             set owner[uDex] = owner[i]
  362.             set lifeTimer[uDex] = CreateTimer()
  363.             set elapsed[uDex] = 0
  364.             set maxTargeterCount[uDex] = 0
  365.             set deathSFX[uDex] = DEFAULT_DEATH_SFX
  366.             set hash[GetHandleId( lifeTimer[uDex] )].unit[0] = U
  367.             call TimerStart( lifeTimer[uDex], LOOP_INTERVAL, true, function AdjustTimedLife )
  368.             call SetUnitOwner( U, owner[i], true )
  369.             call SetUnitFacing( U, facing[i] )
  370.             if IsUnitType( U, UNIT_TYPE_STRUCTURE ) then
  371.                 call SetUnitPosition( U, X[i], Y[i] )
  372.             else
  373.                 call SetUnitX( U, X[i] )
  374.                 call SetUnitY( U, Y[i] )
  375.             endif
  376.             call TriggerRegisterUnitStateEvent( deathEvent, U, UNIT_STATE_LIFE, LESS_THAN, UNIT_MIN_LIFE )
  377.         endif
  378.         return false
  379.     endfunction
  380.  
  381.  
  382.     /////////////////////////////////
  383.     //*****************************//
  384.     //* Usable function for users *//
  385.     //*****************************//
  386.     /////////////////////////////////
  387.  
  388.     //! textmacro REPLICATE takes FUNC, TAKE, X, TARGET
  389.     private function $FUNC$ takes player whichPlayer, $TAKE$, real dur, real damageDealt, real damageReceived, real x, real y, real angle returns unit
  390.         local integer i = GetUnitId( dummyCaster )
  391.         $X$local unit tempUnit = CreateUnit( DUMMY_OWNER, ID, x, y, 0 )
  392.         if dur < 0 then
  393.             set dur = 0
  394.         endif
  395.         if damageDealt < 0 then
  396.             set damageDealt = 0
  397.         endif
  398.         if damageReceived < 0 then
  399.             set damageReceived = 0
  400.         endif
  401.         set X[i] = x
  402.         set Y[i] = y
  403.         set duration[i] = dur
  404.         set damageFactor[i] = damageDealt
  405.         set receiveFactor[i] = damageReceived
  406.         set facing[i] = angle
  407.         set owner[i] = whichPlayer
  408.         call UnitUseItemTarget( dummyCaster, casterItem, $TARGET$ )
  409.         $X$call RemoveUnit( tempUnit )
  410.         $X$set tempUnit = null
  411.         return U
  412.     endfunction
  413.     //! endtextmacro
  414.     //! runtextmacro REPLICATE( "Create", "integer ID", "", "tempUnit" )
  415.     //! runtextmacro REPLICATE( "Copy", "unit u", "//", "u" )
  416.  
  417.     function CreateIllusion takes player whichPlayer, integer ID, real dur, real damageDealt, real damageReceived, real x, real y, real angle returns unit
  418.         set illusion = Create( whichPlayer, ID, dur, damageDealt, damageReceived, x, y, angle )
  419.         return illusion
  420.     endfunction
  421.  
  422.     function CopyUnit takes player whichPlayer, unit u, real dur, real damageDealt, real damageReceived, real x, real y, real angle returns unit
  423.         set illusion = Copy( whichPlayer, u, dur, damageDealt, damageReceived, x, y, angle )
  424.         return illusion
  425.     endfunction
  426.  
  427.     function SetIllusionLevel takes unit u, integer level, boolean showEyeCandy returns boolean
  428.         local integer i = GetUnitId( u )
  429.         local integer lastOrder
  430.         local unit tempUnit
  431.         local unit new
  432.         local real x
  433.         local real y
  434.         local boolean success = false
  435.         if check[i] then
  436.             set x = GetUnitX( u )
  437.             set y = GetUnitY( u )
  438.             set tempUnit = CreateUnit( DUMMY_OWNER, GetUnitTypeId( u ), x, y, GetUnitFacing( u ) )
  439.             if IsUnitType( tempUnit, UNIT_TYPE_HERO ) then
  440.                 set lastOrder = GetUnitCurrentOrder( u )
  441.                 call SetHeroLevel( tempUnit, level, false )
  442.                 set new = Copy( owner[i], tempUnit, duration[i], damageFactor[i], receiveFactor[i], x, y, GetUnitFacing( u ) )
  443.                 set index = 0
  444.                 loop
  445.                     set index = index + 1
  446.                     call UnitAddItemToSlotById( new, GetItemTypeId( UnitItemInSlot( u, index ) ), index )
  447.                     exitwhen index == 6
  448.                 endloop
  449.                 //! runtextmacro REDIRECTDATA( "GetHandleId( u )", "GetWidgetLife( u )*GetWidgetLife( new )/GetUnitState( u, UNIT_STATE_MAX_LIFE )", "GetUnitState( u, UNIT_STATE_MANA )*GetUnitState( new, UNIT_STATE_MANA )/GetUnitState( u, UNIT_STATE_MAX_MANA )" )
  450.                 call RemoveUnit( u )
  451.                 if showEyeCandy then
  452.                     call DestroyEffect( AddSpecialEffectTarget( "Abilities\\Spells\\Other\\Levelup\\LevelupCaster.mdl", new, "origin" ) )
  453.                 endif
  454.                 set success = true
  455.                 set new = null
  456.             debug else
  457.                 debug call Debug( PREFIX + "Specified illusion is not a hero" )
  458.             endif
  459.             call RemoveUnit( tempUnit )
  460.             set tempUnit = null
  461.         debug else
  462.             debug call Debug( PREFIX + "Specified unit is not an illusion created by the system" )
  463.         endif
  464.         return success
  465.     endfunction
  466.  
  467.     //! textmacro DEBUG takes X
  468.     if not check[GetUnitId( u )] then
  469.         debug call Debug( PREFIX + "Specified unit is not an illusion created by the system" )
  470.         $X$return false
  471.     endif
  472.     //! endtextmacro
  473.  
  474.     function AddIllusionDuration takes unit u, real extraTime returns boolean
  475.         local integer i = GetUnitId( u )
  476.         //! runtextmacro DEBUG( "" )
  477.         set duration[i] = duration[i] + extraTime
  478.         return true
  479.     endfunction
  480.  
  481.     function SetIllusionDamageFactor takes unit u, real factor returns boolean
  482.         //! runtextmacro DEBUG( "" )
  483.         set damageFactor[GetUnitId( u )] = factor
  484.         return true
  485.     endfunction
  486.  
  487.     function SetIllusionReceiveFactor takes unit u, real factor returns boolean
  488.         //! runtextmacro DEBUG( "" )
  489.         set receiveFactor[GetUnitId( u )] = factor
  490.         return true
  491.     endfunction
  492.  
  493.     function ShowIllusionDeathEffect takes unit u, boolean flag returns boolean
  494.         //! runtextmacro DEBUG( "" )
  495.         set showDeath[GetUnitId( u )] = flag
  496.         return true
  497.     endfunction
  498.  
  499.     function SetIllusionDeathEffect takes unit u, string model returns boolean
  500.         //! runtextmacro DEBUG( "" )
  501.         set deathSFX[GetUnitId( u )] = model
  502.         return true
  503.     endfunction
  504.  
  505.     function GetIllusionRemainingDuration takes unit u returns real
  506.         local integer i = GetUnitId( u )
  507.         local real remaining = duration[i] - elapsed[i]
  508.         //! runtextmacro DEBUG( "return 0.00//" )
  509.         if remaining < 0.00 then
  510.             return 0.00
  511.         endif
  512.         return remaining
  513.     endfunction
  514.  
  515.     function SetIllusionDuration takes unit u, real time returns boolean
  516.         return AddIllusionDuration( u, time - GetIllusionRemainingDuration( u ) )
  517.     endfunction
  518.  
  519.     function GetIllusionTotalDuration takes unit u returns real
  520.         //! runtextmacro DEBUG( "//" )
  521.         return duration[GetUnitId( u )]
  522.     endfunction
  523.  
  524.     function GetIllusionDamageFactor takes unit u returns real
  525.         //! runtextmacro DEBUG( "//" )
  526.         return damageFactor[GetUnitId( u )]
  527.     endfunction
  528.  
  529.     function GetIllusionReceiveFactor takes unit u returns real
  530.         //! runtextmacro DEBUG( "//" )
  531.         return receiveFactor[GetUnitId( u )]
  532.     endfunction
  533.  
  534.     function GetLastIllusion takes nothing returns unit
  535.         return illusion
  536.     endfunction
  537.  
  538.     function GetIllusionFlag takes unit u returns boolean
  539.         return check[GetUnitId( u )]
  540.     endfunction
  541.  
  542.  
  543.     ////////////////////////////////////////////////
  544.     // This function adjusts the damage dealt and //
  545.     // taken by the illusions                     //
  546.     ////////////////////////////////////////////////
  547.     private function DamageAdjustment takes nothing returns boolean
  548.         local integer uDex = GetUnitId( PDDS.source )
  549.         local integer tDex = GetUnitId( PDDS.target )
  550.         if check[uDex] and check[tDex] then
  551.             set PDDS.amount = PDDS.amount*damageFactor[uDex]*receiveFactor[tDex]
  552.         elseif check[uDex] then
  553.             set PDDS.amount = PDDS.amount*damageFactor[uDex]
  554.         elseif check[tDex] then
  555.             set PDDS.amount = PDDS.amount*receiveFactor[tDex]
  556.         endif
  557.         return false
  558.     endfunction
  559.  
  560.  
  561.     ////////////////////////////////////////////////
  562.     // Registers an illusion death event          //
  563.     ////////////////////////////////////////////////
  564.     private function RefreshDeathTrigger takes nothing returns nothing
  565.         local unit u
  566.         call GroupEnumUnitsInRect( tempGroup, bj_mapInitialPlayableArea, null )
  567.         loop
  568.             set u = FirstOfGroup( tempGroup )
  569.             exitwhen u == null
  570.             call GroupRemoveUnit( tempGroup, u )
  571.             if check[GetUnitId( u )] then
  572.                 call TriggerRegisterUnitStateEvent( deathEvent, u, UNIT_STATE_LIFE, LESS_THAN, UNIT_MIN_LIFE )
  573.             endif
  574.         endloop
  575.     endfunction
  576.  
  577.  
  578.     ////////////////////////////////////////////////
  579.     // This function is responsible for hiding or //
  580.     // showing the illusion's death SFX           //
  581.     ////////////////////////////////////////////////
  582.     private function OnDeath takes nothing returns boolean
  583.         local unit u = GetTriggerUnit()
  584.         local integer i = GetUnitId( u )
  585.         call ShowUnit( u, false )
  586.         call hash.remove( GetHandleId( u ) )
  587.         if showDeath[i] then
  588.             call DestroyEffect( AddSpecialEffect( deathSFX[i], GetUnitX( u ), GetUnitY( u ) ) )
  589.         endif
  590.         set usedDeathEvent = usedDeathEvent + 1
  591.         if usedDeathEvent == 20 then
  592.             set usedDeathEvent = 0
  593.             call DestroyTrigger( deathEvent )
  594.             set deathEvent = CreateTrigger()
  595.             call TriggerAddCondition( deathEvent, Filter( function OnDeath ) )
  596.             call RefreshDeathTrigger()
  597.         endif
  598.         set u = null
  599.         return false
  600.     endfunction
  601.  
  602.  
  603.     ////////////////////
  604.     // Initialization //
  605.     ////////////////////
  606.     private module M
  607.         static method onInit takes nothing returns nothing
  608.             static if LIBRARY_RegisterPlayerUnitEvent then
  609.                 call RegisterPlayerUnitEventForPlayer( EVENT_PLAYER_UNIT_SUMMON, function OnSummon, DUMMY_OWNER )
  610.                 call RegisterPlayerUnitEvent( EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, function ReIssueTargetOrder )
  611.                 call RegisterPlayerUnitEvent( EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER, function ReIssuePointOrder )
  612.                 call RegisterPlayerUnitEvent( EVENT_PLAYER_UNIT_ISSUED_ORDER, function ReIssueOrder )
  613.             else
  614.                 local trigger t1 = CreateTrigger()
  615.                 local trigger t2 = CreateTrigger()
  616.                 local trigger t3 = CreateTrigger()
  617.                 local trigger t4 = CreateTrigger()
  618.                 set index = 16
  619.                 loop
  620.                     set index = index - 1
  621.                     call TriggerRegisterPlayerUnitEvent( t2, Player(index), EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, null )
  622.                     call TriggerRegisterPlayerUnitEvent( t3, Player(index), EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER, null )
  623.                     call TriggerRegisterPlayerUnitEvent( t4, Player(index), EVENT_PLAYER_UNIT_ISSUED_ORDER, null )
  624.                     exitwhen index == 0
  625.                 endloop
  626.                 call TriggerRegisterPlayerUnitEvent( t1, DUMMY_OWNER, EVENT_PLAYER_UNIT_SUMMON, null )
  627.                 call TriggerAddCondition( t1, Filter( function OnSummon ) )
  628.                 call TriggerAddCondition( t2, Filter( function ReIssueTargetOrder ) )
  629.                 call TriggerAddCondition( t3, Filter( function ReIssuePointOrder ) )
  630.                 call TriggerAddCondition( t4, Filter( function ReIssueOrder ) )
  631.             endif
  632.             call TriggerAddCondition( deathEvent, Filter( function OnDeath ) )
  633.             call AddDamageHandler( function DamageAdjustment )
  634.             set hash = HashTable.create()
  635.             set casterItem = CreateItem( ITEM_ID, 0, 0 )
  636.             set dummyCaster = CreateUnit( DUMMY_OWNER, DUMMY_ID, 0, 0, 0 )
  637.             call UnitAddItem( dummyCaster, casterItem )
  638.         endmethod
  639.     endmodule
  640.  
  641.     private struct S extends array
  642.         implement M
  643.     endstruct
  644.  
  645.  
  646. endlibrary
  647.  

Illusion Editor ObjectMerger
Code: jass  [Select]
  1. //!| [ ILLUSION EDITOR OBJECT MERGER ] |
  2. /*
  3.  
  4.     Paste this script to your map and it save it. Close your map, open it again and disable/delete this script.
  5.     Now you have the all the object data needed for the Illusion Editor in your map.
  6.  
  7. */
  8. //! external ObjectMerger w3u nzin i001 anam "Dummy" ansf "(Illusion Editor)" uabi "Ainv, Aloc" ucbs 0 ushr 0 umdl "dummy.mdl" upat "" unbm 0 usid 1000000000 usin 1000000000
  9. //! external ObjectMerger w3a Alil I002 anam "illu" atat "" lild 1 1 lilw 1 1 aare 1 0 aran 1 99999 ahdu 1 5 adur 1 5 atar 1 "air,alive,allies,ancient,bridge,dead,debris,decoration,enemies,friend,ground,hero,invulnerable,item,mechanical,neutral,nonancient,nonhero,nonsapper,notself,organic,player,self,structure,sapper,terrain,tree,vulnerable,wall,ward"
  10. //! external ObjectMerger w3t will I000 anam "" iabi "illu" icla "Permanent" igol 0 iuse 0
  11.  


GUI Support
Code: jass  [Select]
  1. library IllusionEditorGUISupport uses IllusionEditor
  2.  
  3.  
  4.     private function Operate takes nothing returns nothing
  5.         if udg_IE_Operation == 0 then
  6.             set udg_IE_Illusion = GetLastIllusion()
  7.             return
  8.         elseif udg_IE_Operation == udg_IE_CreateIllusion then
  9.             set udg_IE_Illusion = CreateIllusion( udg_IE_Owner, udg_IE_UnitType, udg_IE_Duration, udg_IE_DamageDealtFactor, udg_IE_DamageReceiveFactor, GetLocationX( udg_IE_Position ), GetLocationY( udg_IE_Position ), udg_IE_Facing )
  10.             set udg_IE_Operation = 0
  11.             set udg_IE_Owner = null
  12.             set udg_IE_UnitType = 0
  13.             set udg_IE_Duration = 0.00
  14.             set udg_IE_DamageDealtFactor = 0.00
  15.             set udg_IE_DamageReceiveFactor = 0.00
  16.             set udg_IE_Facing = 0.00
  17.             return
  18.         elseif udg_IE_Operation == udg_IE_CopyUnit then
  19.             set udg_IE_Illusion = CopyUnit( udg_IE_Owner, udg_IE_BaseUnit, udg_IE_Duration, udg_IE_DamageDealtFactor, udg_IE_DamageReceiveFactor, GetLocationX( udg_IE_Position ), GetLocationY( udg_IE_Position ), udg_IE_Facing )
  20.             set udg_IE_Operation = 0
  21.             set udg_IE_Owner = null
  22.             set udg_IE_BaseUnit = null
  23.             set udg_IE_Duration = 0.00
  24.             set udg_IE_DamageDealtFactor = 0.00
  25.             set udg_IE_DamageReceiveFactor = 0.00
  26.             set udg_IE_Facing = 0.00
  27.             return
  28.         elseif udg_IE_Operation == udg_IE_SetLevel then
  29.             set udg_IE_Flag = SetIllusionLevel( udg_IE_Illusion, udg_IE_NewLevel, udg_IE_Flag )
  30.             set udg_IE_Operation = 0
  31.             return
  32.         elseif udg_IE_Operation == udg_IE_SetDuration then
  33.             set udg_IE_Flag = SetIllusionDuration( udg_IE_Illusion, udg_IE_Duration )
  34.             set udg_IE_Operation = 0
  35.             return
  36.         elseif udg_IE_Operation == udg_IE_AddDuration then
  37.             set udg_IE_Flag = AddIllusionDuration( udg_IE_Illusion, udg_IE_Duration )
  38.             set udg_IE_Operation = 0
  39.             return
  40.         elseif udg_IE_Operation == udg_IE_SetDamageFactor then
  41.             set udg_IE_Flag = SetIllusionDamageFactor( udg_IE_Illusion, udg_IE_DamageDealtFactor )
  42.             set udg_IE_Operation = 0
  43.             return
  44.         elseif udg_IE_Operation == udg_IE_SetReceiveFactor then
  45.             set udg_IE_Flag = SetIllusionReceiveFactor( udg_IE_Illusion, udg_IE_DamageReceiveFactor )
  46.             set udg_IE_Operation = 0
  47.             return
  48.         elseif udg_IE_Operation == udg_IE_ShowDeathEffect then
  49.             set udg_IE_Flag = ShowIllusionDeathEffect( udg_IE_Illusion, udg_IE_Flag )
  50.             set udg_IE_Operation = 0
  51.             return
  52.         elseif udg_IE_Operation == udg_IE_SetDeathEffect then
  53.             set udg_IE_Flag = SetIllusionDeathEffect( udg_IE_Illusion, udg_IE_DeathEffect )
  54.             set udg_IE_Operation = 0
  55.             return
  56.         elseif udg_IE_Operation == udg_IE_GetRemainingDuration then
  57.             set udg_IE_Duration = GetIllusionRemainingDuration( udg_IE_Illusion )
  58.             set udg_IE_Operation = 0
  59.             return
  60.         elseif udg_IE_Operation == udg_IE_GetTotalDuration then
  61.             set udg_IE_Duration = GetIllusionTotalDuration( udg_IE_Illusion )
  62.             set udg_IE_Operation = 0
  63.             return
  64.         elseif udg_IE_Operation == udg_IE_GetDamageFactor then
  65.             set udg_IE_DamageDealtFactor = GetIllusionDamageFactor( udg_IE_Illusion )
  66.             set udg_IE_Operation = 0
  67.             return
  68.         elseif udg_IE_Operation == udg_IE_GetReceiveFactor then
  69.             set udg_IE_DamageReceiveFactor = GetIllusionReceiveFactor( udg_IE_Illusion )
  70.             set udg_IE_Operation = 0
  71.             return
  72.         elseif udg_IE_Operation == udg_IE_GetFlag then
  73.             set udg_IE_Flag = GetIllusionFlag( udg_IE_Illusion )
  74.             set udg_IE_Operation = 0
  75.             return
  76.         endif
  77.     endfunction
  78.  
  79.     hook DoNothing Operate
  80.  
  81.  
  82. endlibrary
  83.  
  84.  
  85. function InitTrig_GUI_Support takes nothing returns nothing
  86.     /* We use an InitTrig function instead of a scope/library
  87.     initializer to initialize the values of our variables to
  88.     make sure that InitGlobals() runs first so that the values
  89.     of our variables would not be reset.                    */
  90.     call Trig_GUI_IllusionEditor_Documentation_Actions.execute()
  91. endfunction
  92.  

GUI Support Documentation
Trigger: GUI IllusionEditor Documentation
    Events
    Conditions
    Actions
        -------- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| --------
        -------- |||||||||||||||||||||||||||||||||||||||||||||||||              GUI ILLUSION EDITOR GUIDE              |||||||||||||||||||||||||||||||||||||||||||||||| --------
        -------- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| --------
        -------- First you need to choose what operation you want to do using the system. Like this:             --------
        Set IE_Operation = IE_CreateIllusion
        -------- It can be any from the list below:                                                                                             --------
        --------                                                                                                                                                 --------
        -------- 1. CreateIllusion - creates an illusion of a certain unit-type.                                                      --------
        -------- 2. CopyUnit - creates a mirror image of a unit which possesses the same items and abilities   --------
        --------                      as the original unit.                                                                                             --------
        -------- 3. SetLevel - sets the level of a hero type illusion to a desired value.                                      --------
        -------- 4. SetDuration - sets the total duration of an illusion to a desired value, if the given amount   --------
        --------                          is less than the elapsed time of the illusion, it will be destroyed.                      --------
        -------- 5. AddDuration - adds an extra time to an illusion's duration.                                                   --------
        -------- 6. SetDamageFactor - sets the damage dealt factor of an illusion.                                          --------
        -------- 7. SetReceiveFactor - sets the damage receive factor of an illusion                                       --------
        -------- 8. ShowDeathEffect - shows/hides the death effect of an illusion.                                         --------
        -------- 9. SetDeathEffect - sets a new special effect to replace the default death effect of an          --------
        --------                                 illusion.                                                                                                    --------
        -------- 10. GetRemainingDuration - gets the remaining duration of an illusion.                                   --------
        -------- 11. GetTotalDuration - gets the total duration of an illusion.                                                    --------
        -------- 12. GetDamageFactor - gets the damage dealt factor of an illusion.                                       --------
        -------- 13. GetReceiveFactor - gets the damage receive factor of an illusion.                                   --------
        -------- 14. GetFlag - checks if the illusion was created using this system or not.                                --------
        --------                                                                                                                                                 --------
        -------- Next, you have to setup all the data necessary for the operation you chose. Below are the   --------
        -------- list of data needed for each operation (Note that all these have an IE_ prefix):                       --------
        --------                                                                                                                                                 --------
        -------- 1. - Owner                                                                                                                                --------
        --------     - UnitType                                                                                                                            --------
        --------     - Duration                                                                                                                             --------
        --------     - DamageDealtFactor                                                                                                           --------
        --------     - DamageReceiveFactor                                                                                                      --------
        --------     - Position                                                                                                                              --------
        --------     - Facing                                                                                                                                --------
        --------                                                                                                                                                 --------
        -------- 2. - Owner                                                                                                                                --------
        --------     - BaseUnit                                                                                                                            --------
        --------     - Duration                                                                                                                             --------
        --------     - DamageDealtFactor                                                                                                           --------
        --------     - DamageReceiveFactor                                                                                                      --------
        --------     - Position                                                                                                                              --------
        --------     - Facing                                                                                                                                --------
        --------                                                                                                                                                 --------
        -------- 3. - Illusion                                                                                                                               --------
        --------     - NewLevel                                                                                                                          --------
        --------     - Flag                                                                                                                                   --------
        --------                                                                                                                                                 --------
        -------- 4, 5. - Illusion                                                                                                                           --------
        --------         - Duration                                                                                                                         --------
        --------                                                                                                                                                 --------
        -------- 6. - Illusion                                                                                                                               --------
        --------     - DamageDealtFactor                                                                                                          --------
        --------                                                                                                                                                 --------
        -------- 7. - Illusion                                                                                                                               --------
        --------     - DamageReceiveFactor                                                                                                     --------
        --------                                                                                                                                                 --------
        -------- 8. - Illusion                                                                                                                               --------
        --------     - Flag                                                                                                                                   --------
        --------                                                                                                                                                 --------
        -------- 9. - Illusion                                                                                                                               --------
        --------     - DeathEffect                                                                                                                       --------
        --------                                                                                                                                                 --------
        -------- 10, 11, 12, 13, 14. - Illusion                                                                                                     --------
        --------                                                                                                                                                 --------
        -------- The example we chose is CreateIllusion operation. So as you can see in number 1, we         --------
        -------- need to setup those variables so now we do:                                                                          --------
        Set IE_Owner = Player 1 (Red)
        Set IE_UnitType = Mortar Team
        Set IE_Duration = 5.00
        Set IE_DamageDealtFactor = 0.35
        Set IE_DamageReceiveFactor = 4.00
        Set IE_Position = (Center of (Playable map area))
        Set IE_Facing = Default building facing
        --------                                                                                                                                                 --------
        -------- And finally, what we have to do is execute the operation which in this case is very simple.    --------
        -------- To execute the opertation we have to use this:                                                                       --------
        Do nothing
        -------- Easy right? Plus we are also able to add a new functionality to the previously useless            --------
        -------- <Do nothing> function. ^-^                                                                                                      --------
        --------                                                                                                                                                 --------
        --------                                                                                                                                                 --------
        --------  ======================================================================= --------
        --------                                                                                                                                                 --------
        --------                                                                                                                                                 --------
        -------- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| --------
        -------- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||              CONSTANTS SETTING              ||||||||||||||||||||||||||||||||||||||||||||||||||||||||| --------
        -------- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| --------
        Set IE_CreateIllusion = 1
        Set IE_CopyUnit = 2
        Set IE_SetLevel = 3
        Set IE_SetDuration = 4
        Set IE_AddDuration = 5
        Set IE_SetDamageFactor = 6
        Set IE_SetReceiveFactor = 7
        Set IE_ShowDeathEffect = 8
        Set IE_SetDeathEffect = 9
        Set IE_GetRemainingDuration = 10
        Set IE_GetTotalDuration = 11
        Set IE_GetDamageFactor = 12
        Set IE_GetReceiveFactor = 13
        Set IE_GetFlag = 14
        --------                                                                                                                                                 --------
        --------                                                                                                                                                 --------
        -------- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| --------
        -------- Do not enable the following line. However, they are variable creators so do not delete them. --------
        -------- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| --------
        Set IE_Operation = 0
        Set IE_NewLevel = 0
        Set IE_DamageDealtFactor = 0.00
        Set IE_DamageReceiveFactor = 0.00
        Set IE_Duration = 0.00
        Set IE_Facing = 0.00
        Set IE_Illusion = No unit
        Set IE_Owner = Player 1 (Red)
        Set IE_UnitType = No unit-type
        Set IE_BaseUnit = No unit
        Set IE_Position = IE_Position
        Set IE_Flag = False
        Set IE_DeathEffect = 
        --------  ======================================================================= --------

Picked from the vault...

Illusion Editor v1.2b [vJass + GUI Support]


By AGD

ILLUSION EDITOR



This system provides users with helpful utilities with regards to creation of illusions as well as the manipulation of many of their aspects.
With this system, you can now create illusions of any type as easily as creating units. This even allows you to create permanent illusions.
Read the script header for more details.

Please give credits to the following people if you use this resource in your map.

Credits:
    - Written by AGD
    - Looking_For_Help (PDDS)
    - TriggerHappy (UnitDex)
    - Bribe (table)
    - Magtheridon96 (RegisterPlayerUnitEvent)

Main Script
Code: jass  [Select]
  1. library IllusionEditor /*
  2.  
  3.  
  4.   */requires /*
  5.  
  6.   */UnitDex /*
  7.         [http://www.hiveworkshop.com/threads/system-unitdex-unit-indexer.248209/]
  8.  
  9.   */DamageEvent /*
  10.         [http://www.hiveworkshop.com/threads/system-physical-damage-detection.228456/]
  11.  
  12.   */Table /*
  13.         [http://www.hiveworkshop.com/threads/snippet-new-table.188084/]
  14.  
  15.   */optional RegisterPlayerUnitEvent /*
  16.         [http://blizzardmodding.info/4907/snippet-registerplayerunitevent/]
  17.  
  18.  
  19. *///! novjass
  20.  
  21.      _______________________
  22.     |                       |
  23.     | Illusion Editor v1.2b |
  24.     |    Written by AGD     |
  25.     |_______________________|
  26. /*
  27.     This system gives you freedom and ease in creating illusions. With this, you
  28.     can now create illusions of any type as easily as creating units or make an
  29.     illusion copy from an already existing unit, with the ability to change many
  30.     of their aspects (such as duration, damage dealt, damage recieved, deathSFX,
  31.     and hero level) dynamically.
  32.  
  33.  
  34.     Hint:
  35.         - Use zero or any negative value for duration to make a permanent illusion
  36.         - Setting a hero illusion's level might cause a change to its proper name
  37.  
  38.     To Import:
  39.         - Copy all the neccessary Object Editor data or alternatively use the object merger
  40.         - Copy this trigger/trigger category together with the requirements
  41.         - Configure the configurable object rawcodes
  42. */
  43.     |=======|
  44.     |  API  |
  45.     |=======|
  46.  
  47.         function CreateIllusion takes player whichPlayer, integer ID, real dur, real damageDealt, real damageReceived, real x, real y, real angle returns unit/*
  48.         - Creates an illusion of type <ID>
  49.  
  50.       */function CopyUnit takes player whichPlayer, unit u, real dur, real damageDealt, real damageReceived, real x, real y, real angle returns unit/*
  51.         - Creates an illusion copy of a unit which possesses the same abilities and items as the original unit
  52.  
  53.       */function SetIllusionLevel takes unit u, integer level, boolean showEyeCandy returns boolean/*
  54.         - Sets the level of the illusion to a desired value and returns boolean value depending on the success of the operation
  55.           (Only works if the illusion is a hero and if it was created using this system)
  56.  
  57.       */function SetIllusionDuration takes unit u, real time returns boolean/*
  58.         - Sets the duration of the illusion and returns a boolean value depending on the success of the operation
  59.           (This only works for illusions created by this system)
  60.  
  61.       */function AddIllusionDuration takes unit u, real extraTime returns boolean/*
  62.         - Adds an extra duration to an illusion's timed life and returns a boolean value depending on the success of the operation
  63.           (This only works for illusions created by this system)
  64.  
  65.       */function SetIllusionDamageFactor takes unit u, real factor returns boolean/*
  66.         - Sets the damagedealt factor of the illusion and returns a boolean value depending on the success of the operation
  67.           (This only works for illusions created by this system)
  68.  
  69.       */function SetIllusionReceiveFactor takes unit u, real factor returns boolean/*
  70.         - Sets the damagereceivefactor of the illusion and returns a boolean value depending on the success of the operation
  71.           (This only works for illusions created by this system)
  72.  
  73.       */function ShowIllusionDeathEffect takes unit u, boolean flag returns boolean/*
  74.         - Sets the illusion's death animation ON/OFF and returns a boolean value depending on the success of the operation
  75.           (This only works for illusions created by this system)
  76.  
  77.       */function SetIllusionDeathEffect takes unit u, string model returns boolean/*
  78.         - Sets the death animation of the illusion and returns a boolean value depending on the success of the operation
  79.           (This only works for illusions created by this system)
  80.  
  81.       */function GetIllusionRemainingDuration takes unit u returns real/*
  82.         - Returns the remaining duration of the illusion
  83.           (This will return 0 for illusions not created by this system)
  84.  
  85.       */function GetIllusionTotalDuration takes unit u returns real/*
  86.         - Returns the duration of the illusion
  87.           (This will return 0 for illusions not created by this system)
  88.  
  89.       */function GetIllusionDamageFactor takes unit u returns real/*
  90.         - Returns the damagedealt factor of the illusion
  91.           (This will return 0 for illusions not created by this system)
  92.  
  93.       */function GetIllusionReceiveFactor takes unit u returns real/*
  94.         - Returns the damagereceive factor of the illusion
  95.           (This will return 0 for illusions not created by this system)
  96.  
  97.       */function GetLastIllusion takes nothing returns unit/*
  98.         - Returns the last illusion created using this system
  99.  
  100.       */function GetIllusionFlag takes unit u returns boolean/*
  101.         - Checks if the illusion is created by this system or not
  102.  
  103. *///! endnovjass
  104.  
  105.     globals
  106.  
  107.         ///////////////////////////
  108.         // Configuration Section //
  109.         ///////////////////////////
  110.  
  111.         /////////////////////////////////////////////////////
  112.         // Rawcode of the item used for creating illusions //
  113.         /////////////////////////////////////////////////////
  114.         private constant integer ITEM_ID = 'I000'
  115.         /////////////////////////////////////////////////////
  116.         // Rawcode of the dummy caster                     //
  117.         /////////////////////////////////////////////////////
  118.         private constant integer DUMMY_ID = 'i001'
  119.         /////////////////////////////////////////////////////
  120.         // Illusion timed life check interval              //
  121.         /////////////////////////////////////////////////////
  122.         private constant real LOOP_INTERVAL = 0.03125
  123.         /////////////////////////////////////////////////////
  124.         // Synchronize this value with the duration of     //
  125.         // illusions produced by the the item in the       //
  126.         // object editor so that this system will be able  //
  127.         // to make the neccessary adjustments.             //
  128.         // It would be better to set this value to 3600    //
  129.         // which is the maximum duration you can put in    //
  130.         // the object editor. But always be reminded that  //
  131.         // everytime you change this value, change also    //
  132.         // that of the object editor's!                    //
  133.         /////////////////////////////////////////////////////
  134.         private constant real ITEM_DUR_LIMIT = 5.00
  135.         /////////////////////////////////////////////////////
  136.         // The remaining time of the illusion before it    //
  137.         // would be replaced with another one in case the  //
  138.         // desired duration of the illusion is greater     //
  139.         // than what the item could provide                //
  140.         /////////////////////////////////////////////////////
  141.         private constant real REPLACE_TIME_ALLOWANCE = 0.10
  142.         /////////////////////////////////////////////////////
  143.         // The default death animation of the illusions    //
  144.         /////////////////////////////////////////////////////
  145.         private constant string DEFAULT_DEATH_SFX = "Abilities\\Spells\\Orc\\MirrorImage\\MirrorImageDeathCaster.mdl"
  146.         /////////////////////////////////////////////////////
  147.         // The owning player of the dummy unit             //
  148.         /////////////////////////////////////////////////////
  149.         private constant player DUMMY_OWNER = Player(15)
  150.         /////////////////////////////////////////////////////
  151.         // The prefix of the operation error message when  //
  152.         // debug mode is enabled                           //
  153.         /////////////////////////////////////////////////////
  154.         private constant string PREFIX = "Operation Failed: "
  155.  
  156.         //////////////////////////
  157.         // End of Configuration //
  158.         //////////////////////////
  159.  
  160.     endglobals
  161.  
  162.  
  163.     //===== Do not change anything below this line if you're not so sure on what you're doing =====//
  164.  
  165.  
  166.     globals
  167.  
  168.         private HashTable hash
  169.         private group tempGroup         = CreateGroup()
  170.         private trigger deathEvent      = CreateTrigger()
  171.         private integer index           = 0
  172.         private integer tempInt         = 0
  173.         private integer usedDeathEvent  = 0
  174.         private unit illusion
  175.         private unit U
  176.         private unit dummyCaster
  177.         private item casterItem
  178.  
  179.         // These variables are used to store unit specific data for
  180.         // each illusion created using this system
  181.         private integer array maxTargeterCount
  182.         private integer array order
  183.         private integer array orderType
  184.         private boolean array flag
  185.         private boolean array check
  186.         private boolean array showDeath
  187.         private real array targPointX
  188.         private real array targPointY
  189.         private unit array orderTarget
  190.         private timer array lifeTimer
  191.         private real array elapsed
  192.         private real array duration
  193.         private real array damageFactor
  194.         private real array receiveFactor
  195.         private real array X
  196.         private real array Y
  197.         private real array facing
  198.         private player array owner
  199.         private unit array summon
  200.         private string array deathSFX
  201.  
  202.     endglobals
  203.  
  204.     static if DEBUG_MODE then
  205.         private function Debug takes string msg returns nothing
  206.             call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 30, "|CFFFFCC00[Illusion Editor]|R  " + msg )
  207.         endfunction
  208.     endif
  209.  
  210.     private keyword Copy
  211.  
  212.     ///////////////////////////////////////////////////
  213.     // These three functions caches the order of the //
  214.     // expiring illusion units to be passed to their //
  215.     // replacements. Similarly when the expiring     //
  216.     // illusion is targeted with an order, the order //
  217.     // will be redirected to its replacement as well.//
  218.     ///////////////////////////////////////////////////
  219.     private function ReIssueTargetOrder takes nothing returns boolean
  220.         local unit u = GetOrderedUnit()
  221.         local unit t = GetOrderTargetUnit()
  222.         local integer i = GetUnitId( u )
  223.         local integer tDex = GetUnitId( t )
  224.         local integer key = GetHandleId( t )
  225.         if check[i] then
  226.             set orderType[i] = 1
  227.             set orderTarget[i] = t
  228.         endif
  229.         if check[tDex] then
  230.             set order[i] = GetUnitCurrentOrder( u )
  231.             if not flag[i] then
  232.                 loop
  233.                     set maxTargeterCount[tDex] = maxTargeterCount[tDex] + 1
  234.                     if hash[key].unit[maxTargeterCount[tDex]] == null then
  235.                         set hash[key].unit[maxTargeterCount[tDex]] = u
  236.                         set flag[i] = true
  237.                         break
  238.                     endif
  239.                 endloop
  240.             endif
  241.         endif
  242.         set u = null
  243.         set t = null
  244.         return false
  245.     endfunction
  246.  
  247.     private function ReIssuePointOrder takes nothing returns boolean
  248.         local integer i = GetUnitId( GetOrderedUnit() )
  249.         if check[i] then
  250.             set orderType[i] = 2
  251.             set targPointX[i] = GetOrderPointX()
  252.             set targPointY[i] = GetOrderPointY()
  253.         endif
  254.         set flag[i] = false
  255.         return false
  256.     endfunction
  257.  
  258.     private function ReIssueOrder takes nothing returns boolean
  259.         local integer i = GetUnitId( GetOrderedUnit() )
  260.         if check[i] then
  261.             set orderType[i] = 3
  262.         endif
  263.         set flag[i] = false
  264.         return false
  265.     endfunction
  266.  
  267.  
  268.     /////////////////////////////////////////////////
  269.     // This function controls the duration of the  //
  270.     // illusions as well as replacing them in case //
  271.     // their hardcoded lifetime expires before     //
  272.     // meeting the duration desired for them       //
  273.     /////////////////////////////////////////////////
  274.     private function AdjustTimedLife takes nothing returns nothing
  275.         local timer t            = GetExpiredTimer()
  276.         local integer timerKey   = GetHandleId( t )
  277.         local unit u             = hash[timerKey].unit[0]
  278.         local integer key        = GetHandleId( u )
  279.         local integer i          = GetUnitId( u )
  280.         local integer lastOrder
  281.         local unit new
  282.         local real toAdd
  283.         if not IsUnitType( u, UNIT_TYPE_DEAD ) and u != null then
  284.             set elapsed[i] = elapsed[i] + LOOP_INTERVAL
  285.             if duration[i] < ITEM_DUR_LIMIT and duration[i] > 0 and elapsed[i] >= duration[i] then
  286.                 call hash.remove( timerKey )
  287.                 call RemoveUnit( u )
  288.                 call DestroyTimer( t )
  289.             elseif elapsed[i] >= ITEM_DUR_LIMIT - REPLACE_TIME_ALLOWANCE then
  290.                 set toAdd = duration[i] - ( ITEM_DUR_LIMIT - REPLACE_TIME_ALLOWANCE )
  291.                 if toAdd < 0 then
  292.                     set toAdd = 0
  293.                 endif
  294.                 set lastOrder = GetUnitCurrentOrder( u )
  295.                 set new = Copy.evaluate( owner[i], u, toAdd, damageFactor[i], receiveFactor[i], GetUnitX( u ), GetUnitY( u ), GetUnitFacing( u ) )
  296.                 //! textmacro REDIRECTDATA takes KEY, NEWLIFE, NEWMANA
  297.                 call ShowUnit( u, false )
  298.                 call SetWidgetLife( new, $NEWLIFE$ )
  299.                 call SetUnitState( new, UNIT_STATE_MANA, $NEWMANA$ )
  300.                 set index = 0
  301.                 loop
  302.                     set index = index + 1
  303.                     set U = hash[$KEY$].unit[index]
  304.                     set tempInt = GetUnitId( U )
  305.                     if U != null and flag[tempInt] then
  306.                         set flag[tempInt] = false
  307.                         call IssueTargetOrderById( U, order[tempInt], new )
  308.                     endif
  309.                     exitwhen index > maxTargeterCount[i]
  310.                 endloop
  311.                 if orderType[i] == 1 then
  312.                     call IssueTargetOrderById( new, lastOrder, orderTarget[i] )
  313.                 elseif orderType[i] == 2 then
  314.                     call IssuePointOrderById( new, lastOrder, targPointX[i], targPointY[i] )
  315.                 elseif orderType[i] == 3 then
  316.                     call IssueImmediateOrderById( new, lastOrder )
  317.                 endif
  318.                 if IsUnitSelected( u, GetLocalPlayer() ) then
  319.                     call SelectUnit( new, true )
  320.                 endif
  321.                 set maxTargeterCount[i] =  0
  322.                 set index = GetUnitId( new )
  323.                 set deathSFX[index] = deathSFX[i]
  324.                 set showDeath[index] = showDeath[i]
  325.                 //! endtextmacro
  326.                 //! runtextmacro REDIRECTDATA( "key", "GetWidgetLife( u )", "GetUnitState( u, UNIT_STATE_MANA )" )
  327.                 call hash.remove( timerKey )
  328.                 set showDeath[i] = false
  329.                 call RemoveUnit( u )
  330.                 call DestroyTimer( t )
  331.                 if u == illusion then
  332.                     set illusion = new
  333.                 endif
  334.                 set new = null
  335.             endif
  336.         else
  337.             call hash.remove( timerKey )
  338.             call RemoveUnit( u )
  339.             call DestroyTimer( t )
  340.         endif
  341.         set t = null
  342.         set u = null
  343.     endfunction
  344.  
  345.  
  346.     ////////////////////
  347.     // After Creation //
  348.     ////////////////////
  349.     private function OnSummon takes nothing returns boolean
  350.         local integer i
  351.         local integer uDex
  352.         if GetSummoningUnit() == dummyCaster then
  353.             set i = GetUnitId( dummyCaster )
  354.             set U = GetTriggerUnit()