library IllusionSystem requires ListModule
/****************************************************/****************************************************************************************
System coded by Robbepop.
Please give credits if you use it in your map! ;-)
Requires:
- List Module
- One object data ability. (just copy and paste)
- One global dummy unit. (... if you don't already have one)
- vJass knowledge. (The system's coding is possible with Gui, too.)
This system allows you to create variable illusions with just one object of an ability.
See in the 'test' trigger how to do so.
Via the global variable 'lastCreatedIllusion' you have access to the illsion you have
lastly created with this system and are able to perform several actions.
This is also shown in the 'test' trigger.
There are some variable factors for illusions.
However, due to the wc3 mechanics not too many ...
You can scale the duration of an illusion,
the damage factor and the hit factor.
There are 3 possible values for the damage factor, 1.0, 2.0 or 3.0 to decide if your
illusion shell takes damage as normal (1.0) or with a factor of 2.0 or 3.0.
Possible values for the hit factor are 0, 0.1, 0.2, 0.3 ... 0.9 and 1.0.
This is the value which decides how much attack damage your illusion will deal.
To create illusion without a timed life just use a negative duration as parameter e.g. -1.
Im sorry that there are not more options and possibilities but I hope this system allows
illusions which are variable enough to make this system useful for you. =)
*******************************************************************************************/
globals
private constant integer DUMMY_ID = 'n000' //Configure this to your dummy's id.
private constant integer ILLU_ABIL = 'A000' //Change this value to your copy's id.
unit lastCreatedIllusion
endglobals
struct Illusion
implement List
private unit Dummy
private real IlluDuration
private method destroy takes nothing returns nothing
//Var Clearing
call KillUnit(.Dummy)
set .Dummy = null
//List Modul
call .listRemove()
//Deallocate
call .deallocate()
endmethod
static method create takes unit target, real dmgfactor, real hitfactor, real dur returns thistype
//Var Init
local thistype this = 0
//Check for possible values:
if dmgfactor >= 1. and dmgfactor <= 3. and hitfactor >= 0. and hitfactor <= 1. then
//Var Setting
set this = thistype.allocate()
//List Modul
call .listAdd()
//Var Setting
set .Dummy = CreateUnit(GetOwningPlayer(target), DUMMY_ID, GetUnitX(target), GetUnitY(target), 0)
set .IlluDuration = dur
//Create Illusion
call UnitAddAbility(.Dummy, ILLU_ABIL)
call SetUnitAbilityLevel(.Dummy, ILLU_ABIL, R2I((dmgfactor * 11) + (hitfactor * 10) - 10))
call IssueTargetOrderById(.Dummy, 852274, target)
//Error: forbidden values:
else
debug call BJDebugMsg("|cffff0000Error:|r Used forbidden values to create an illusion!")
endif
//Return
return this
endmethod
private static method GetDummyId takes unit check returns thistype
local thistype this = thistype.first
loop
exitwhen this == 0
if check == .Dummy then
return this
endif
set this = this.next
endloop
return 0
endmethod
private static method main takes nothing returns nothing
//Var Init
local unit dummy = GetSummoningUnit()
local thistype this = GetDummyId(dummy)
//Check for true illusion:
if this > 0 then
//Var Setting
set lastCreatedIllusion = GetTriggerUnit()
//Set Illu Duration
if .IlluDuration >= 0 then
call UnitApplyTimedLife(lastCreatedIllusion, 'Blil', .IlluDuration)
endif
//Remove Dummy
call this.destroy()
endif
//Clear
set dummy = null
endmethod
private static method onSummoning takes nothing returns boolean
if IsUnitIllusion(GetTriggerUnit()) then
call thistype.main()
endif
return false
endmethod
private static method onInit takes nothing returns nothing
//Var Init
local trigger t
//Trigger Init
set t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SUMMON)
call TriggerAddCondition(t, Condition(function thistype.onSummoning))
//Ability Init
set bj_lastCreatedUnit = CreateUnit(Player(12), DUMMY_ID, 0, 0, 0)
call UnitAddAbility(bj_lastCreatedUnit, ILLU_ABIL)
call RemoveUnit(bj_lastCreatedUnit)
//Clear
set t = null
endmethod
endstruct
/****************************************************/****************************************************************************************
You can use these two functions to create an illusion with just one line of code in
vJass and to get the last created illusion with this system. Note: illusions created
from other sources won't get saved as a 'lastCreatedIllusion'!
****************************************************************************************/
function GetLastCreatedIllusion takes nothing returns unit
return lastCreatedIllusion
endfunction
function CreateIllusion takes unit target, real d, real h, real dur returns Illusion
local Illusion
[b]Keywords:[/b]
illusion, vJass, create, unit, copy, paste, illu, system