- Joined
- Oct 12, 2011
- Messages
- 3,449
Description
Allows you to create any unit's illusion (mirror image). This snippet has one weakness: not working for magic immune units.
Requirements- Bribe's UnitIndexer
- My DDS
- JNGP
How to install- My DDS
- JNGP
- Copy "Code" trigger folder into your map
- Install all required libraries properly
- Import dummy.mdx into your map
- Copy all object editor datas into your map
- Make sure
Code- Install all required libraries properly
- Import dummy.mdx into your map
- Copy all object editor datas into your map
- Make sure
ILLUSION_ITEM
's ability is ILLUSION_ABILITY_1
JASS:
library Illusion /* v2.1.0 -by Dalvengyr
Description
¯¯¯¯¯¯¯¯¯¯¯
Allows you to freely create illusion (mirror image) of any non magic immune unit
Requirements
¯¯¯¯¯¯¯¯¯¯¯¯
- Bribe's UnitIndexer | hiveworkshop.com/forums/spells-569/gui-unit-indexer-1-2-0-2-a-197329/
- Dalve's DDS | hiveworkshop.com/forums/submissions-414/system-damagedetectsystem-261912/
How to use
¯¯¯¯¯¯¯¯¯¯
struct Illusion
1. Create illusion version of a unit type
| static method create takes player id, integer unitid, real x, real y, real face returns thistype
2. Create illusion based from an existing unit
| static method copy takes player id, unit whichUnit, real x, real y, real face returns thistype
Struct members
| readonly unit unit => unit instance of illusion
| real dealtFactor => dealt damage multiplier for the illusion
| real takenFactor => taken damage multiplier for the illusion
Link
¯¯¯¯
hiveworkshop.com/forums/submissions-414/snippet-illusion-256397/
*/
// ===================================================================== //
// //
// Configuration //
globals
// Based on their rawcode at Object Editor
private constant integer ITEM_ID = 'I000' // ILLUSION_ITEM
private constant integer SPELL_ID = 'A001' // ILLUSION_ABILITY_2
private constant integer DUMMY_ID = 'h000' // Dummy
endglobals
// //
// ===================================================================== //
// Furthermore, edit them by your own risk!
globals
private item Item
private unit Dummy
private boolean Detect = false
private constant player PASSIVE = Player(PLAYER_NEUTRAL_PASSIVE)
endglobals
native UnitAlive takes unit id returns boolean
struct Illusion
real dealtFactor
real takenFactor
readonly unit unit
private static real LocX
private static real LocY
private static thistype TempDex
private static thistype array Index
// Create illusion based on existing unit
static method copy takes player id, unit whichUnit, real x, real y, real face returns thistype
// If target is valid
if whichUnit != null and UnitAlive(whichUnit) then
// If target is not magic immune
if not(IsUnitType(whichUnit, UNIT_TYPE_MAGIC_IMMUNE)) then
// Prepare to detect created illusion
set TempDex = allocate()
set LocX = x
set LocY = y
set Detect = true
// Create illusion
call SetUnitPosition(Dummy, GetUnitX(whichUnit), GetUnitY(whichUnit))
call SetUnitOwner(Dummy, id, false)
call UnitUseItemTarget(Dummy, Item, whichUnit)
return TempDex
debug else
debug call BJDebugMsg("Failed to create Illusion :: Target is magic immune.")
endif
debug else
debug call BJDebugMsg("Failed to create Illusion :: Target is invalid.")
endif
return 0
endmethod
// Create new illusion
static method create takes player id, integer unitId, real x, real y, real face returns thistype
local unit dummy = CreateUnit(PASSIVE, unitId, 0, 0, face)
local thistype this = copy(id, dummy, x, y, face)
call RemoveUnit(dummy)
set dummy = null
return this
endmethod
// On damage event
private static method onDamage takes nothing returns boolean
local thistype data
// If damage source is a custom illusion
set data = GetUnitUserData(udg_DDS__Event__DamageSource)
if Index[data] != 0 then
set udg_DDS__Event__DamageAmount = udg_DDS__Event__DamageAmount*Index[data].dealtFactor
endif
// If damage target is a custom illusion
set data = GetUnitUserData(udg_DDS__Event__DamageTarget)
if Index[data] != 0 then
set udg_DDS__Event__DamageAmount = udg_DDS__Event__DamageAmount*Index[data].takenFactor
endif
return false
endmethod
// When unit is indexed
private static method onIndex takes nothing returns boolean
if Detect and IsUnitIllusion(udg_UDexUnits[udg_UDex]) then
set TempDex.unit = udg_UDexUnits[udg_UDex]
// Set default value
set TempDex.takenFactor = 1
set TempDex.dealtFactor = 1
set Index[GetUnitUserData(udg_UDexUnits[udg_UDex])] = TempDex
call SetUnitPosition(udg_UDexUnits[udg_UDex], TempDex.LocX, TempDex.LocY)
set Detect = false
endif
return false
endmethod
// When unit is deindexed
private static method onDeindex takes nothing returns boolean
local integer data = GetUnitUserData(GetTriggerUnit())
if Index[data] != 0 then
call Index[data].destroy()
set Index[data].unit = null
set Index[data] = 0
endif
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t
// Prepare the dummy caster
set Dummy = CreateUnit(PASSIVE, DUMMY_ID, 0, 0, 0)
set Item = CreateItem(ITEM_ID, 0, 0)
call UnitAddAbility(Dummy, SPELL_ID)
call UnitAddItem(Dummy, Item)
// On damage trigger
set t = CreateTrigger()
call TriggerRegisterVariableEvent(t, "udg_DDS__Event__Trigger", EQUAL, 1.00)
call TriggerAddCondition(t, Condition(function thistype.onDamage))
// On index trigger
set t = CreateTrigger()
call TriggerRegisterVariableEvent(t, "udg_UnitIndexEvent", EQUAL, 1.00)
call TriggerAddCondition(t, Condition(function thistype.onIndex))
// On deindex trigger
set t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(t, Condition(function thistype.onDeindex))
set t = null
endmethod
endstruct
endlibrary
JASS:
scope test
// I hope this demo can explain everything you need to know
function onDamage takes nothing returns boolean
call CreateTextTagUnitBJ(I2S(R2I(udg_DDS__Event__DamageAmount)), udg_DDS__Event__DamageTarget, 0, 10, 100, 100, 100, 0)
call SetTextTagVelocityBJ(GetLastCreatedTextTag(), 128.00, 90)
call SetTextTagPermanentBJ(GetLastCreatedTextTag(), false)
call SetTextTagLifespanBJ(GetLastCreatedTextTag(), 2.00)
call SetTextTagFadepointBJ(GetLastCreatedTextTag(), 1.00)
return false
endfunction
function create takes nothing returns nothing
local unit c = GetEnumUnit()
local Illusion u
if IsUnitType(c, UNIT_TYPE_HERO) then
// copy method is useful to copy entire data on a unit like level, carried items, attributes, etc.
set u = Illusion.copy(GetOwningPlayer(c), c, GetUnitX(c), GetUnitY(c), GetUnitFacing(c))
else
// while create is used to create entirely new illusion
set u = Illusion.create(GetOwningPlayer(c), GetUnitTypeId(c), GetUnitX(c), GetUnitY(c), GetUnitFacing(c))
endif
// Custom image is BIG
call SetUnitScale(u.unit, 2, 0, 0)
// Illusion takes 4x damage and deals half damage
set u.takenFactor = 4
set u.dealtFactor = 0.5
set c = null
endfunction
function Trig_Untitled_Trigger_001_Copy_Actions takes nothing returns nothing
local group g = GetUnitsSelectedAll(GetTriggerPlayer())
call ForGroup(g, function create)
call DestroyGroup(g)
set g = null
endfunction
function InitTrig_test takes nothing returns nothing
local trigger t = CreateTrigger()
call FogEnable(false)
call FogMaskEnable(false)
set gg_trg_test = CreateTrigger()
call TriggerRegisterPlayerEventEndCinematic(gg_trg_test, Player(0))
call TriggerAddAction(gg_trg_test, function Trig_Untitled_Trigger_001_Copy_Actions)
call TriggerRegisterVariableEvent(t, "udg_DDS__Event__Trigger", EQUAL, 1.00)
call TriggerAddCondition(t, Condition(function onDamage))
call DisplayTimedTextToPlayer(Player(0), 0, 0, 0, "Press 'esc' to create selected unit's illusion")
call DisplayTimedTextToPlayer(Player(0), 0, 0, 0, "- Create new illusion if unit is not a hero, will copy if hero")
call DisplayTimedTextToPlayer(Player(0), 0, 0, 0, "- Custom illusion takes 4x damage and deals half damage")
call DisplayTimedTextToPlayer(Player(0), 0, 0, 0, "- Using wand of illusion will create one additional illusion")
call DisplayTimedTextToPlayer(Player(0), 0, 0, 0, "- Custom illusions are BIG and don't have timed life")
endfunction
endscope
Attachments
Last edited: