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

Game System Saving Fails

Status
Not open for further replies.
Level 37
Joined
Aug 14, 2006
Messages
7,601
Hey.

I have a system that worked before, but it seems like the newest version of Warcraft III broke it somehow. I would like you to check this system out and fix the possible errors.

The system works excellent, but when saving and loading the game in same chapter the combat kings which have levels from 1 to 10 are always reseted to level 1 when the game is loaded. For example, if Galeoth have level 5 Mana Breaker Combat King, player saves the game and then loads it, he should have that level 5 Mana Breaker, not level 1.

The one who can help will have some rep & credits.

  • Save Data
    • Events
      • Game - The game is about to be saved
    • Conditions
    • Actions
      • Game Cache - Create a game cache from TCOCacheTemp_3.w3v
      • Set GameCache = (Last created game cache)
      • Custom script: call StoreHeroSpells ( udg_GameCache, "TCO_Heroes", "TCO_Galeoth", udg_AAAGaleoth )
      • Save GameCache
  • Load Data
    • Events
      • Game - A saved game is loaded
    • Conditions
    • Actions
      • Game Cache - Create a game cache from TCOCacheTemp_3.w3v
      • Set GameCache = (Last created game cache)
      • Custom script: call RestoreHeroSpells ( udg_GameCache, "TCO_Heroes", "TCO_Galeoth", udg_AAAGaleoth )
JASS:
function GetSpellBook takes nothing returns integer
    return 'A6AU'
endfunction

function CreateSpell takes integer itemid, integer spellbookid, integer spellid returns nothing
local integer p = 0
    set udg_Spell_System_last = udg_Spell_System_last + 1
    set udg_Spell_System_item[udg_Spell_System_last] = itemid
    set udg_Spell_System_abil[udg_Spell_System_last] = spellbookid
    set udg_Spell_System_spell[udg_Spell_System_last] = spellid
    loop
        exitwhen p > 12
        call SetPlayerAbilityAvailable(Player(p), udg_Spell_System_abil[udg_Spell_System_last], false)
        set p = p + 1
    endloop
endfunction

function UnitAddSpell takes unit u, integer itemid returns boolean
    local integer i = 0
    set udg_Spell_System_success = false
    loop
        exitwhen i > udg_Spell_System_last
        if (udg_Spell_System_item[i] == itemid) then
            if GetUnitAbilityLevel(u, udg_Spell_System_abil[i]) <= 0 then
                call UnitAddAbility(u, udg_Spell_System_abil[i])
                set udg_Spell_System_success = true
return true
            else
                call SetUnitAbilityLevel(u, udg_Spell_System_spell[i], GetUnitAbilityLevel(u, udg_Spell_System_spell[i]) + 1)
                set udg_Spell_System_success = true
                return true
            endif
        endif
        set i = i + 1
    endloop
    return false
endfunction

function UnitRemoveSpell takes unit u, integer abilid returns boolean
    local integer i = 0
    loop
        exitwhen i > udg_Spell_System_last
        if udg_Spell_System_spell[i] == abilid then
            if GetUnitAbilityLevel(u, udg_Spell_System_abil[i]) <= 0 then
return false
            else
                call UnitRemoveAbility(u, udg_Spell_System_abil[i])
                set udg_Spell_System_success = true
                return true
            endif
        endif
        set i = i + 1
    endloop
    return false
endfunction

function StoreHeroSpells takes gamecache cache, string missionkey, string key, unit whichunit returns nothing
    local integer i = 0
    if udg_Spell_System_Active then
        //call BJDebugMsg("Storing spells...")
        loop
            exitwhen i > udg_Spell_System_last
if GetUnitAbilityLevel(whichunit, udg_Spell_System_abil[i]) > 0 then
                call StoreInteger(cache, missionkey, key + "spell" + I2S(i), GetUnitAbilityLevel(whichunit, udg_Spell_System_spell[i]))
                //call BJDebugMsg("Spell stored: " + I2S(i))
            else
                call StoreInteger(cache, missionkey, key + "spell" + I2S(i), 0)
            endif
            set i = i + 1
        endloop
    endif
    call SaveGameCache(cache)
endfunction

function RestoreHeroSpells takes gamecache cache, string missionkey, string key, unit whichunit returns nothing
    local integer i = 0
    if udg_Spell_System_Active then
        //call BJDebugMsg("Loading spells...")
        loop
            exitwhen i > udg_Spell_System_last
if HaveStoredInteger(cache, missionkey, key + "spell" + I2S(i)) then
                if GetStoredInteger(cache, missionkey, key + "spell" + I2S(i)) > 0 then
                    call UnitAddAbility(whichunit, udg_Spell_System_abil[i])
                    call SetUnitAbilityLevel(whichunit, udg_Spell_System_spell[i], GetStoredInteger(cache, missionkey, key + "spell" + I2S(i)))
                    //call BJDebugMsg("Spell loaded: " + I2S(i))
                endif
            endif
set i = i + 1
        endloop
    endif
endfunction

function StoreHero takes gamecache cache, string missionkey, string key, unit whichunit returns nothing
    call StoreHeroSpells(cache, missionkey, key, whichunit)
    call UnitRemoveAbility(whichunit, GetSpellBook())
    //call TriggerSleepAction(0.0)
    call StoreUnit(cache, missionkey, key, whichunit)
endfunction

function RestoreHero takes gamecache cache, string missionkey, string key, player whichplayer, location whichloc, real angle returns unit
    set bj_lastLoadedUnit = RestoreUnit(cache, missionkey, key, whichplayer, GetLocationX(whichloc), GetLocationY(whichloc), angle)
    call UnitAddAbility(bj_lastLoadedUnit, GetSpellBook())
    call RestoreHeroSpells(cache, missionkey, key, bj_lastLoadedUnit)
    return bj_lastLoadedUnit
endfunction



FIRST: ITEM
SECOND: DUMMY SPELL BOOK
THIRD: SPELL ITSELF

  • -------- ========= COMBAT KINGS ========= --------
  • -------- Counter Attack --------
  • Custom script: call CreateSpell('I656', 'A6AP', 'A6B2')
  • -------- Evasion --------
  • Custom script: call CreateSpell('I654', 'A6AQ', 'A64T')
  • -------- Lucky Strike --------
  • Custom script: call CreateSpell('I653', 'A6AR', 'A64S')
  • -------- Natural Armor --------
  • Custom script: call CreateSpell('I657', 'A6AS', 'A6B3')
  • -------- Stunner --------
  • Custom script: call CreateSpell('I655', 'A6AT', 'A6B1')
  • -------- Blind --------
  • Custom script: call CreateSpell('I6B1', 'A6E4', 'A64M')
  • -------- Disarm --------
  • Custom script: call CreateSpell('I6B3', 'A6AF', 'A6AO')
  • -------- Stunner --------
  • Custom script: call CreateSpell('I655', 'A6AT', 'A6B1')
  • -------- Force Blow --------
  • Custom script: call CreateSpell('I6B6', 'A6E7', 'A64F')
  • -------- Immobility --------
  • Custom script: call CreateSpell('I6B2', 'A6E5', 'A6DZ')
  • -------- Mana Breaker --------
  • Custom script: call CreateSpell('I6B5', 'A6E6', 'A6EV')
  • -------- Mute --------
  • Custom script: call CreateSpell('I6B4', 'A6E8', 'A6E0')
 
Last edited:
Level 5
Joined
Sep 1, 2010
Messages
168
As far as my limited knowledge goes, you've simply missed to save the level of the abilities and to set the levels of the abilities on loading.
Maybe I've overlooked something, but I see nowhere a 'set level' GUI or call() equivalent for getting the level of the abilities.

Hope this helps (sorry for no code; no WE on the university computer and newb to jass).
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Try some debugging messages:
JASS:
call BJDebugMsg( I2S( GetUnitAbilityLevel( whichunit, udg_Spell_System_spell[i] ) ) )
Add that after the first call StoreInteger in StoreHeroSpells.

JASS:
call BJDebugMsg( "Level is 0")
Add that after the second call StoreInteger in StoreHeroSpells.

Add debug messages to RestoreHeroSpells to check the level of the restored ability.

A test map would be nice.
 
Level 37
Joined
Aug 14, 2006
Messages
7,601
There is no longer test map, the system was made years ago and I lost the test map already. :(

I'll test your suggestion soon, it will take an hour probably.

EDIT: By the way, now that we nowaday have those Hashtables, would it be easy to do that save/load with Hashtables? Just for that save/load so that the abilities will have correct levels...

EDIT 2: PROBLEM FIXED! I fixed the problem my making an own GUI based sexy system that fixes the levels. Sorry for the trouble.
 
Last edited:
Status
Not open for further replies.
Top