• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Health Decrease

Status
Not open for further replies.
Level 8
Joined
Jun 16, 2008
Messages
333
How do you make a trigger where if you enter a certain terrain your health decreases slowly?

I have this much so far in jass
JASS:
 function Trig_Burn_Copy_Func002Func002Func005C takes nothing returns boolean
    return false
endfunction

function Trig_Burn_Copy_Func002Func002C takes nothing returns boolean
    if ( not ( IsUnitAliveBJ(GetEnumUnit()) == true ) ) then
        return false
    endif
    if ( not Trig_Burn_Copy_Func002Func002Func005C() ) then
        return false
    endif
    if ( not ( GetTerrainTypeBJ(udg_tempPoint) == 'Dlav' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Burn_Copy_Func002A takes nothing returns nothing
    set udg_tempPoint = GetUnitLoc(GetEnumUnit())
    if ( Trig_Burn_Copy_Func002Func002C() ) then
        call UnitDamageTargetBJ( GetEnumUnit(), GetEnumUnit(), 20.00, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
    else
        call RemoveLocation(udg_tempPoint)
        call DestroyGroup(udg_tempGroup)
    endif
endfunction

function Trig_Burn_Copy_Actions takes nothing returns nothing
    set udg_tempGroup = GetUnitsOfTypeIdAll('Edem')
    call ForGroupBJ( udg_tempGroup, function Trig_Burn_Copy_Func002A )
endfunction

//===========================================================================
function InitTrig_Burn_Copy takes nothing returns nothing
    set gg_trg_Burn_Copy = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Burn_Copy, 0.25 )
    call TriggerAddAction( gg_trg_Burn_Copy, function Trig_Burn_Copy_Actions )
endfunction

  • Terrain killer Events Time - Every 0.12 seconds of game time Conditions Actions Set tempGroup = (Units of type Paladin) Unit Group - Pick every unit in tempGroup and do (Actions) Loop - Actions Set tempPoint = (Position of (Picked unit)) If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions ((Picked unit) is alive) Equal to True Or - Any (Conditions) are true Conditions (Terrain type at (Position of (Picked unit))) Equal to Ashenvale - dungeon lava Then - Actions Unit - IDK Else - Actions Custom script: call RemoveLocation(udg_tempPoint) Custom script: call DestroyGroup(udg_tempGroup)
 
Last edited by a moderator:
Level 13
Joined
Jul 26, 2008
Messages
1,009
First way I can think of to do it is group every unit on the map in a periodic timer. Then check the X and Y of the units and if that point is the terraintype you're looking for. If it is, do damage.

JASS:
function BurnEm takes nothing returns nothing
    if GetTerrainType(GetUnitX(GetEnumUnit()), GetUnitY(GetEnumUnit())) == 'Dlav' then
        call SetWidgetLife(GetEnumUnit(), GetWidgetLife(GetEnumUnit()) - 20)
    endif
endfunction

function GroupEm takes nothing returns boolean
    if GetUnitTypeId(GetEnumUnit()) = 'Edem' and GetWidgetLife(GetEnumUnit()) > 0.405 then
        return true
    endif
 return false
endfunction

function Trig_Untitled_Trigger_001_Conditions takes nothing returns boolean
    local group g = CreateGroup()
    call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, function GroupEm)
    call ForGroup(g, function BurnEm)
    call DestroyGroup(g)
    set g = null
 return false
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Untitled_Trigger_001, 0.26 )
    call TriggerAddCondition( gg_trg_Untitled_Trigger_001, Condition( function Trig_Untitled_Trigger_001_Conditions ) )
endfunction
 
Ok, it should be like that:
JASS:
function BurnEm takes nothing returns nothing
    if GetTerrainType(GetUnitX(GetEnumUnit()), GetUnitY(GetEnumUnit())) == 'Dlav' then
        call SetWidgetLife(GetEnumUnit(), GetWidgetLife(GetEnumUnit()) - 20)
    endif
endfunction

function GroupEm takes nothing returns boolean
    if GetUnitTypeId(GetFilterUnit()) == 'Edem' and GetWidgetLife(GetFilterUnit()) > 0.405 then
        return true
    endif
 return false
endfunction

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    local group g = CreateGroup()
    call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, Filter (function GroupEm))
    call ForGroup(g, function BurnEm)
    call DestroyGroup(g)
    set g = null
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( t, 0.26 )
    call TriggerAddAction (t, function Trig_Untitled_Trigger_001_Actions)
endfunction

Test Map:
View attachment Terrain Damage [0] Jass.w3x

GUI version:
View attachment Terrain Damage.w3x
 
Status
Not open for further replies.
Top