• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Firing Trigger

Status
Not open for further replies.
Level 5
Joined
Sep 27, 2011
Messages
141
Hi everyone
I was wondering if anybody could create a trigger that is able to detect units or destructables in a straight line and their verticle height(For headshot etc) and add them to a group it would be best if you were unable to detect units/destructables behind cliffs or other objects or cliffs.
I havent been on in a while but thanks in advance if anyone can solve this problem.
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
for detecting in straight line u must use timer and jump foward each time +25 range example, and check if in 25 range have any unit or no

for cliff thing easily u can save in begining of the ability the cliff height where is ur unit then in timer loop u just allways check if it is same than cliff height in next location

i uploaded a map and here a trigger (here ur unit move foward 600 range and deal damage to every unit on way)

JASS:
function Trig_Distance_Shrink_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A00D'
endfunction

function Shrinking takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer id = GetHandleId(t)
    local integer cv
    local unit u = LoadUnitHandle(udg_Spell_Table, id, 1)
    local unit pu
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local real ang = LoadReal(udg_Spell_Table, id, 2)
    local real nx = LoadReal(udg_Spell_Table, id, 5) + 50 * Cos(ang * bj_DEGTORAD)
    local real ny = LoadReal(udg_Spell_Table, id, 6) + 50 * Sin(ang * bj_DEGTORAD)
    local real distance = LoadReal(udg_Spell_Table, id, 3) - 50
    local integer cliff = LoadInteger(udg_Spell_Table, id, 4)

    if distance > 0 and IsTerrainWalkable(nx, ny) and cliff==GetTerrainCliffLevel(nx, ny) then
        call SaveReal(udg_Spell_Table, id, 3, distance)
        call SaveReal(udg_Spell_Table, id, 5, nx)
        call SaveReal(udg_Spell_Table, id, 6, ny)
        call GroupEnumUnitsInRange(udg_UG, nx, ny, 60, null)
        loop
            set pu = FirstOfGroup(udg_UG)
            exitwhen (pu==null)
            if IsUnitEnemy(pu, GetOwningPlayer(u)) then
                set cv = GetUnitUserData(pu)
                if LoadInteger(udg_Misc_Table, id, cv) == 0 then
                    call UnitDamageTarget(u, pu, 100.00, true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
                endif
                call SaveInteger(udg_Misc_Table, id, cv, 1)
            endif
            call GroupRemoveUnit(udg_UG, pu)
        endloop
        call DestroyEffect(AddSpecialEffect ("Abilities\\Spells\\Orc\\Shockwave\\ShockwaveMissile.mdl", nx , ny))
        call TimerStart(t, 0.03, false, function Shrinking)

    else
        call SetUnitVertexColor(u, 255, 255, 255, 255)
        if GetLocalPlayer() == GetOwningPlayer(u) then
            call ClearSelection()
            call SelectUnit(u, true)
        endif
        call SetUnitPosition(u, nx, ny)
        call PauseTimer(t)
        call DestroyTimer(t)
        call FlushChildHashtable(udg_Spell_Table, id)
        call FlushChildHashtable(udg_Misc_Table, id)
    endif

    set t = null
    set u = null
    set pu = null
endfunction

function Trig_Distance_Shrink_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real ang = GetUnitFacing(u)
    local integer cliff = GetTerrainCliffLevel(GetUnitX(u), GetUnitY(u))
    local timer t = CreateTimer()
    local integer id = GetHandleId(t)
    local real distance = 600.00

    call SetUnitVertexColor(u, 255, 255, 255, 0)

    call SaveUnitHandle(udg_Spell_Table, id, 1, u)
    call SaveReal(udg_Spell_Table, id, 2, ang)
    call SaveReal(udg_Spell_Table, id, 3, distance)
    call SaveInteger(udg_Spell_Table, id, 4, cliff)
    call SaveReal(udg_Spell_Table, id, 5, GetUnitX(u))
    call SaveReal(udg_Spell_Table, id, 6, GetUnitY(u))
    call TimerStart(t, 0.03, false, function Shrinking)

    set u = null
    set t = null
endfunction

//===========================================================================
function InitTrig_Distance_Shrink takes nothing returns nothing
    set gg_trg_Distance_Shrink = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Distance_Shrink, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Distance_Shrink, Condition( function Trig_Distance_Shrink_Conditions ) )
    call TriggerAddAction( gg_trg_Distance_Shrink, function Trig_Distance_Shrink_Actions )
endfunction

in map header i used getterrainwalkable function for detect if have anything on way
(thx to Magtheridon96)

JASS:
function HideBothersomeItem takes nothing returns nothing
    if IsItemVisible(GetEnumItem()) then
        set udg_TW_hidden[udg_TW_hiddenMax] = GetEnumItem()
        call SetItemVisible(udg_TW_hidden[udg_TW_hiddenMax], false)
        set udg_TW_hiddenMax = udg_TW_hiddenMax + 1
    endif
endfunction

function IsTerrainWalkable takes real x, real y returns boolean
    
    call MoveRectTo(udg_TW_r, x, y)
    call EnumItemsInRect(udg_TW_r, null, function HideBothersomeItem)

    call SetItemPosition(udg_TW_check, x, y)//this unhides the item...
    set udg_TW_X=GetItemX(udg_TW_check)
    set udg_TW_Y=GetItemY(udg_TW_check)
    call SetItemVisible(udg_TW_check, false)//...so we must hide it again
    
    loop
        exitwhen udg_TW_hiddenMax <= 0
        set udg_TW_hiddenMax = udg_TW_hiddenMax - 1
        call SetItemVisible(udg_TW_hidden[udg_TW_hiddenMax], true)
        set udg_TW_hidden[udg_TW_hiddenMax] = null
    endloop
    
    return (x - udg_TW_X) * (x - udg_TW_X) + (y - udg_TW_Y) * (y - udg_TW_Y) < udg_TW_MAX_RANGE * udg_TW_MAX_RANGE
endfunction

function InitTrig_initTerrainWalk takes nothing returns nothing
    set udg_TW_MAX_RANGE = 10
    set udg_TW_X = 0
    set udg_TW_Y = 0
    set udg_TW_r = Rect(0, 0, 128, 128)
    set udg_TW_check = CreateItem('ciri', 0, 0)
    call SetItemVisible(udg_TW_check, false)
    set udg_TW_hiddenMax = 0 
endfunction

(in map init u must use custom script for call initTerrainWalk() function, or just give the values directly in gui)

if u want detect only the cliff then ignore the 2nd jass tag
 

Attachments

  • a_new_spellPack.w3x
    74.7 KB · Views: 33
Status
Not open for further replies.
Top