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

[Solved] Trigger not working

Status
Not open for further replies.
Level 22
Joined
Feb 3, 2009
Messages
3,292
The bellow trigger is supposed to cast any spell casted towards a unit with MIMIC_SPELLID right back at the source and it's supposed to make a dummy cast any no target spell in 1000 AOE of a unit with MIMIC_SPELLID.

The first part works perfectly but the second part doesn't.
I believe the problem is somwhere in function MIMIC_COND.

Help appreciated.

JASS:
//=========================Mimic v1.2=========================
//============================================================
//====================Made by: Mckill2009=====================
//============================================================
//============================================================

//===HOW TO USE:
//- Create a HASH variable in the trigger editor
//- Initialize the HASH
//- Copy the Dummy Hero and Ability
//- make sure that the Hero and Ability has the RAW CODE 'H000' and 'A001' respectively
//  if not then you may change the MIMIC_SPELLID and MIMIC_DUMMYID raw codes
//- Make a new trigger and convert to custom text via EDIT >>> CONVERT CUSTOM TEXT
//- The trigger name MUST be >>> Mimic (or you may change it as long as it matches InitTrig_NAME_OF_TRIGGER below
//- Copy ALL that is written here (overwrite the existing texts in the trigger)
//- You may configure some things

//============================================================
//=======================CONFIGURABLES========================
//============================================================

function MIMIC_SPELLID takes nothing returns integer
    return 'A0F7' //This is the Hero ability ID
endfunction

function MIMIC_DUMMYID takes nothing returns integer
    return 'H06K' //This is the HERO DUMMY ID (IT MUST BE A HERO)
endfunction

function MIMIC_CHANCE takes nothing returns integer
    return 100 //This is the BASE CHANCE, adjust it if you want
endfunction

//============================================================
//====================END OF CONFIGURABLES====================
//============================================================

//=====This function is just to get the ORDER STRING of the spell so...
//=====DO NOT TOUCH THIS!
function MIMIC_ORDER_ID takes nothing returns nothing
    call SaveInteger(udg_HASH, GetHandleId(GetTriggerUnit()), 1, GetIssuedOrderId())
endfunction

//============================================================
//============================================================

function MIMIC_COND2 takes nothing returns boolean
call BJDebugMsg("Con2")
    return GetUnitAbilityLevel(GetFilterUnit(), MIMIC_SPELLID()) > 0
endfunction

function MIMIC_COND takes nothing returns boolean
 local group g = CreateGroup()
 local unit t = GetSpellTargetUnit()
 local boolean bool
 if (t == null) then
 set g = GetUnitsInRangeOfLocMatching(1000.0, GetSpellTargetLoc(), function MIMIC_COND2)
 set t = GroupPickRandomUnit(g)
 endif
 set bool = GetUnitAbilityLevel(t, MIMIC_SPELLID()) > 0 and (GetTriggerUnit() != GetSpellTargetUnit())
 if (bool == true) then
 call BJDebugMsg("true")
 endif
 call DestroyGroup(g)
 set t = null
 return bool
endfunction

function MIMIC_CAST takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local unit t = GetSpellTargetUnit() 
    local location l = GetSpellTargetLoc()
    local group g
    local unit dummy
    local integer ID = GetHandleId(GetTriggerUnit())
    local integer spellid = GetSpellAbilityId()
    local integer spellidlvl = GetUnitAbilityLevel(c, spellid)
    local integer spelllevel = 100
    if GetRandomInt(1, 100) <= spelllevel then 
    if (not (t == null)) and (not (l == null)) then
        call BJDebugMsg("3")
        call PlaySoundOnUnitBJ( gg_snd_SpellbreakerYesAttack3, 100, t )
        set dummy = CreateUnit(GetOwningPlayer(t), MIMIC_DUMMYID(), GetUnitX(t), GetUnitY(t), 0)
        call SetHeroLevel(dummy, 30, false)
        call UnitApplyTimedLife(dummy, 'BTLF', 10)
        call UnitAddAbility(dummy, spellid)
        call SetUnitAbilityLevel(dummy, spellid, spellidlvl) 
        call IssueTargetOrderById(dummy, LoadInteger(udg_HASH, ID, 1), c)  
    elseif (t == null) then
    call BJDebugMsg("1")
    set g = CreateGroup()
    set g = GetUnitsInRangeOfLocMatching(1000.0, l, function MIMIC_COND2)
    set t = GroupPickRandomUnit(g)
        if (not (t == null)) then
        call BJDebugMsg("2")
        call PlaySoundOnUnitBJ( gg_snd_SpellbreakerYesAttack3, 100, t )
        set dummy = CreateUnit(GetOwningPlayer(t), MIMIC_DUMMYID(), GetUnitX(t), GetUnitY(t), 0)
        call SetHeroLevel(dummy, 30, false)
        call UnitApplyTimedLife(dummy, 'BTLF', 10)
        call UnitAddAbility(dummy, spellid)
        call SetUnitAbilityLevel(dummy, spellid, spellidlvl) 
        call IssueImmediateOrderById(dummy, LoadInteger(udg_HASH, ID, 1))  
        endif
    endif
    endif
    call FlushChildHashtable(udg_HASH, ID)
    call RemoveLocation(l)
    call DestroyGroup(g)
    set c = null
    set t = null
    set dummy = null
endfunction

//==== Init Trigger Mimic ====

function InitTrig_Spell_Deflect takes nothing returns nothing
    local trigger t                         = CreateTrigger()      
    local trigger tt                        = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ      (t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition                (t, Condition(function MIMIC_COND))
    call TriggerAddAction                   (t, function MIMIC_CAST)
    call TriggerRegisterAnyUnitEventBJ      (tt, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)    
    call TriggerRegisterAnyUnitEventBJ      (tt, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
    call TriggerRegisterAnyUnitEventBJ      (tt, EVENT_PLAYER_UNIT_ISSUED_ORDER)
    call TriggerAddAction                   (tt, function MIMIC_ORDER_ID)    
    set t = null        
    set tt = null
endfunction
 
Status
Not open for further replies.
Top