• 🏆 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] Spellbook Multiple Pages Error.

Status
Not open for further replies.
Level 26
Joined
Jun 5, 2008
Messages
1,767
Yeah, well. I was going to ask my friend to help me out, since he said it was easy.
Sadly, he's offline and unable to answer me, so I gave it my best shot.

The idea was to add a number of abilities. Clicking one of these abilities would then increase the level of the spellbook ability to a certain level and to get back you would simply click a back ability, which set the level of the spellbook ability to 1.

JASS:
 // The two /'s means that any text written behind it is ignored by the game.
 // Usefull when I want to tell you how this works :)
 // Read the trigger called "Spellbook Instructions" for instructions.

constant function Spellbook_Back_ID takes nothing returns integer
    return 'A004' // This is the ability rawcode of the Previous Page ability.
endfunction
constant function Spellbook_Civil_ID takes nothing returns integer
    return 'A049' // This is the ability rawcode of the Next Page ability.
endfunction
constant function Spellbook_Defensive_ID takes nothing returns integer
    return 'A04C' // This is the ability rawcode of the Next Page ability.
endfunction
constant function Spellbook_Agriculture_ID takes nothing returns integer
    return 'A048' // This is the ability rawcode of the Next Page ability.
endfunction
constant function Spellbook_Economy_ID takes nothing returns integer
    return 'A044' // This is the ability rawcode of the Next Page ability.
endfunction
constant function Spellbook_Religion_ID takes nothing returns integer
    return 'A04D' // This is the ability rawcode of the Next Page ability.
endfunction
constant function Spellbook_Military_ID takes nothing returns integer
    return 'A04A' // This is the ability rawcode of the Next Page ability.
endfunction
constant function Spellbook_CurrPageId takes nothing returns integer
    return 'A019' // This is the ability rawcode of the Current Page ability.
endfunction

function InitSpellbookId takes nothing returns nothing
 // This is a list of every spellbook ability that is used in the map. Fill in new spellbook rawcodes here.
 set udg_SpellbookId[0] = 'A01D'
 set udg_SpellbookId[1] = 'A018'
 set udg_SpellbookId[2] = 'A026'
 set udg_SpellbookId[3] = 'A025'
 set udg_SpellbookId[4] = 'A024'
 set udg_SpellbookId[5] = 'A023'
 set udg_SpellbookId[6] = 'A028'
 set udg_SpellbookId[7] = 'A027'
 set udg_SpellbookId[8] = 'A022'
 set udg_SpellbookId[9] = 'A00R'
 set udg_SpellbookId[10] = 'A029'
 // set udg_SpellbookId[2] = 'new ID here'
endfunction

 // Following lines are not to be toutched unless you know what you are doing.

function Trig_SpellbookPages_Conditions takes nothing returns boolean
 return GetSpellAbilityId() == Spellbook_Back_Id() or GetSpellAbilityId() == Spellbook_Civil_ID() or GetSpellAbilityId() == Spellbook_Defensive_ID() or GetSpellAbilityId() == Agriculture_ID() or GetSpellAbilityId() == Economy_ID() or GetSpellAbilityId() == Religion_ID() or GetSpellAbilityId() == Military_ID()
endfunction

function Trig_SpellbookPages_Actions takes nothing returns nothing
 local unit caster = GetTriggerUnit()
 local integer i = 0
    if GetSpellAbilityId() == Spellbook_Back_Id() then
        loop
            exitwhen udg_SpellbookId[i] == 0
            if GetUnitAbilityLevel(caster, udg_SpellbookId[i]) > 0 then
                call DecUnitAbilityLevel(caster, udg_SpellbookId[i] )
                call SetUnitAbilityLevel(caster, Spellbook_CurrPageId(), GetUnitAbilityLevel(caster, udg_SpellbookId[i]))
            endif
            set i = i+1
        endloop
    elseif GetSpellAbilityId() == Spellbook_Spellbook_Civil_ID() then
        loop
            exitwhen udg_SpellbookId[i] == 0
            if GetUnitAbilityLevel(caster, udg_SpellbookId[i] ) > 0 then
                call SetUnitAbilityLevel(caster, udg_SpellbookId[i], GetUnitAbilityLevel(caster, udg_SpellbookId[i])+1)
                call SetUnitAbilityLevel(caster, Spellbook_CurrPageId(), GetUnitAbilityLevel(caster, udg_SpellbookId[i]))
            endif
            set i = i+1
        endloop
    elseif GetSpellAbilityId() == Spellbook_Defensive_ID() then
        loop
            exitwhen udg_SpellbookId[i] == 0
            if GetUnitAbilityLevel(caster, udg_SpellbookId[i] ) > 0 then
                call SetUnitAbilityLevel(caster, udg_SpellbookId[i], GetUnitAbilityLevel(caster, udg_SpellbookId[i])+1)
                call SetUnitAbilityLevel(caster, Spellbook_CurrPageId(), GetUnitAbilityLevel(caster, udg_SpellbookId[i]))
            endif
            set i = i+1
        endloop
    elseif GetSpellAbilityId() == Spellbook_Agriculture_ID() then
        loop
            exitwhen udg_SpellbookId[i] == 0
            if GetUnitAbilityLevel(caster, udg_SpellbookId[i] ) > 0 then
                call SetUnitAbilityLevel(caster, udg_SpellbookId[i], GetUnitAbilityLevel(caster, udg_SpellbookId[i])+1)
                call SetUnitAbilityLevel(caster, Spellbook_CurrPageId(), GetUnitAbilityLevel(caster, udg_SpellbookId[i]))
            endif
            set i = i+1
        endloop
    elseif GetSpellAbilityId() == Spellbook_Economy_ID() then
        loop
            exitwhen udg_SpellbookId[i] == 0
            if GetUnitAbilityLevel(caster, udg_SpellbookId[i] ) > 0 then
                call SetUnitAbilityLevel(caster, udg_SpellbookId[i], GetUnitAbilityLevel(caster, udg_SpellbookId[i])+1)
                call SetUnitAbilityLevel(caster, Spellbook_CurrPageId(), GetUnitAbilityLevel(caster, udg_SpellbookId[i]))
            endif
            set i = i+1
        endloop
    elseif GetSpellAbilityId() == Spellbook_Religion_ID() then
        loop
            exitwhen udg_SpellbookId[i] == 0
            if GetUnitAbilityLevel(caster, udg_SpellbookId[i] ) > 0 then
                call SetUnitAbilityLevel(caster, udg_SpellbookId[i], GetUnitAbilityLevel(caster, udg_SpellbookId[i])+1)
                call SetUnitAbilityLevel(caster, Spellbook_CurrPageId(), GetUnitAbilityLevel(caster, udg_SpellbookId[i]))
            endif
            set i = i+1
        endloop
    elseif GetSpellAbilityId() == Spellbook_Military_ID() then
        loop
            exitwhen udg_SpellbookId[i] == 0
            if GetUnitAbilityLevel(caster, udg_SpellbookId[i] ) > 0 then
                call SetUnitAbilityLevel(caster, udg_SpellbookId[i], GetUnitAbilityLevel(caster, udg_SpellbookId[i])+1)
                call SetUnitAbilityLevel(caster, Spellbook_CurrPageId(), GetUnitAbilityLevel(caster, udg_SpellbookId[i]))
            endif
            set i = i+1
        endloop
    endif
 set caster = null
endfunction

//===========================================================================
function InitTrig_SpellbookPages_Copy takes nothing returns nothing
    call InitSpellbookId()
    set gg_trg_SpellbookPages_Copy = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SpellbookPages_Copy, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_SpellbookPages_Copy, Condition( function Trig_SpellbookPages_Conditions ) )
    call TriggerAddAction( gg_trg_SpellbookPages_Copy, function Trig_SpellbookPages_Actions )
endfunction

Excuse my noobiness. This is an attempted edit, alright. But hey, it's still something to learn from working with. Any help at all would be appreciated.
Well, I'd prefer a working example though, but I couldn't find any downloadable spells that was similar to what I was looking for.

The idea is to keep all building recipes in these books. ^^
 
Level 26
Joined
Jun 5, 2008
Messages
1,767
Well, I tried editing this code to serve my purposes.

JASS:
 // The two /'s means that any text written behind it is ignored by the game.
 // Usefull when I want to tell you how this works :)
 // Read the trigger called "Spellbook Instructions" for instructions.

constant function Spellbook_PrevPageId takes nothing returns integer
    return 'A004' // This is the ability rawcode of the Previous Page ability.
endfunction
constant function Spellbook_NextPageId takes nothing returns integer
    return 'A01B' // This is the ability rawcode of the Next Page ability.
endfunction
constant function Spellbook_CurrPageId takes nothing returns integer
    return 'A019' // This is the ability rawcode of the Current Page ability.
endfunction

function InitSpellbookId takes nothing returns nothing
 // This is a list of every spellbook ability that is used in the map. Fill in new spellbook rawcodes here.
 set udg_SpellbookId[0] = 'A01D'
 set udg_SpellbookId[1] = 'A018'
 set udg_SpellbookId[2] = 'A026'
 set udg_SpellbookId[3] = 'A025'
 set udg_SpellbookId[4] = 'A024'
 set udg_SpellbookId[5] = 'A023'
 set udg_SpellbookId[6] = 'A028'
 set udg_SpellbookId[7] = 'A027'
 set udg_SpellbookId[8] = 'A022'
 set udg_SpellbookId[9] = 'A00R'
 set udg_SpellbookId[10] = 'A029'
 // set udg_SpellbookId[2] = 'new ID here'
endfunction

 // Following lines are not to be toutched unless you know what you are doing.

function Trig_SpellbookPages_Conditions takes nothing returns boolean
 return GetSpellAbilityId() == Spellbook_PrevPageId() or GetSpellAbilityId() == Spellbook_NextPageId()
endfunction

function Trig_SpellbookPages_Actions takes nothing returns nothing
 local unit caster = GetTriggerUnit()
 local integer i = 0
    if GetSpellAbilityId() == Spellbook_PrevPageId() then
        loop
            exitwhen udg_SpellbookId[i] == 0
            if GetUnitAbilityLevel(caster, udg_SpellbookId[i]) > 0 then
                call DecUnitAbilityLevel(caster, udg_SpellbookId[i] )
                call SetUnitAbilityLevel(caster, Spellbook_CurrPageId(), GetUnitAbilityLevel(caster, udg_SpellbookId[i]))
            endif
            set i = i+1
        endloop
    elseif GetSpellAbilityId() == Spellbook_NextPageId() then
        loop
            exitwhen udg_SpellbookId[i] == 0
            if GetUnitAbilityLevel(caster, udg_SpellbookId[i] ) > 0 then
                call SetUnitAbilityLevel(caster, udg_SpellbookId[i], GetUnitAbilityLevel(caster, udg_SpellbookId[i])+1)
                call SetUnitAbilityLevel(caster, Spellbook_CurrPageId(), GetUnitAbilityLevel(caster, udg_SpellbookId[i]))
            endif
            set i = i+1
        endloop
    endif
 set caster = null
endfunction

//===========================================================================
function InitTrig_SpellbookPages takes nothing returns nothing
    call InitSpellbookId()
    set gg_trg_SpellbookPages = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SpellbookPages, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_SpellbookPages, Condition( function Trig_SpellbookPages_Conditions ) )
    call TriggerAddAction( gg_trg_SpellbookPages, function Trig_SpellbookPages_Actions )
endfunction

If there is something that you do not recognize, I suppose it's custom? :O
 
Level 26
Joined
Jun 5, 2008
Messages
1,767
I realized that making it cooler rather than more simple is an impossible dream. XD
It seems to be working for now at least. I did it the simple way and used a spellbook ability and shoved four spellbook abilities in there, I haven't noticed any major errors.

(I lowered the amount of categories, Warfare was shoved into defense and religion was removed entirely.)

If it fucks up in the future, this would be a nice fix, if not, well shit happens?
People doesn't appear to be that interested in this idea, so who knows? XD
 
Status
Not open for further replies.
Top