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

[Trigger] Save/Load System

Level 11
Joined
Aug 11, 2009
Messages
594
I have been searching for a save/load system for my RPG for some time now, trying different ones but none that really fits or im too much of a noob to edit them to work xD

Preferably it should save to a file so you dont need to write it down by yourself.

The codeless one is cool in here but the fact you need to enable locals (which doesnt seem to work for me or i was looking at an old guide to it) and there are only 5 save slots does give it alot of drawback since i will have a lot more heroes available.

Does anyone know a solid system or use one for your own map that you would be willing to share?

I dont know jass so setup would need to be in GUI so i can add all heroes etc.

Preferably it would save:
1. Hero+abilities+items+stats+xp
2. Items stored in two different stashes.
3. Gold and Lumber

This is the last big thing i need to add before i have atleast a playable RPG map so would be extremely grateful if anyone would help me with this :D

I understand its a big ask but I cant really solve it myself.

Thanks in advance!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,553
Codeless is your best option for GUI. You don't need to enable local files anymore, that has been gone for many patches now. Also, I don't think it has an actual limit of 5 heroes, you simply need to modify it to allow more. The system itself uses Events and easy to use functions which you can run whenever you'd like. So things like the Dialog menu are optional. You could have automatic saving/loading, use chat commands, etc.

I have a simplified version of the system in this thread as well as some solutions to possible issues you may run into:
 
Last edited:
Level 11
Joined
Aug 11, 2009
Messages
594
Ty so much! I will take a look at your version but might not be able to test until a couple of days. Would it be ok if I PM you any issues I have then or should I post here even if it takes a few days?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,553
Ty so much! I will take a look at your version but might not be able to test until a couple of days. Would it be ok if I PM you any issues I have then or should I post here even if it takes a few days?
So it doesn't really make sense to use my barebones demo map seeing as how everything you want to Save is already covered in the Codeless map. But you could use it as a reference and learn from it.

Also, it's okay to post here.
 
Level 11
Joined
Aug 11, 2009
Messages
594
Ok, so I run into some trobule immediately xD

First it wouldnt load but found in other posts that you needed to change Aerial Shackle to level 2 and tooltip to !.

But now it works to load but it sets gold and lumber to 0 and hero level to 49 when its supposed to be 150. The XP values are correct in the Save Init. Everything else seems to load correct. Though I havnt tried to add the stashes yet which might be problematic for me to do.
  • Save GUI
    • Events
      • Player - Player 1 (Red) types a chat message containing -save as An exact match
      • Player - Player 2 (Blue) types a chat message containing -save as An exact match
      • Player - Player 3 (Teal) types a chat message containing -save as An exact match
      • Player - Player 4 (Purple) types a chat message containing -save as An exact match
      • Player - Player 5 (Yellow) types a chat message containing -save as An exact match
      • Player - Player 6 (Orange) types a chat message containing -save as An exact match
      • Player - Player 7 (Green) types a chat message containing -save as An exact match
      • Player - Player 8 (Pink) types a chat message containing -save as An exact match
      • Player - Player 9 (Gray) types a chat message containing -save as An exact match
      • Player - Player 10 (Light Blue) types a chat message containing -save as An exact match
      • Player - Player 11 (Dark Green) types a chat message containing -save as An exact match
    • Conditions
      • SaveUseGUI Equal to True
      • (SavePlayerHero[((Player number of (Triggering player)) - 1)] is A Hero) Equal to True
    • Actions
      • -------- ------------------- --------
      • -------- NOTE: You must load values in the reverse order you saved them in. This is why we save the unit type last. --------
      • -------- ------------------- --------
      • Set VariableSet SaveTempUnit = SavePlayerHero[((Player number of (Triggering player)) - 1)]
      • Set VariableSet SaveCount = -1
      • -------- ------------------- --------
      • -------- Save Abilities --------
      • -------- ------------------- --------
      • For each (Integer SaveTempInt) from 0 to SaveAbilityTypeMax, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of SaveAbilityType[SaveTempInt] for SaveTempUnit) Greater than 0
            • Then - Actions
              • -------- Save level of ability --------
              • Set VariableSet SaveCount = (SaveCount + 1)
              • Set VariableSet SaveValue[SaveCount] = (Level of SaveAbilityType[SaveTempInt] for SaveTempUnit)
              • Set VariableSet SaveMaxValue[SaveCount] = 10
              • -------- Save the array index --------
              • Set VariableSet SaveCount = (SaveCount + 1)
              • Set VariableSet SaveValue[SaveCount] = SaveTempInt
              • Set VariableSet SaveMaxValue[SaveCount] = SaveAbilityTypeMax
            • Else - Actions
      • -------- Save the number of abilities the unit has --------
      • Set VariableSet SaveCount = (SaveCount + 1)
      • Set VariableSet SaveValue[SaveCount] = (SaveCount / 2)
      • Set VariableSet SaveMaxValue[SaveCount] = SaveAbilityTypeMax
      • -------- ------------------- --------
      • -------- Save Items --------
      • -------- ------------------- --------
      • For each (Integer SaveTempInt) from 0 to 5, do (Actions)
        • Loop - Actions
          • Set VariableSet SaveCount = (SaveCount + 1)
          • Custom script: set udg_SaveValue[udg_SaveCount] = SaveHelper.ConvertItemId(GetItemTypeId(UnitItemInSlot(udg_SaveTempUnit, udg_SaveTempInt)))
          • Set VariableSet SaveMaxValue[SaveCount] = SaveItemTypeMax
      • -------- ------------------- --------
      • -------- Save Attributes --------
      • -------- ------------------- --------
      • Set VariableSet SaveCount = (SaveCount + 1)
      • Set VariableSet SaveValue[SaveCount] = (Strength of SaveTempUnit (Exclude bonuses))
      • Set VariableSet SaveMaxValue[SaveCount] = 999
      • -------- ------------------- --------
      • Set VariableSet SaveCount = (SaveCount + 1)
      • Set VariableSet SaveValue[SaveCount] = (Agility of SaveTempUnit (Exclude bonuses))
      • Set VariableSet SaveMaxValue[SaveCount] = 999
      • -------- ------------------- --------
      • Set VariableSet SaveCount = (SaveCount + 1)
      • Set VariableSet SaveValue[SaveCount] = (Intelligence of SaveTempUnit (Exclude bonuses))
      • Set VariableSet SaveMaxValue[SaveCount] = 999
      • -------- ------------------- --------
      • -------- Save Experience (%) and Level --------
      • -------- ------------------- --------
      • Set VariableSet SaveCount = (SaveCount + 1)
      • Custom script: set udg_SaveValue[udg_SaveCount] = R2I( (GetHeroXP(udg_SaveTempUnit)) / SaveHelper.GetLevelXP(GetHeroLevel(udg_SaveTempUnit)) * 100) // percentage
      • Set VariableSet SaveMaxValue[SaveCount] = 100
      • -------- ------------------- --------
      • Set VariableSet SaveCount = (SaveCount + 1)
      • Set VariableSet SaveValue[SaveCount] = (Hero level of SaveTempUnit)
      • Set VariableSet SaveMaxValue[SaveCount] = 100
      • -------- ------------------- --------
      • -------- Save Unit Type --------
      • -------- ------------------- --------
      • Set VariableSet SaveCount = (SaveCount + 1)
      • Custom script: set udg_SaveValue[udg_SaveCount] = SaveHelper.ConvertUnitId(GetUnitTypeId(udg_SaveTempUnit))
      • Set VariableSet SaveMaxValue[SaveCount] = SaveUnitTypeMax
      • -------- ------------------- --------
      • -------- Save Gold & Lumber --------
      • -------- ------------------- --------
      • Set VariableSet SaveCount = (SaveCount + 1)
      • Set VariableSet SaveValue[SaveCount] = ((Player(((Player number of (Triggering player)) - 1))) Current gold)
      • Set VariableSet SaveMaxValue[SaveCount] = 100
      • -------- ------------------- --------
      • Set VariableSet SaveCount = (SaveCount + 1)
      • Set VariableSet SaveValue[SaveCount] = ((Player(((Player number of (Triggering player)) - 1))) Current lumber)
      • Set VariableSet SaveMaxValue[SaveCount] = 100
      • -------- ------------------- --------
      • -------- Save to disk --------
      • -------- ------------------- --------
      • Custom script: set udg_SaveTempInt = Savecode.create()
      • For each (Integer A) from 0 to SaveCount, do (Actions)
        • Loop - Actions
          • Custom script: call Savecode(udg_SaveTempInt).Encode(udg_SaveValue[bj_forLoopAIndex], udg_SaveMaxValue[bj_forLoopAIndex])
      • Set VariableSet SaveTempString = <Empty String>
      • Custom script: set udg_SaveTempString = Savecode(udg_SaveTempInt).Save(GetTriggerPlayer(), 1)
      • Custom script: call SaveFile.create(GetTriggerPlayer(), SaveHelper.GetUnitTitle(udg_SaveTempUnit), -1, udg_SaveTempString)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • SaveShowCode Equal to True
        • Then - Actions
          • Custom script: set udg_SaveCodeColored = Savecode_colorize(udg_SaveTempString)
          • Game - Display to (All players) the text: SaveCodeColored
        • Else - Actions

  • Load GUI
    • Events
      • Game - SaveLoadEvent becomes Equal to 1.00
    • Conditions
      • SaveUseGUI Equal to True
    • Actions
      • Set VariableSet SaveCount = 0
      • -------- ------------------- --------
      • -------- NOTE: You must load values in the reverse order you saved them in --------
      • -------- ------------------- --------
      • -------- Validate --------
      • -------- ------------------- --------
      • Custom script: set udg_SaveTempInt = integer(Savecode.create())
      • Custom script: if not (Savecode(udg_SaveTempInt).Load(udg_SaveLoadEvent_Player, udg_SaveLoadEvent_Code, 1)) then
      • Game - Display to (Player group(SaveLoadEvent_Player)) the text: Invalid load code (...
      • Skip remaining actions
      • Custom script: endif
      • Custom script: call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Loaded " + User[udg_SaveLoadEvent_Player].nameColored + "'s character!")
      • Unit - Remove SavePlayerHero[((Player number of SaveLoadEvent_Player) - 1)] from the game
      • -------- ------------------- --------
      • -------- Load Lumber & Gold --------
      • -------- ------------------- --------
      • Set VariableSet SaveCount = (SaveCount + 1)
      • Set VariableSet SaveMaxValue[SaveCount] = 100
      • Custom script: call SaveHelper.GUILoadNext()
      • Player - Set SaveLoadEvent_Player.Current lumber to SaveValue[SaveCount]
      • -------- ------------------- --------
      • Set VariableSet SaveCount = (SaveCount + 1)
      • Set VariableSet SaveMaxValue[SaveCount] = 100
      • Custom script: call SaveHelper.GUILoadNext()
      • Player - Set SaveLoadEvent_Player.Current gold to SaveValue[SaveCount]
      • -------- ------------------- --------
      • -------- Load Hero --------
      • -------- ------------------- --------
      • Set VariableSet SaveMaxValue[SaveCount] = SaveUnitTypeMax
      • Custom script: call SaveHelper.GUILoadNext()
      • -------- ------------------- --------
      • Unit - Create 1 SaveUnitType[SaveValue[SaveCount]] for SaveLoadEvent_Player at (Center of Town 1 Start <gen>) facing Default building facing degrees
      • Set VariableSet U_Hero[(Player number of SaveLoadEvent_Player)] = (Last created unit)
      • Set VariableSet SaveTempUnit = (Last created unit)
      • Set VariableSet SavePlayerHero[((Player number of SaveLoadEvent_Player) - 1)] = SaveTempUnit
      • Selection - Select SaveTempUnit for SaveLoadEvent_Player
      • -------- ------------------- --------
      • -------- Load Experience and Level --------
      • -------- ------------------- --------
      • Set VariableSet SaveCount = (SaveCount + 1)
      • Set VariableSet SaveMaxValue[SaveCount] = 100
      • Custom script: call SaveHelper.GUILoadNext()
      • Set VariableSet SaveCount = (SaveCount + 1)
      • Set VariableSet SaveMaxValue[SaveCount] = 100
      • Custom script: call SaveHelper.GUILoadNext()
      • -------- ------------------- --------
      • Custom script: set udg_SaveTempReal = SaveHelper.GetLevelXP(udg_SaveValue[udg_SaveCount-1])
      • Hero - Set SaveTempUnit experience to (Integer((((Real(SaveValue[SaveCount])) / 100.00) x SaveTempReal))), Hide level-up graphics
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Hero level of SaveTempUnit) Not equal to SaveValue[(SaveCount - 1)]
        • Then - Actions
          • Hero - Set SaveTempUnit Hero-level to SaveValue[(SaveCount - 1)], Hide level-up graphics
        • Else - Actions
      • -------- ------------------- --------
      • -------- Load Attributes --------
      • -------- ------------------- --------
      • Set VariableSet SaveCount = (SaveCount + 1)
      • Set VariableSet SaveMaxValue[SaveCount] = 999
      • Custom script: call SaveHelper.GUILoadNext()
      • Hero - Modify Intelligence of SaveTempUnit: Set to SaveValue[SaveCount].
      • -------- ------------------- --------
      • Set VariableSet SaveCount = (SaveCount + 1)
      • Set VariableSet SaveMaxValue[SaveCount] = 999
      • Custom script: call SaveHelper.GUILoadNext()
      • Hero - Modify Agility of SaveTempUnit: Set to SaveValue[SaveCount].
      • -------- ------------------- --------
      • Set VariableSet SaveCount = (SaveCount + 1)
      • Set VariableSet SaveMaxValue[SaveCount] = 999
      • Custom script: call SaveHelper.GUILoadNext()
      • Hero - Modify Strength of SaveTempUnit: Set to SaveValue[SaveCount].
      • -------- ------------------- --------
      • -------- Load Items --------
      • -------- ------------------- --------
      • For each (Integer A) from 0 to 5, do (Actions)
        • Loop - Actions
          • Set VariableSet SaveCount = (SaveCount + 1)
          • Set VariableSet SaveMaxValue[SaveCount] = SaveItemTypeMax
          • Custom script: call SaveHelper.GUILoadNext()
          • Hero - Create SaveItemType[SaveValue[SaveCount]] and give it to SaveTempUnit
      • -------- ------------------- --------
      • -------- Load Abilities --------
      • -------- ------------------- --------
      • Set VariableSet SaveCount = (SaveCount + 1)
      • Set VariableSet SaveMaxValue[SaveCount] = SaveAbilityTypeMax
      • Custom script: call SaveHelper.GUILoadNext()
      • Set VariableSet SaveTempReal = (Real(SaveValue[SaveCount]))
      • For each (Integer A) from 0 to (Integer(SaveTempReal)), do (Actions)
        • Loop - Actions
          • Set VariableSet SaveCount = (SaveCount + 1)
          • Set VariableSet SaveMaxValue[SaveCount] = SaveAbilityTypeMax
          • Custom script: call SaveHelper.GUILoadNext()
          • Unit - Add SaveAbilityType[SaveValue[SaveCount]] to SaveTempUnit
          • Set VariableSet SaveCount = (SaveCount + 1)
          • Set VariableSet SaveMaxValue[SaveCount] = 10
          • Custom script: call SaveHelper.GUILoadNext()
          • Unit - Set level of SaveAbilityType[SaveValue[(SaveCount - 1)]] for SaveTempUnit to SaveValue[SaveCount]
      • Custom script: call Savecode(udg_SaveTempInt).destroy()

Can you spot something wrong?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,553
Your SaveMaxValue is pretty low for some of these fields. That limits the integer being saved to that given value so if you had 5000 gold you'd only save 100.

Also, make sure when testing that you exit Warcraft 3 completely. Restarting the map will break the system.

Other than that, I don't know.
 
Level 11
Joined
Aug 11, 2009
Messages
594
Ok, so the levels did become right after changing the values and restarting wc3 before loading, however gold and lumber still loads 0 :(


EDIT: I think everything is solved. Atleast it worked once with both Gold, Lumber and a Stash unit :)
 
Last edited:
Top