• 🏆 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!

[JASS] I can't make a JASS version of this trigger

Status
Not open for further replies.
Level 5
Joined
Jan 27, 2007
Messages
154
I'm just a noob with JASS, i'm trying my best to comprehend but it seems that the slow way is still the best.
I'm trying to make a JASS version of this skill but I seems to fail.. My syntax is always wrong...

Trigger Version:
  • Triggers:
  • Unit - A unit Is attacked
  • Conditions
    • ((Attacking unit) has buff Kusanagi Chidori ) Equal to True
  • Actions:
    • Set Lycast = (Position of (Triggering unit))
    • Unit - Create 1 Peasant for (Owner of (Attacking unit)) at Lycast facing (Facing of (Attacking unit)) degrees
    • Unit - Hide (Last created unit)
    • Unit - Order (Last created unit) to Human Mountain King - Storm Bolt (Attacked unit)
    • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
    • Custom script: call RemoveLocation(udg_Lycast)
The JASS that I always fail:
JASS:
function Trig_Lyghtning_Conditions takes nothing returns boolean
    if ( not ( UnitHasBuffBJ(GetAttacker(), 'A005') == true ) ) then
       return false
    endif
    return true
    return GetSpellAbilityId() == 'A004'
endfunction

function Trig_Lyghtning_Actions takes nothing returns nothing
endfunction

//===========================================================================
function InitTrig_Lyghtningi takes nothing returns nothing 
    set gg_trg_Lyghtning = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Lyghtning, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Lyghtning, Condition( function Trig_Lyghtning_Conditions ) )
    call TriggerAddAction( gg_trg_Lyghtning, function Trig_Lyghtning_Actions ) 
    local unit u = CreateUnitAtLoc(GetTriggerPlayer(), 'h002', GetSpellTargetLoc(), 0.00)
    call SetUnitPositionLoc(GetLastCreatedUnit(), GetUnitLoc(GetTriggerUnit()))
    set u = null
    set s = null
 
Last edited:
Level 22
Joined
Dec 31, 2006
Messages
2,216
You are missing an "endfunction" at the bottom of the JASS trigger, locals must be at the top of a function, there's an error in your "function Init_Trig...", GetTriggerPlayer() will not return the owner and it cannot be used in an InitTrig function and the local variable "s" isn't defined.
JASS:
function InitTrig_Lyghtningi takes nothing returns nothing //Remove the "i" after "InitTrig_Lyghtning"
    set gg_trg_Lyghtning = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Lyghtning, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Lyghtning, Condition( function Trig_Lyghtning_Conditions ) )
    call TriggerAddAction( gg_trg_Lyghtning, function Trig_Lyghtning_Actions )
//==================
    local unit u = CreateUnitAtLoc(GetTriggerPlayer(), 'h002', GetSpellTargetLoc(), 0.00)
//==================
    call SetUnitPositionLoc(GetLastCreatedUnit(), GetUnitLoc(GetTriggerUnit()))
    set u = null
    set s = null //This isn't defined
endfunction //You forgot this

Your condition won't work correctly.
JASS:
function Trig_Lyghtning_Conditions takes nothing returns boolean
    if ( not ( UnitHasBuffBJ(GetAttacker(), 'A005') == true ) ) then
       return false //The function will stop here
    endif
    return true //Or here
    return GetSpellAbilityId() == 'A004' //And this will never happen
endfunction
And your GUI trigger and your JASS trigger (if it had worked) will do something totally different.

Fixed and optimized version:
JASS:
function Trig_Lyghtning_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetAttacker(), 'A005') > 0
endfunction

function Trig_Lyghtning_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local unit u2 = CreateUnit(p, 'h002', x, y, 0.)
    call IssueTargetOrder(u2, "thunderbolt", u)
    call UnitApplyTimedLife(u2, 'BTLF', 1.)
    set u = null
    set p = null
    set u2 = null
endfunction

//===========================================================================
function InitTrig_Lyghtning takes nothing returns nothing
    set gg_trg_Lyghtning = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Lyghtning, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Lyghtning, Condition( function Trig_Lyghtning_Conditions ) )
    call TriggerAddAction( gg_trg_Lyghtning, function Trig_Lyghtning_Actions )
endfunction
 
Level 5
Joined
Jan 27, 2007
Messages
154
You are missing an "endfunction" at the bottom of the JASS trigger, locals must be at the top of a function, there's an error in your "function Init_Trig...", GetTriggerPlayer() will not return the owner and it cannot be used in an InitTrig function and the local variable "s" isn't defined.
JASS:
function InitTrig_Lyghtningi takes nothing returns nothing //Remove the "i" after "InitTrig_Lyghtning"
    set gg_trg_Lyghtning = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Lyghtning, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Lyghtning, Condition( function Trig_Lyghtning_Conditions ) )
    call TriggerAddAction( gg_trg_Lyghtning, function Trig_Lyghtning_Actions )
//==================
    local unit u = CreateUnitAtLoc(GetTriggerPlayer(), 'h002', GetSpellTargetLoc(), 0.00)
//==================
    call SetUnitPositionLoc(GetLastCreatedUnit(), GetUnitLoc(GetTriggerUnit()))
    set u = null
    set s = null //This isn't defined
endfunction //You forgot this

Your condition won't work correctly.
JASS:
function Trig_Lyghtning_Conditions takes nothing returns boolean
    if ( not ( UnitHasBuffBJ(GetAttacker(), 'A005') == true ) ) then
       return false //The function will stop here
    endif
    return true //Or here
    return GetSpellAbilityId() == 'A004' //And this will never happen
endfunction
And your GUI trigger and your JASS trigger (if it had worked) will do something totally different.

Fixed and optimized version:
JASS:
function Trig_Lyghtning_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetAttacker(), 'A005') > 0
endfunction

function Trig_Lyghtning_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local unit u2 = CreateUnit(p, 'h002', x, y, 0.)
    call IssueTargetOrder(u2, "thunderbolt", u)
    call UnitApplyTimedLife(u2, 'BTLF', 1.)
    set u = null
    set p = null
    set u2 = null
endfunction

//===========================================================================
function InitTrig_Lyghtning takes nothing returns nothing
    set gg_trg_Lyghtning = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Lyghtning, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Lyghtning, Condition( function Trig_Lyghtning_Conditions ) )
    call TriggerAddAction( gg_trg_Lyghtning, function Trig_Lyghtning_Actions )
endfunction

thx!... I've learned much from you...

EDIT:
Oh, I forgot... The skill counts attack as executed even if the damage is not yet resolved, How I can solve this...
 
Last edited:
Level 21
Joined
Aug 21, 2005
Messages
3,699
The basic idea behind a damage detection system is simply adding the EVENT_UNIT_DAMAGED event to the trigger each time a unit enters the playable map. That way, each unit on the map will be registered. Pretty easy to implement that, but damage detection systems usually take care of some other things as well.
 
Status
Not open for further replies.
Top