Save/Load Code, Yet Another

Discussion in 'Tutorial Repository' started by AceHart, Jan 21, 2007.

  1. Reflexar

    Reflexar New Member

    Ratings:
    +12 / 0 / -0
    How can I make so that the system doesn't save items which are NOT added to the list of items ( I mean the array )

    Since I want some items to not be saved....


    Please Help me! Kind regards!
     
  2. polo2005

    polo2005 Wana start playing LoL? http://tinyurl.com/369as27

    Ratings:
    +97 / 0 / -0
    edit 2:

    what if i want a save/laod that saves both abilties and lvl of them for more than 1 hero? would it work to move over the ability part to the ALL trigger?
     
  3. Reflexar

    Reflexar New Member

    Ratings:
    +12 / 0 / -0
    Please answer our questions Master AceHart :D
     
  4. Dasslokk

    Dasslokk New Member

    Ratings:
    +9 / 0 / -0
    I don't have any knowledge of this, but I was just wondering how you could get it to save the abilities as learned and not just the hero level. At least that wha happends when I load a saved code.
     
  5. kungfuturte0

    kungfuturte0 New Member

    Ratings:
    +2 / 0 / -0
    Hey, i can't seem to get abilities to be loaded?

    I enabled saveload all but abilities aren't saved
     
  6. SerraAvenger

    SerraAvenger Cuz I can

    Ratings:
    +236 / 0 / -0
    Oh Master...
    I today was thinking of how to do a save load code and came up with the same "compress all" thing, then I just saw you already do it the same way : )

    <3 that's so fine, 8-12 hours less to code for me ^^ (assuming you're twice as fast as I am)

    Although you might not even read this post, just thought I'ld say this.
    EDIT: I tested this a little bit and I had to see it is not exactly what I wanted. I thus coded my own system that doesn't use encryption/decryption, really compresses all info into one integer (perhaps one day I'll be using longinteger for that :D).
    For security, I use hashing (players enter passwords that act as a key, and if they forget the password they're able to reload it if they're playing with the name they last saved). That way, I'm much faster (and I guess shorter) than this, but I can't save as much info. I'll thus also implement a hash that maps big values (namely rawids) into a small array, and saves the array indicies instead.
    It is a little more complicated to use though, as the coder first needs to be initialized (only once, telling it which fields to use and how big they are) and then it can be used.

    Current information hold:
    the product of all field sizes must be <= 2³¹
    With longintegers:
    the product of all field sizes must be <= 10³⁶
     
  7. Vylatin

    Vylatin New Member

    Ratings:
    +32 / 0 / -0
    How many characters would it be if you want to save...

    Hero Type
    Hero Level
    Items
    Gold/lumber

    ?

    Too many characters is only pain. Please reply
     
  8. Tooblet

    Tooblet Active Member

    Ratings:
    +6 / 0 / -0
    I know Acehart has left us all alone here at thehelper :p
    But maybe there is someone else who might help me with a slight modification.

    I need this system to be able to get over 250 items in the item integer array.

    I find that the current maximum is 145 items. It must be some way to make that maximum limit higher, right?

    I know a bit of jass and vjass if that helps.
     
  9. ianu74

    ianu74 New Member

    Ratings:
    +8 / 0 / -0
    I copied the code yet i get errors like this.
    Code:
    Line 94:Expected a name
        set udg_Save[udg_SaveCount] = SaveLoad_Unit2Integer( udg_TempUnit )
    I ticked the create unknown variables while passing triggers box.
     
  10. gwcadu942

    gwcadu942 New Member

    Ratings:
    +0 / 0 / -0
    Very tks


    very tks

    +reppppppppppppppppppppppppppppppppppppppp

    i loves you!!!!!
     
  11. gwcadu942

    gwcadu942 New Member

    Ratings:
    +0 / 0 / -0
    help me plzzzz

    my is error


    SaveLoad Load All
    set udg_Validate = SaveLoad_Decode( udg_Code )
    set udg_TempUnitType = SaveLoad_Integer2Unit(udg_Save[udg_SaveCount])
    set udg_TempItemType = SaveLoad_Integer2Item(udg_Save[udg_SaveCount])


    SaveLoad Save All
    set udg_Save[udg_SaveCount] = SaveLoad_Unit2Integer( udg_TempUnit )
    set udg_Save[udg_SaveCount] = SaveLoad_Item2Integer( udg_TempItem )
    set udg_Code = SaveLoad_Encode()
     
  12. Renendaru

    Renendaru (Evol)ution is nothing without love.

    Ratings:
    +309 / 0 / -0
    Did you put the system core from the demo map into the map header of yours?
     
  13. gwcadu942

    gwcadu942 New Member

    Ratings:
    +0 / 0 / -0
    yes my map

    Why? demo map
     
  14. _TriNiTY_

    _TriNiTY_ New Member

    Ratings:
    +0 / 0 / -0
    thx for the save/load code..
    anyway, i tried to save with a nickname Worldedit, then i load the code with a nickname AAA, then, the decoding is successful -_-

    could you make it to be only loadable with 1 nickname?
    coz someone can copy another's code so easily
    thx
     
  15. egomanyak

    egomanyak New Member

    Ratings:
    +8 / 0 / -0
    how i add lumber save?
     
  16. Yoshii

    Yoshii New Member

    Ratings:
    +74 / 0 / -0
    ^^ clearly someone who did not read the 1st post not to be mean
    I didnt know anything about about save/load and was able to make one that save anything hero, lumber, gold,spent and unspent skill piont,lvl, ability just by donwloading the map posted and reading the 1st post.

    Thx for the great tutorial
     
  17. TDestroyer

    TDestroyer New Member

    Ratings:
    +0 / 0 / -0
    Help

    Dude this tutorial is awesome but i have a problem. I took your code and made it so it works on all the stuff i wanted it to. It works perfectly except that it only saves 1 item. if anyone can see my mistake let me know

    Code:
    Initialization
        Events
            Map initialization
        Conditions
        Actions
            -------- List of Heroes --------
            Set SaveLoad_Heroes_LastIndex = 2
            Set SaveLoad_Heroes[1] = Peasant
            Set SaveLoad_Heroes[2] = Fighter
            -------- List of Items --------
            Set SaveLoad_Items_LastIndex = 9
            Set SaveLoad_Items[1] = Short Sword
            Set SaveLoad_Items[2] = Dagger
            Set SaveLoad_Items[3] = Wooden Staff
            Set SaveLoad_Items[4] = Bow
            Set SaveLoad_Items[5] = Leather Armor
            Set SaveLoad_Items[6] = Robe
            Set SaveLoad_Items[9] = Vial of Healing
            -------- List of Abilities --------
            Set SaveLoad_Abilities_LastIndex = 5
            Set SaveLoad_Abilities[1] = Attribute Bonus - Peasant Hero
            Set SaveLoad_Abilities[2] = Critical Strike - Peasant Hero
            Set SaveLoad_Abilities[3] = Shockwave - Fighter Hero
            Set SaveLoad_Abilities[4] = Critical Strike - Fighter Hero
            Set SaveLoad_Abilities[5] = Martial Training - Fighter Hero
            -------- Other Variables --------
            Set SaveLoad_Alphabet = abcdefghijklmnopqrstuvwxyz
            Set SaveLoad_Initialized = False
    
    --------------------------------------------------------------------
    Save Control
        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
            -------- Prepare the save array with this player's Hero --------
            Set SaveCount = 0
            -------- Player's Gold/Lumber --------
            Set Save[1] = ((Triggering player) Current gold)
            Set Save[2] = ((Triggering player) Current lumber)
            -------- Take all Heroes --------
            Unit Group - Pick every unit in (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True)) and do (Actions)
                Loop - Actions
                    Set Hero = (Picked unit)
            -------- Save the Hero --------
            Custom script:   set udg_Save[3] = SaveLoad_Unit2Integer( udg_Hero )
            -------- Hero Experience --------
            Set Save[4] = (Hero experience of Hero)
            -------- How many items does he carry --------
            Set Save[5] = (Number of items carried by Hero)
            -------- Add all items --------
            Set SaveCount = 5
            For each (Integer A) from 1 to 6, do (Actions)
                Loop - Actions
                    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        If - Conditions
                            ((Item carried by Hero in slot (Integer A)) is owned) Equal to True
                        Then - Actions
                            -------- The actual item --------
                            Set SaveCount = (SaveCount + 1)
                            Set TempItem = (Item carried by Hero in slot (Integer A))
                            Custom script:   set udg_Save[udg_SaveCount] = SaveLoad_Item2Integer( udg_TempItem )
                            -------- The number of charges it has --------
                            Set SaveCount = (SaveCount + 1)
                            Set Save[SaveCount] = (Charges remaining in (Item carried by Hero in slot (Integer A)))
                        Else - Actions
            -------- Add all abilities --------
            For each (Integer A) from 1 to SaveLoad_Abilities_LastIndex, 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
                            -------- The actual ability --------
                            Set SaveCount = (SaveCount + 1)
                            Set Save[SaveCount] = (Integer A)
                            -------- Its level --------
                            Set SaveCount = (SaveCount + 1)
                            Set Save[SaveCount] = (Level of SaveLoad_Abilities[(Integer A)] for Hero)
                        Else - Actions
            -------- Turn values into code --------
            Custom script:   set udg_Code = SaveLoad_Encode()
            -------- Show code to player --------
            Quest - Display to (Player group((Triggering player))) the Secret message: Your code:
            Game - Display to (Player group((Triggering player))) for 60.00 seconds the text: Code
    ------------------------------------------------------------------
    Load Control
        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
            (Substring((Entered chat string), 1, 6)) Equal to (Matched chat string)
            (Length of (Entered chat string)) Greater than 6
        Actions
            -------- Try to decode what was typed --------
            Set Code = (Substring((Entered chat string), 7, (Length of (Entered chat string))))
            Custom script:   set udg_Validate = SaveLoad_Decode( udg_Code )
            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                If - Conditions
                    Validate Equal to False
                Then - Actions
                    -------- Invalid code --------
                    Game - Display to (Player group((Triggering player))) the text: There's some error ...
                    Skip remaining actions
                Else - Actions
            -------- It worked, let's do something with it --------
            Unit Group - Pick every unit in (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True)) and do (Actions)
                Loop - Actions
                    Unit - Remove (Picked unit) from the game
            Set TempInt = SaveCount
            Set SaveCount = 1
            -------- Restore Gold/Lumber --------
            Player - Set (Triggering player) Current gold to Save[1]
            Player - Set (Triggering player) Current lumber to Save[2]
            -------- For "number of Heroes", do --------
            -------- Restore Hero --------
            Custom script:   set udg_TempUnitType = SaveLoad_Integer2Unit(udg_Save[3])
            Unit - Create 1 TempUnitType for (Triggering player) at ((Triggering player) start location) facing Default building facing degrees
            Set PlayerHeroes[(Player number of (Triggering player))] = (Last created unit)
            -------- Set Experience --------
            Hero - Set (Last created unit) experience to Save[4], Hide level-up graphics
            -------- Recreate all items --------
            Set SaveCount = 5
            For each (Integer A) from 1 to Save[5], do (Actions)
                Loop - Actions
                    -------- The actual item --------
                    Set SaveCount = (SaveCount + 1)
                    Custom script:   set udg_TempItemType = SaveLoad_Integer2Item(udg_Save[udg_SaveCount])
                    Hero - Create TempItemType and give it to (Last created unit)
                    -------- Number of charges --------
                    Set SaveCount = (SaveCount + 1)
                    Item - Set charges remaining in (Last created item) to Save[SaveCount]
            -------- Give Skills --------
            For each (Integer SaveCount) from (SaveCount + 1) to TempInt, do (Actions)
                Loop - Actions
                    For each (Integer A) from 1 to Save[(SaveCount + 1)], do (Actions)
                        Loop - Actions
                            Custom script:   call SelectHeroSkill( GetLastCreatedUnit(), udg_SaveLoad_Abilities[ udg_Save[ udg_SaveCount ] ] )
                    Set SaveCount = (SaveCount + 1)
    
    I think the error is in the load code because the saves are longer when i have more items. But when i load i dont receive them...

    btw some of the variables that u set up i hard coded into the script, like case sensitivity so i didn't have so many variables
     
  18. NeuroToxin

    NeuroToxin New Member

    Ratings:
    +46 / 0 / -0
    Ok I get the error expected a name when I copied over everything and set it right please help. I cant enable anything without the error and I did copy over the header
     
  19. TDestroyer

    TDestroyer New Member

    Ratings:
    +0 / 0 / -0
    Help2

    I just found out that it wasn't the save/load code that was messing it up. I still don't know the problem but is in this code not the previous. This code is supposed to stack items (turning 1potion into 2), player lock items(prevent other players from picking them up), and slot lock(only allow 1 item of each type. ex: sword and staff both lvl 1 so u can only have 1 or the other).

    Here is the code...
    Code:
    Pick Up Item Control
        Events
            Unit - A unit Acquires an item
        Conditions
        Actions
            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                If - Conditions
                    (Item level of (Item being manipulated)) Equal to 0
                Then - Actions
                    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        If - Conditions
                            (Charges remaining in (Item being manipulated)) Equal to 0
                        Then - Actions
                            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                If - Conditions
                                    ((Custom value of (Item being manipulated)) Equal to 0) or ((Custom value of (Item being manipulated)) Equal to (Player number of (Owner of (Hero manipulating item))))
                                Then - Actions
                                    Item - Set the custom value of (Item being manipulated) to (Player number of (Owner of (Hero manipulating item)))
                                Else - Actions
                                    Game - Display to (Player group((Owner of (Hero manipulating item)))) the text: This item doesn't b...
                                    Hero - Drop (Item being manipulated) from (Hero manipulating item)
                        Else - Actions
                            For each (Integer A) from 1 to 6, do (Actions)
                                Loop - Actions
                                    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                        If - Conditions
                                            (Item-type of (Item carried by (Hero manipulating item) in slot (Integer A))) Equal to (Item-type of (Item being manipulated))
                                            (Item carried by (Hero manipulating item) in slot (Integer A)) Not equal to (Item being manipulated)
                                            (Charges remaining in (Item carried by (Hero manipulating item) in slot (Integer A))) Less than 99
                                        Then - Actions
                                            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                If - Conditions
                                                    ((Charges remaining in (Item carried by (Hero manipulating item) in slot (Integer A))) + (Charges remaining in (Item being manipulated))) Greater than 99
                                                Then - Actions
                                                    Item - Set charges remaining in (Item being manipulated) to ((Charges remaining in (Item carried by (Hero manipulating item) in slot (Integer A))) + ((Charges remaining in (Item being manipulated)) - 99))
                                                    Item - Set charges remaining in (Item carried by (Hero manipulating item) in slot (Integer A)) to 99
                                                    Hero - Drop (Item being manipulated) from (Hero manipulating item)
                                                Else - Actions
                                                    Item - Set charges remaining in (Item carried by (Hero manipulating item) in slot (Integer A)) to ((Charges remaining in (Item carried by (Hero manipulating item) in slot (Integer A))) + (Charges remaining in (Item being manipulated)))
                                                    Item - Remove (Item being manipulated)
                                        Else - Actions
                Else - Actions
                    For each (Integer A) from 1 to 6, do (Actions)
                        Loop - Actions
                            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                If - Conditions
                                    (Item level of (Item carried by (Hero manipulating item) in slot (Integer A))) Equal to (Item level of (Item being manipulated))
                                    (Item carried by (Hero manipulating item) in slot (Integer A)) Not equal to (Item being manipulated)
                                Then - Actions
                                    Game - Display to (Player group((Owner of (Hero manipulating item)))) the text: You already have a ...
                                    Hero - Drop (Item being manipulated) from (Hero manipulating item)
                                    Skip remaining actions
                                Else - Actions
                    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        If - Conditions
                            ((Custom value of (Item being manipulated)) Equal to 0) or ((Custom value of (Item being manipulated)) Equal to (Player number of (Owner of (Hero manipulating item))))
                        Then - Actions
                            Item - Set the custom value of (Item being manipulated) to (Player number of (Owner of (Hero manipulating item)))
                        Else - Actions
                            Game - Display to (Player group((Owner of (Hero manipulating item)))) the text: This item doesn't b...
                            Hero - Drop (Item being manipulated) from (Hero manipulating item)
    
    
    if you see any problems let me know
     
  20. SumQuestions

    SumQuestions New Member

    Ratings:
    +0 / 0 / -0
    The Multiple Heros isnt workin for me :/

    it actually never worked at all
     

Share This Page