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

Status
Not open for further replies.
Level 6
Joined
Sep 19, 2007
Messages
215
I need to figure out why this save trigger is adding random abilities instead of the ones that are learnt through items , it wont save the spell thats added at level one i have tried so many different ways i want to make it where the hero has no spells at start accept for the one u start with and as u play the game u get spells from boss drops and level them up with same items again but when i save it doesnt load the first spell or set the levels of the other ones and sometimes adds another random one

  • Save Abilities
    • 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
    • Conditions
    • Actions
      • -------- Find the players hero, and save it. I realize it leaks but it's just for demonstration. --------
      • Set SaveCount = 0
      • Unit Group - Pick every unit in (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True)) and do (Set Hero = (Picked unit))
      • Custom script: set udg_Save[udg_SaveCount] = CodeGen_ConvertUnit(GetUnitTypeId(udg_Hero))
      • -------- Save heroes level. --------
      • Set SaveCount = (SaveCount + 1)
      • Set Save[SaveCount] = (Hero level of Hero)
      • -------- Save players gold. --------
      • Set SaveCount = (SaveCount + 1)
      • Set Save[SaveCount] = ((Triggering player) Current gold)
      • -------- Save heroes items. --------
      • Set SaveCount = (SaveCount + 1)
      • Set Save[SaveCount] = (Number of items carried by Hero)
      • For each (Integer A) from 1 to Save[SaveCount], do (Actions)
        • Loop - Actions
          • Set SaveCount = (SaveCount + 1)
          • Set Item = (Item carried by Hero in slot (Integer A))
          • Custom script: set udg_Save[udg_SaveCount] = CodeGen_ConvertItem(GetItemTypeId(udg_Item))
      • -------- Save players Lumber. --------
      • Set SaveCount = (SaveCount + 1)
      • Set Save[SaveCount] = ((Triggering player) Current lumber)
      • -------- Save heroes skills --------
      • For each (Integer A) from 0 to SaveLoad_AbilityCount, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of SaveLoad_Abilities[(Integer A)] for Hero) Greater than 0
            • Then - Actions
              • -------- save skill level --------
              • Set SaveCount = (SaveCount + 1)
              • Set Save[SaveCount] = (Level of SaveLoad_Abilities[(Integer A)] for Hero)
              • Game - Display to (All players) the text: (String(Save[SaveCount]))
              • Set SaveCount = (SaveCount + 1)
              • Set Save[SaveCount] = (Level of SaveLoad_Abilities[(Integer A)] for Hero)
              • Set SaveCount = (SaveCount + 1)
              • Custom script: set udg_Save[udg_SaveCount] = bj_forLoopAIndex
            • Else - Actions
      • -------- Show Code --------
      • Custom script: set udg_Code = CodeGen_Compile()
      • Game - Display to (Player group((Triggering player))) for 60.00 seconds the text: Code

  • Load Abilities
    • Events
      • Player - Player 1 (Red) types a chat message containing -load as A substring
      • Player - Player 2 (Blue) types a chat message containing -load as A substring
      • Player - Player 3 (Teal) types a chat message containing -load as A substring
      • Player - Player 4 (Purple) types a chat message containing -load as A substring
    • Conditions
      • (String((Substring((Entered chat string), 1, 6))) as Lower case) Equal to -load
    • Actions
      • -------- Check if load is valid --------
      • Set Code = (Substring((Entered chat string), 7, 999))
      • Custom script: call CodeGen_Load(udg_Code)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • SaveLoad_Valid Equal to False
        • Then - Actions
          • Game - Display to (Player group((Triggering player))) for 10.00 seconds the text: SaveLoad_Error
          • Skip remaining actions
        • Else - Actions
      • -------- Start loading, load the hero first. --------
      • Set LoadCount = 0
      • Unit Group - Pick every unit in (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True)) and do (Unit - Remove (Picked unit) from the game)
      • Unit - Create 1 SaveLoad_Hero[Load[LoadCount]] for (Triggering player) at (Center of Region 008 <gen>) facing Default building facing degrees
      • Set Hero = (Last created unit)
      • Selection - Select (Last created unit) for (Triggering player)
      • -------- Load heroes level --------
      • Set LoadCount = (LoadCount + 1)
      • Hero - Set (Last created unit) Hero-level to Load[LoadCount], Hide level-up graphics
      • -------- Now load players gold --------
      • Set LoadCount = (LoadCount + 1)
      • Player - Set (Triggering player) Current gold to Load[LoadCount]
      • -------- Now items --------
      • Set LoadCount = (LoadCount + 1)
      • Set ItemCount = Load[LoadCount]
      • For each (Integer A) from 1 to Load[LoadCount], do (Actions)
        • Loop - Actions
          • Set LoadCount = (LoadCount + 1)
          • Hero - Create SaveLoad_Item[Load[LoadCount]] and give it to Hero
      • -------- abilities --------
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • Set LoadCount = (LoadCount + 1)
          • Set AbilityLevel = Load[LoadCount]
          • Game - Display to (All players) the text: (String(AbilityLevel))
          • Set LoadCount = (LoadCount + 1)
          • For each (Integer B) from 1 to AbilityLevel, do (Actions)
            • Loop - Actions
              • Custom script: call UnitAddAbility(udg_Hero, udg_SaveLoad_Abilities[udg_Load[udg_LoadCount]])
 
Level 6
Joined
Sep 19, 2007
Messages
215
im using the one based off codegen here on the hive i never noticed that but thats not what my problem is right now :(
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,197
As Gismo359 has said. You are not parsing the lumber from the load stream. As a result you are trying to interpret the lumber as ability data which obviously makes no sense.

Also your save and load logic for abilities is wrong. You are saving ability level twice and loading it once (again causing mal-alignment of data). You also perform a pointless Loop B during loading. You also never apply the loaded ability level to the loaded ability.

Your item save logic is also wrong. You make the false assumption that all items are filled sequentially in slots with no gaps. In reality players can have gaps with item placement in slots so that a hero carrying 5 items might have them in slots 2 to 6 instead of 1 to 5. You need to either push all items to sequential slots or skip empty slots so that all items are saved.

To make it clear, for every element you save you have to load in order. This is the principle behind a stream of data. If you skip an element during loading then it will interpret that element's data as something else which is wrong. Since steams are continuous the result is all elements past that point will be interpreted incorrectly and so be wrong.

What you are currently doing...
Code:
SAVE: hero id index -> hero level -> gold -> number of items -> number of items * [item id index] -> lumber -> 5 * [ability level -> ability level -> ability id index]
LOAD: hero id index -> hero level -> gold -> number of items -> number of items * [item id index] -> [COLOR="Red"]5 * [ability level -> ability id index][/COLOR]
Which is wrong because elements are missed out at the end.

What you should be doing...
Code:
SAVE: hero id index -> hero level -> gold -> number of items -> number of items * [item id index] -> lumber -> 5 * [COLOR="Green"][ability level -> ability id index][/COLOR]
LOAD: hero id index -> hero level -> gold -> number of items -> number of items * [item id index] -> [COLOR="Green"]lumber ->[/COLOR] 5 * [ability level -> ability id index]
Since then both are loaded correctly in the same order as they are saved.
 
Status
Not open for further replies.
Top