Trigger Help

thef1titan

New Member
Reaction score
0
Ok, im new to Jass and i've run in to a problem
Im trying to make a trigger where if the spell target's life is 1/6 of max or less then will change to the triggering units player and be moved to a storage area. Also to work it requires an item in item slot 1,2 or 3 and replaces it with an item that smmons the unit.

JASS:

function SpellChk1 takes nothing returns boolean
    if( not( GetSpellAbilityId() == 'A000')) then
        return false
    endif
        return true
endfunction

function CaptureChkS1 takes nothing returns boolean
    if ( not( GetItemTypeId( UnitItemInSlotBJ( GetTriggerUnit(), 1)) == 'I001')) then
        return false
    endif
        return true
endfunction

function CaptureChkS2 takes nothing returns boolean
    if ( not( GetItemTypeId( UnitItemInSlotBJ( GetTriggerUnit(), 2)) == 'I001')) then
        return false
    endif
        return true
endfunction

function CaptureChkS3 takes nothing returns boolean
    if ( not( GetItemTypeId( UnitItemInSlotBJ( GetTriggerUnit(), 3)) == 'I001')) then
        return false
    endif
        return true
endfunction

function Rate takes nothing returns boolean
    if ( not( R2I(GetUnitStateSwap(UNIT_STATE_LIFE, GetSpellTargetUnit())) <= (R2I(GetUnitStateSwap(UNIT_STATE_MAX_LIFE, GetSpellTargetUnit())) * (1/6)))) then
        return false
    endif
        return true
endfunction

function Red2 takes nothing returns boolean
    if (not(GetOwningPlayer(GetTriggerUnit()) == Player(0))) then               
        return false
    endif
        return true
endfunction

//End Conditions

function CaptureS1 takes nothing returns nothing
local unit u
local unit t = GetSpellTargetUnit()
    if ( Rate()) then
        if (CaptureChkS1()) then
            call CreateNUnitsAtLoc( 1, 'h000', GetOwningPlayer(u), GetUnitLoc(t), bj_UNIT_FACING)
            call UnitApplyTimedLife(GetLastCreatedUnit(), 'BTLF', 1)
            call IssueTargetOrderBJ(GetLastCreatedUnit(), "charm", t)
            call SetUnitPositionLoc( t , GetRectCenter( gg_rct_Pokemon_Stores))
            set u = GetTriggerUnit()
            call TriggerSleepAction( 1/10 )
            call UnitAddItemByIdSwapped( 'I004', u) 
            if ( Red2()) then
                set udg_RSlot1=t
                return
            endif
        
        endif

        if (CaptureChkS2()) then
            call CreateNUnitsAtLoc( 1, 'h000', GetOwningPlayer(u), GetUnitLoc(t), bj_UNIT_FACING)
            call UnitApplyTimedLife(GetLastCreatedUnit(), 'BTLF', 1)
            call IssueTargetOrderBJ(GetLastCreatedUnit(), "charm", t)
            call SetUnitPositionLoc( t , GetRectCenter( gg_rct_Pokemon_Stores))
            call RemoveItem( UnitItemInSlotBJ(GetTriggerUnit(), 2))
            call TriggerSleepAction( 1/10 )
            call UnitAddItemByIdSwapped( 'I004', u) 
            if ( Red2()) then
                set udg_RSlot2=t
                return
            endif
            
        endif
        if ( CaptureChkS3()) then
            call CreateNUnitsAtLoc( 1, 'h000', GetOwningPlayer(u), GetUnitLoc(t), bj_UNIT_FACING)
            call UnitApplyTimedLife(GetLastCreatedUnit(), 'BTLF', 1)
            call IssueTargetOrderBJ(GetLastCreatedUnit(), "charm", t)
            call SetUnitPositionLoc( t , GetRectCenter( gg_rct_Pokemon_Stores))
            call RemoveItem( UnitItemInSlotBJ(u, 3))
            call TriggerSleepAction( 1/10 )
            call UnitAddItemByIdSwapped( 'I004', u) 
            if ( Red2()) then
                set udg_RSlot3=t
                return
            endif
            
        endif
    endif            
endfunction

//Trigger

function InitTrig_RegCapt takes nothing returns nothing
    set gg_trg_RegCapt = CreateTrigger (  )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_RegCapt, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition( gg_trg_RegCapt, Condition(function SpellChk1))
    call TriggerAddAction(gg_trg_RegCapt, function CaptureS1)
endfunction


On a side note: How can i change attack types, like instead of Normal, its fire? Same with armor. (I HAVE looked around, couldnt find it)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top