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

[JASS] Jass Trigger Help.

Status
Not open for further replies.
Level 2
Joined
Jun 6, 2006
Messages
14
JASS:
function Trig_Bloodline_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A05K'        
endfunction

function Bloodline_Effects takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = GetHandleUnit(t, "u")
    local unit v = GetHandleUnit(t, "v")
    local location l = GetHandleLocation(t,"l")
    local integer i = GetHandleInt(t, "i")
    call SetUnitLifeBJ( u, GetUnitStateSwap(UNIT_STATE_LIFE, u) + ( (.04 * i ) * DistanceBetweenPoints(GetUnitLoc(v), l) ) )
    if UnitHasBuffBJ(v, 'B012') == true then
        if GetBooleanOr(GetLocationX(GetUnitLoc(v)) != GetLocationX(l),GetLocationY(GetUnitLoc(v)) != GetLocationY(l)) then
            call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Human\\HumanBlood\\BloodElfSpellThiefBlood.mdl",v,"chest"))    
        endif
    endif         
    set l = GetUnitLoc(v)
    call SetHandleHandle(t, "l", l) 
    set t = null
    set u = null
    set v = null                  
endfunction

function Trig_Bloodline_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local unit u = GetTriggerUnit()
    local unit v = GetSpellTargetUnit()
    local integer i = GetUnitAbilityLevelSwapped('A05K', u)
    local location l = GetUnitLoc(v)
    call SetHandleHandle(t, "u", u)
    call SetHandleHandle(t, "v", v)
    call SetHandleInt(t, "i", i)
    call SetHandleHandle(t, "l", l)
    call TimerStart(t, 0.04, true, function Bloodline_Effects)
    call TriggerSleepAction( ( ( 5.00 * I2R(i) ) )
    call FlushHandleLocals(t)
    call PauseTimer(t)
    call DestroyTimer(t)
    set t = null
    set u = null
    set v = null
    call RemoveLocation(l)
    set l = null
endfunction

//===========================================================================
function InitTrig_Bloodline takes nothing returns nothing
    set gg_trg_Bloodline = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Bloodline, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Bloodline, Condition( function Trig_Bloodline_Conditions ) )
    call TriggerAddAction( gg_trg_Bloodline, function Trig_Bloodline_Actions )
endfunction

I am very new to Jass, and this is the first trigger I have made, but when I save it, all that happens is a bunch of errors come up saying "Expected endif" "Expected name" etc. Can someone help me fix up this code? (The code is supposed to target a unit, and check every .04 seconds on how far they have moved and heal the caster of the spell by that much distance, lasting 5 seconds per level.)
 
Last edited by a moderator:
Level 2
Joined
Jan 29, 2009
Messages
21
You forgot an end parenthesis on the line "call TriggerSleepAction( ( ( 5.00 * I2R(i) ) )" (it should be "call TriggerSleepAction( ( ( 5.00 * I2R(i) ) ) )")

Also, I don't think there's a GetHandleLocation function (unless you wrote it)

Other than that though it compiles just fine on my WE. Do you have NewGen world edit / vJass?
 
Level 6
Joined
Mar 20, 2008
Messages
208
Post the errors.

If you don't know what newgen or vjass is, then odds are you do not have them. Which means your sethandle functions are invalid.

On a side note, it looks like you are removing the location L while the timer is still using it.
I am not sure, but I think that timer might go off on a seperate thread, while the rest of the trigger finishes, someone correct me if I'm wrong.
 
Level 14
Joined
Nov 18, 2007
Messages
816
Those GetHandleSomething() are LHV functions. Where did you put those functions?
JASS:
GetBooleanOr(GetLocationX(GetUnitLoc(v)) != GetLocationX(l),GetLocationY(GetUnitLoc(v)) != GetLocationY(l))
could also be
JASS:
GetLocationX(GetUnitLoc(v)) != GetLocationX(l) or GetLocationY(GetUnitLoc(v)) != GetLocationY(l)
call TriggerSleepAction( ( ( 5.00 * I2R(i) ) )-->call TriggerSleepAction(5*i)

Irrelevant side-note: Switch to vJass, you will not regret it. No more stupid LHV functions. No more Destroying of timers or groups. No more I2H(). Your code will get 200% safer, just by using the things vJass offers.
 
Level 2
Joined
Jan 29, 2009
Messages
21
Post the errors.

If you don't know what newgen or vjass is, then odds are you do not have them. Which means your sethandle functions are invalid.

On a side note, it looks like you are removing the location L while the timer is still using it.
I am not sure, but I think that timer might go off on a seperate thread, while the rest of the trigger finishes, someone correct me if I'm wrong.

You are correct, I'm fairly sure that if you destroy the location right after you attach it to the timer the reference to the location will be destroyed and you'll never be able to use it (its not like calling a function where its passed by value).

And in order for this code to work, you need vJass / NewGen (They come in a pack together I believe, or at least that's how I got 'em).

You can download it all here: http://www.wc3campaigns.net/showthread.php?t=90999

Hope this helps!
 
Level 2
Joined
Jun 6, 2006
Messages
14
I got NewGen and I still cannot seem to get it to work. I don't know if someone can fix this entire trigger for me, and I don't know if its allowed to ask that, but I think I am going to give up on Jass because it is difficult to learn and use without having prior experience to another coding language etc.
 
Level 2
Joined
Jan 29, 2009
Messages
21
Whats going wrong that you can't seem to work?

And yes- learning JASS (especially without coding experience) is frustrating at times, but stick with it. It's infinitely useful, and once you learn it you realize how restricting GUI really is. There's plenty of tutorials here to give you all the hints you need.
 
Level 14
Joined
Nov 18, 2007
Messages
816
JASS:
library Bloodline initializer Init uses TimerUtils
    
    globals
        private constant    integer                 AID                 = 'A05K'
        private constant    integer                 BID                 = 'B012'
        private             real            array   DURATION            //
        private             real            array   HEAL_PERCENTAGE     //
        private constant    real                    TICK                = 0.03125
        private constant    string                  BLOOD_FX            = "Objects\\Spawnmodels\\Human\\HumanBlood\\BloodElfSpellThiefBlood.mdl"
        private constant    string                  BLODD_FX_ATTPT      = "chest"
    endglobals
    
    private function SetUpDURATION takes nothing returns nothing
        set DURATION[1]=5.
        set DURATION[2]=10.
        set DURATION[3]=15.
        // add more levels if required
    endfunction
    
    private function SetUpHEAL_PERCENTAGE takes nothing returns nothing
        set HEAL_PERCENTAGE[1]=0.04
        set HEAL_PERCENTAGE[2]=0.08
        set HEAL_PERCENTAGE[3]=0.12
        // add more levels if required
    endfunction
    
    private function Duration takes integer level returns real
        return DURATION[level]
    endfunction
    
    private function Heal_Percentage takes integer level returns real
        return HEAL_PERCENTAGE[level]
    endfunction
    
    private struct Data
        timer t
        unit u
        unit v
        integer l
        real x
        real y
        
        real c
    endstruct
    
    private function Cond takes nothing returns boolean
        return GetSpellAbilityId() == AID
    endfunction

    private function Callback takes nothing returns nothing
    local Data s = GetTimerData(GetExpiredTimer())
    local real d=SquareRoot(((GetUnitX(s.v)-s.x)*(GetUnitX(s.v)-s.x))+((GetUnitY(s.v)-s.y)*(GetUnitY(s.v)-s.y)))
        call SetWidgetLife(s.u, GetWidgetLife(s.u)+(Heal_Percentage(s.l)*d))
        set s.x=GetUnitX(s.v)
        set s.y=GetUnitY(s.v)
        if GetUnitAbilityLevel(s.v, BID)>0 and d>0 then
            call DestroyEffect(AddSpecialEffectTarget(BLOOD_FX,s.v,BLOOD_FX_ATTPT))
        endif
        set s.c=s.c+TICK
        if s.c>Duration(s.l) then
            set s.u=null
            set s.v=null
            call ReleaseTimer(s.t)
            call s.destroy()
        endif
    endfunction

    private function Actions takes nothing returns nothing
    local Data s=Data.create()
        set s.t=NewTimer()
        set s.u=GetTriggerUnit()
        set s.v=GetSpellTargetUnit()
        set s.l=GetUnitAbilityLevel(s.u, AID)
        set s.x=GetUnitX(s.v)
        set s.y=GetUnitY(s.v)
        set s.c=0
        call SetTimerData(s.t, s)
        call TimerStart(s.t, TICK, true, function Callback)
    endfunction

    //===========================================================================
    private function Init takes nothing returns nothing
    local trigger t=CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(t, Condition(function Cond))
        call TriggerAddAction(t, function Actions)
        
        // SetUp spell constants
        call SetUpDURATION()
        call SetUpHEAL_PERCENTAGE()
    endfunction
    
endlibrary
That should work.
Edit: bugfix
 
Last edited:
Level 2
Joined
Jun 6, 2006
Messages
14
Thank you very much, the way you coded it looks a lot different than how I have seen it, I will look over it and learn from it.

Edit: I tried to put it in NewGen editor, and it comes up with errors on every single line. Is there some specific way I need to implement this?
 
Last edited:
Status
Not open for further replies.
Top