• 🏆 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] Help for Project

Status
Not open for further replies.
Hi guys, here i am again. This time i have a spell, not for my map, but for the Pyrite's camp (i joined his project and i am helping him)

I am making evil aura. You can easily know what it is if you read the Brainstorm section.

Anyway, back to the point, the compiler reports 2 errors, the first error is in my second "if" statement, and my second error is in the "elseif" statement. I have no idea what is wrong. Please help me.

JASS:
globals 
    unit udg_Hero 
endglobals
//====================================================
function Armor_Acts takes nothing returns nothing
    local player owner = GetOwningPlayer(udg_Hero)  
    if GetSpellAbilityId() == 'DUM1' and GetTriggerUnit() == udg_Hero then //the ability used is the a dummy ability
        if GetUnitAbilityLevel(udg_Hero, 'ARAI' )== 1 or GetUnitAbilityLevel(udg_Hero, 'ARAD' )== 1 then  //if Armor aura increase or decrase lv is ==1
            UnitRemoveAbility(udg_Hero, 'B0K1')  //remove book1
            UnitAddAbility(udg_Hero, 'B0K2')  //add book2
            SetPlayerAbilityAvailable(owner, 'B0K2', false)  //disable book2
        elseif GetUnitAbilityLevel(udg_Hero, 'ARAI' )== 2 or GetUnitAbilityLevel(udg_Hero, 'ARAD' )== 2 then then
            UnitRemoveAbility(udg_Hero, 'B0K1')
            UnitAddAbility(udg_Hero, 'B0K2')
            SetPlayerAbilityAvailable(owner, 'B0K2', false)
        endif
    endif
    set owner = null
endfunction
//====================================================
function InitTrig_Armor takes nothing returns nothing
    local trigger Armor = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( Armor, EVENT_PLAYER_UNIT_SPELL_EFFECT )   
    call TriggerAddAction( Armor, function Armor_Acts )
    set Armor = null
    //the trigger is local, but will be set to global in firther versions
endfunction

Now, this spell is not MUI as well. Being MUI is not important (there will only be 1 hero using this aura), but still, i would like to make the spell MUI (if possible) because i would like to know how you can use Globals to make MUI spells.
It's just something i would like to know, but the really important thing here is the error reports ... i think i am not using the "and" and the "or" expression correctly, but i am not sure.
Please help.

Btw, long time no c mates =)
 
Mm ok guys. Now i have other problem ...
It looks that my script is 100% correct, but the result in game is not the result i would expect.

When the hero learns the dummy ability, he gets 2 auras. When he uses the dummy ability, the 2 auras switch.
This wouldn't be difficult to do, but i want to optimize it as best as i can and to avoid using memory.
My problem here are spellbooks.
When the hero learns the ability, it gets a spellbook with 2 auras. The spellbook is disabled and the auras don't show.
When the hero uses the dummy ability, the spell book1 is removed, and the spell book 2 is added with the same process.
In theory it works. But not in practice. Every time i use the dummy ability, i switch to spell book2, but there is always 1 aura that doesn't work. And i don't know why.

JASS:
function MyConds takes nothing returns boolean
    return GetSpellAbilityId() == 'AHtc'  //the ability used is the a dummy ability
endfunction
//================================
function MyActs takes nothing returns nothing
    local player owner = GetOwningPlayer(udg_Hero)  
    if GetUnitAbilityLevel(udg_Hero, 'A005' )== 1 then  //if Armor aura increase lv is ==1
        call UnitRemoveAbility(udg_Hero, 'A005')  //remove book1
        call TriggerSleepAction(1.25)
        call UnitAddAbility(udg_Hero, 'A004')  //add book2
        call SetUnitAbilityLevel(udg_Hero, 'A004', 1)
        call TriggerSleepAction(0.5)
        call SetPlayerAbilityAvailable(owner, 'A004', false)  //disable book2
    elseif GetUnitAbilityLevel(udg_Hero, 'A004' )== 1 then  //if Attack Aura increase lv is ==1
        call UnitRemoveAbility(udg_Hero, 'A004') //remove book 2
        call TriggerSleepAction(1.25)
        call UnitAddAbility(udg_Hero, 'A005')    //add book1
        call SetUnitAbilityLevel(udg_Hero, 'A005', 1)
        call TriggerSleepAction(0.5)
        call SetPlayerAbilityAvailable(owner, 'A005', false) //disable book 1
    endif
    set owner = null
endfunction
//===================================
function InitTrig_test takes nothing returns nothing
    local trigger EvilAura = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( EvilAura, EVENT_PLAYER_UNIT_SPELL_EFFECT )   
    call TriggerAddCondition(EvilAura, Condition(function MyConds))
    call TriggerAddAction( EvilAura, function MyActs )
    set EvilAura = null
    //the trigger is local, but will be set to global in firther versions
endfunction

Here is the code. I think that the problem is not the fact this trigger is local ( i will change that when i solve the problem).
Help ?
I don't know what is happening.
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
Umm auras based on same aura ?
oh wait why would you want to use same aura twice
may be for damage reducing (enemy) increasing(friendly)
well you need to avoid this I guess
(I tought base ability isnt a problem for passives but it seems like its well good luck with your ability)

I said these things because you seem sure about that spell book is changed So there must be something wrong with auras

And try testing with not disabled spell books to see what is problem
They are not added or ... well you know
 
Mmm, well i am forced to use the same aura, because i want its reverse effect. If not, i will have to create my own auras. Still it makes sense that the problem is in the auras ... however i doubt it as auras are not a spell, but passive abilities.

I will try that spell book thingy.



EDIT: BLARG this is beyond my comprehension... I did that book stuff. And when i use the ability, when i change the books, the book2 does NOT have the second aura ... why !? My second book only has 1 aura ... and it should have 2. If book1 can have two auras, why can't book2 !?

help !?
 
Last edited:
Level 19
Joined
Aug 24, 2007
Messages
2,888
well for example you are using command aura for attach increasing
try another aura that affects nearby units damage for reducing
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
try something
if unit has etc ability create a dummy make it cast slowing-attack reducing ability (or armor reducing) well howl of terror does some
anyway ...
 
That book idea solved my problems. Thx Need_O2. +rep.

Now guys i have here my triggers. They ALL work fine. However i want my process to be as best optimized as possible and therefore i post them here.

Please i am waiting for suggestions about how i can improve my spell. If you think you may have some post them and i will consider them.

Trigger 1 Level_up, when all starts:

JASS:
globals            //the global variable that marks the
    unit udg_Hero  //unit using the spell
endglobals
//=============================================
function LvUp_Conds takes nothing returns boolean
    return GetLearnedSkill() == 'AHtc'  //dummy ability learned
endfunction
//====================================================
function LvUp_Acts takes nothing returns nothing
    set udg_Hero = GetTriggerUnit() //sets the var. this will be needed when using/evolving the spell
    if GetUnitAbilityLevel(udg_Hero, 'AHtc' )== 1 then //if lv of dummy ability is == 1(the nit first learns the ability)
        call UnitAddAbility(udg_Hero, 'A004')  //adds book1
        call SetUnitAbilityLevel(udg_Hero, 'A004', 1) //sets lv of book1 to 1
    elseif GetUnitAbilityLevel(udg_Hero, 'AHtc' )== 2 then //Hero learns lv 2
        if GetUnitAbilityLevel(udg_Hero, 'A004' )==1 then  //if unit has book1 before learning
            call UnitRemoveAbility(udg_Hero, 'A004')  //removes book1
            call UnitAddAbility(udg_Hero, 'A004')    //adds book1
            call SetUnitAbilityLevel(udg_Hero, 'A004', 2) //sets lv of book1 to 2
            call SetUnitAbilityLevel(udg_Hero, 'A001', 2) //set lv of armour increase aura to 2
            call SetUnitAbilityLevel(udg_Hero, 'A003', 2) //set lv of attack decrease aura to 2
            //disable book1
        endif
        if GetUnitAbilityLevel(udg_Hero, 'A005' )== 1 then //if unit has book2 before learning
            call UnitRemoveAbility(udg_Hero, 'A005')  //removes book2
            call UnitAddAbility(udg_Hero, 'A005')    //adds book2
            call SetUnitAbilityLevel(udg_Hero, 'A005', 2) //sets lv of book2 to 2
            call SetUnitAbilityLevel(udg_Hero, 'A000', 2) //set lv of armour reduction aura to 2
            call SetUnitAbilityLevel(udg_Hero, 'A002', 2) //set lv of attack increase aura to 2
            //disable book2
        endif
    elseif GetUnitAbilityLevel(udg_Hero, 'AHtc' )== 3 then //Hero learns lv 3
        if GetUnitAbilityLevel(udg_Hero, 'A004' )== 2 then //if unit has book1 before learning
            call UnitRemoveAbility(udg_Hero, 'A004')  //removes book1
            call UnitAddAbility(udg_Hero, 'A004')    //adds book1
            call SetUnitAbilityLevel(udg_Hero, 'A004', 3) //sets lv of book1 to 3
            call SetUnitAbilityLevel(udg_Hero, 'A001', 3) //set lv of armour increase aura to 3
            call SetUnitAbilityLevel(udg_Hero, 'A003', 3) //set lv of attack decrease aura to 3
            //disable book1
        endif
        if GetUnitAbilityLevel(udg_Hero, 'A005' )== 2 then  //if unit has book2 before learning
            call UnitRemoveAbility(udg_Hero, 'A005')  //removes book2
            call UnitAddAbility(udg_Hero, 'A005')    //adds book2
            call SetUnitAbilityLevel(udg_Hero, 'A005', 3) //sets lv of book2 to 3
            call SetUnitAbilityLevel(udg_Hero, 'A000', 3) //set lv of armour reduction aura to 3
            call SetUnitAbilityLevel(udg_Hero, 'A002', 3) //set lv of attack increase aura to 3
            //disable book2
        endif
    elseif GetUnitAbilityLevel(udg_Hero, 'AHtc' )== 4 then //Hero learns level 4
        if GetUnitAbilityLevel(udg_Hero, 'A004' )== 3 then //if unit has book1 before learning
            call UnitRemoveAbility(udg_Hero, 'A004')  //removes book1
            call UnitAddAbility(udg_Hero, 'A004')    //adds book1
            call SetUnitAbilityLevel(udg_Hero, 'A004', 4) //sets lv of book1 to 4
            call SetUnitAbilityLevel(udg_Hero, 'A001', 4) //set lv of armour increase aura to 4
            call SetUnitAbilityLevel(udg_Hero, 'A003', 4) //set lv of attack decrease aura to 4
            //disable book1
        endif
        if GetUnitAbilityLevel(udg_Hero, 'A005' )== 3 then //if unit has book2 before learning
            call UnitRemoveAbility(udg_Hero, 'A005')  //removes book2
            call UnitAddAbility(udg_Hero, 'A005')    //adds book2
            call SetUnitAbilityLevel(udg_Hero, 'A005', 4) //sets lv of book2 to 4
            call SetUnitAbilityLevel(udg_Hero, 'A000', 4) //set lv of armour reduction aura to 4
            call SetUnitAbilityLevel(udg_Hero, 'A002', 4) //set lv of attack increase aura to 4
            //disable book2
        endif
    elseif GetUnitAbilityLevel(udg_Hero, 'AHtc' )== 5 then //hero learns lv 5
        if GetUnitAbilityLevel(udg_Hero, 'A004' )== 4 then //if unit has book1 before learning
            call UnitRemoveAbility(udg_Hero, 'A004')  //removes book1
            call UnitAddAbility(udg_Hero, 'A004')    //adds book1
            call SetUnitAbilityLevel(udg_Hero, 'A004', 5) //sets lv of book1 to 5
            call SetUnitAbilityLevel(udg_Hero, 'A001', 5) //set lv of armour increase aura to 5
            call SetUnitAbilityLevel(udg_Hero, 'A003', 5) //set lv of attack decrease aura to 5
            //disable book1
        endif
        if GetUnitAbilityLevel(udg_Hero, 'A005' )== 4 then //if unit has book2 before learning
            call UnitRemoveAbility(udg_Hero, 'A005')  //removes book2
            call UnitAddAbility(udg_Hero, 'A005')    //adds book2
            call SetUnitAbilityLevel(udg_Hero, 'A005', 5) //sets lv of book2 to 5
            call SetUnitAbilityLevel(udg_Hero, 'A000', 5) //set lv of armour reduction aura to 5
            call SetUnitAbilityLevel(udg_Hero, 'A002', 5) //set lv of attack increase aura to 5
            //disable book2
        endif
    endif
endfunction
//===========================================================================
function InitTrig_Level_up takes nothing returns nothing
    local integer index = 0
    set gg_trg_Level_up = CreateTrigger(  )
    loop 
        exitwhen index == 16
        call TriggerRegisterPlayerUnitEvent(gg_trg_Level_up, Player(index), EVENT_PLAYER_HERO_SKILL, null) 
        set index = index + 1
    endloop
    call TriggerAddCondition( gg_trg_Level_up, Condition( function LvUp_Conds ) )
    call TriggerAddAction( gg_trg_Level_up, function LvUp_Acts )
endfunction

Trigger 2, the aura and the dummy spell itself, the heart of the code:

JASS:
globals            //the global variable that marks the
    unit udg_Hero  //unit using the spell
endglobals
//====================================================
function EvilA_Conds takes nothing returns boolean
    return GetSpellAbilityId() == 'AHtc'  //the dummy ability used
endfunction
//================================
function EvilA_Acts takes nothing returns nothing
    local player owner = GetOwningPlayer(udg_Hero)//marks the owner of hero. This will be important to disable the books
    if GetUnitAbilityLevel(udg_Hero, 'A004' )== 1 then  //if lv of book1 == 1
        call UnitRemoveAbility(udg_Hero, 'A004')  //remove book1
        call UnitAddAbility(udg_Hero, 'A005')  //add book2
        call SetUnitAbilityLevel(udg_Hero, 'A005', 1)  // set lv of book2 to 1
        //disable book2
    elseif GetUnitAbilityLevel(udg_Hero, 'A005' )== 1 then  //if lv of book2 == 1
        call UnitRemoveAbility(udg_Hero, 'A005') //remove book 2
        call UnitAddAbility(udg_Hero, 'A004')    //add book1
        call SetUnitAbilityLevel(udg_Hero, 'A004', 1) //set lv of book1 to 1
        //disable book 1
    elseif GetUnitAbilityLevel(udg_Hero, 'A004' )== 2 then  //if lv of book1 == 2
        call UnitRemoveAbility(udg_Hero, 'A004') //remove book1
        call UnitAddAbility(udg_Hero, 'A005')    //add book2
        call SetUnitAbilityLevel(udg_Hero, 'A005', 2) //set lv of book2 to 2
        call SetUnitAbilityLevel(udg_Hero, 'A000', 2) //set lv of armour reduction aura to 2
        call SetUnitAbilityLevel(udg_Hero, 'A002', 2) //set lv of attack increase aura to 2
        //disable book 2
    elseif GetUnitAbilityLevel(udg_Hero, 'A005' )== 2 then  //if lv of book2 == 2
        call UnitRemoveAbility(udg_Hero, 'A005') //remove book 2
        call UnitAddAbility(udg_Hero, 'A004')    //add book1
        call SetUnitAbilityLevel(udg_Hero, 'A004', 2) //set lv of book1 to 2
        call SetUnitAbilityLevel(udg_Hero, 'A001', 2) //set lv of armour increase aura to 2
        call SetUnitAbilityLevel(udg_Hero, 'A003', 2) //set lv of attack decrease aura to 2
        //disable book 1
    elseif GetUnitAbilityLevel(udg_Hero, 'A004' )== 3 then  //if lv of book1 == 3
        call UnitRemoveAbility(udg_Hero, 'A004') //remove book1
        call UnitAddAbility(udg_Hero, 'A005')    //add book2
        call SetUnitAbilityLevel(udg_Hero, 'A005', 3) //set lv of book2 to 2
        call SetUnitAbilityLevel(udg_Hero, 'A000', 3) //set lv of armour reduction aura to 3
        call SetUnitAbilityLevel(udg_Hero, 'A002', 3) //set lv of attack increase aura to 3
        //disable book 2
    elseif GetUnitAbilityLevel(udg_Hero, 'A005' )== 3 then  //if lv of book2 == 3
        call UnitRemoveAbility(udg_Hero, 'A005') //remove book 2
        call UnitAddAbility(udg_Hero, 'A004')    //add book1
        call SetUnitAbilityLevel(udg_Hero, 'A004', 3) //set lv of book1 to 3
        call SetUnitAbilityLevel(udg_Hero, 'A001', 3) //set lv of armour increase aura to 3
        call SetUnitAbilityLevel(udg_Hero, 'A003', 3) //set lv of attack decrease aura to 3
        //disable book 1
    elseif GetUnitAbilityLevel(udg_Hero, 'A004' )== 4 then  //if lv of book1 == 4
        call UnitRemoveAbility(udg_Hero, 'A004') //remove book1
        call UnitAddAbility(udg_Hero, 'A005')    //add book2
        call SetUnitAbilityLevel(udg_Hero, 'A005', 4) //set lv of book2 to 4
        call SetUnitAbilityLevel(udg_Hero, 'A000', 4) //set lv of armour reduction aura to 4
        call SetUnitAbilityLevel(udg_Hero, 'A002', 4) //set lv of attack increase aura to 4
        //disable book 2
    elseif GetUnitAbilityLevel(udg_Hero, 'A005' )== 4 then  //if lv of book2 == 4
        call UnitRemoveAbility(udg_Hero, 'A005') //remove book 2
        call UnitAddAbility(udg_Hero, 'A004')    //add book1
        call SetUnitAbilityLevel(udg_Hero, 'A004', 4) //set lv of book1 to 4
        call SetUnitAbilityLevel(udg_Hero, 'A001', 4) //set lv of armour increase aura to 4
        call SetUnitAbilityLevel(udg_Hero, 'A003', 4) //set lv of attack decrease aura to 4
        //disable book 1
    elseif GetUnitAbilityLevel(udg_Hero, 'A004' )== 5 then  //if lv of book1 == 5
        call UnitRemoveAbility(udg_Hero, 'A004') //remove book1
        call UnitAddAbility(udg_Hero, 'A005')    //add book2
        call SetUnitAbilityLevel(udg_Hero, 'A005', 5) //set lv of book2 to 5
        call SetUnitAbilityLevel(udg_Hero, 'A000', 5) //set lv of armour reduction aura to 5
        call SetUnitAbilityLevel(udg_Hero, 'A002', 5) //set lv of attack increase aura to 5
        //disable book 2
     elseif GetUnitAbilityLevel(udg_Hero, 'A005' )== 5 then  //if lv of book2 == 5
        call UnitRemoveAbility(udg_Hero, 'A005') //remove book 2
        call UnitAddAbility(udg_Hero, 'A004')    //add book1
        call SetUnitAbilityLevel(udg_Hero, 'A004', 5) //set lv of book1 to 5
        call SetUnitAbilityLevel(udg_Hero, 'A001', 5) //set lv of armour increase aura to 5
        call SetUnitAbilityLevel(udg_Hero, 'A003', 5) //set lv of attack decrease aura to 5
        //disable book 1
    endif
    set owner = null  //nullifies the local var, to prevent leaks
endfunction
//===================================
function InitTrig_Evil_Aura takes nothing returns nothing
    local integer index = 0
    set gg_trg_Evil_Aura = CreateTrigger(  )
    loop 
        exitwhen index == 16
        call TriggerRegisterPlayerUnitEvent(gg_trg_Evil_Aura, Player(index), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    set index = index + 1
    endloop
    call TriggerAddCondition( gg_trg_Evil_Aura, Condition( function EvilA_Conds ) )
    call TriggerAddAction( gg_trg_Evil_Aura, function EvilA_Acts )
endfunction

If you think you have a way to ONLY optimize my code please post it.
I am waiting =).
 
Nope. i tried to use an algorith but i don't have a decent order i can use.
Besides algorithms can only be used in full JASS abilities, and this is not a full JASS ability, i use auras already available in game.

I considered many ways to craete the code before arriving here, algorithms were one of the many dead ends. There is no way i can ever make this spell JESP (using algor.). JESP is just not available for all spells as some of them can't be written in algorithmic form.

Nested ifs allowed me to solve the problem and are fast enough to work. Although i agree the final code will be huge and scary, it will actually be very easy to configure, as i tried hard to be like that.

The code is also commented so you can realise how simple it is.
 
Last edited:
Well I think all the stuff like this

JASS:
if GetUnitAbilityLevel(udg_Hero, 'A004' )==1 then //if unit has book1 before learning
call UnitRemoveAbility(udg_Hero, 'A004') //removes book1
call UnitAddAbility(udg_Hero, 'A004') //adds book1
call SetUnitAbilityLevel(udg_Hero, 'A004', 2) //sets lv of book1 to 2
call SetUnitAbilityLevel(udg_Hero, 'A001', 2) //set lv of armour increase aura to 2
call SetUnitAbilityLevel(udg_Hero, 'A003', 2) //set lv of attack decrease aura to 2  //disable book1
endif

Could just be made into one function which sets the ability level of the spell book to that of the aura ability.
 
No. That can not be done. I have to consider all levels and all chances of the hero learning a spell.

If i do it your way, i will only consider 1 possible chance. This way is more practical because i can see various scenarios into only 1 function. Although i agree it is big, as i told you it as compacted as possible.

And for the last time, algorithms don't work here because i am using auras from in-game. I told you it was a dead end.
I have JESP spells in my map made all by myself and i know when i can make good use of algorithms.

Also, this spell is huge because it considers ALL possible scenarios. I could cut half of it, but then the "bug" would be back. Yes, half of what you see was made to delete the bug. The bug was originated because i was considering a static method, a method that never changes. However a good code is a code that changes for all situations, and therefore i improved mine to fix that definition.
 
I am NOT ignoring your suggestions, and i am NOT diminishing you. You are the project leader and therefore your opinion is very important to me.

However i would like you to understand that i really can't use an algorithm here, otherwise i would've done that a long time ago.

Also, I hope you understand i took a lot of effort and time to make that work properly. If you look carefully you will my code is 100% natives, thus increasing the "virtual machine's" speed.

Still if you have any more suggestions i would like to hear them, as long as they integrate the heart of the spell.
 
Status
Not open for further replies.
Top