• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Need help with making a bank system

Status
Not open for further replies.
Level 19
Joined
Aug 8, 2007
Messages
2,765
Yeah its me again, im gonna try to use this for all questions related for this systeem for here on out

Heres my current code

JASS:
struct Demo extends array
    private static Base encryptionKey
        private static method saveWithLocal takes nothing returns boolean
        local NumberStack stack = BigInt.create(encryptionKey)
        local string encrypted
        local integer i = 21
        local string s
        set SaveTriggers[GetPlayerId(GetTriggerPlayer())] = CreateTrigger()
        set SaveDialog[GetPlayerId(GetTriggerPlayer())] = DialogCreate()
        call TriggerAddAction(SaveTriggers[GetPlayerId(GetTriggerPlayer())], function thistype.onSaveDialogClick)
        
        //push numbers on to stack (save two values)
                        //value     max
        call SaveHeroLevel(udg_PlayerUnit[GetConvertedPlayerId(GetTriggerPlayer())], stack)
        call SaveGold(stack, GetTriggerPlayer())
        call SaveCustomInventory(stack, GetTriggerPlayer())
        call SaveHero(stack, GetTriggerPlayer())
        //display numbers in stack
        call DisplayTimedTextToPlayer(GetTriggerPlayer(),0,0,60,"Saving: 10,20")
        
        //encryption
        //EncryptNumber takes   BigInt number, integer security, integer shuffles, 
        //                      integer forPlayerId, string playerSalt, real checksumVariance 
        //                      returns string
        ///////////////////////////////////////////////////////////////////////////////////////////////
                                    //numbers   checksum (1 out of xxxx codes work)     shuffles (1-3)
                                    //                                                  if freeze, lower
        set encrypted=EncryptNumber(stack,      1000000,                                3, /*
        
                                    //player to save for            //password          //don't change
        */                          GetPlayerId(GetTriggerPlayer()),    "salt value",   .85)
        
        //add dashes
        set encrypted=AddRepeatedString(encrypted,"-",4,0)    //add "-" every 4 characters starting at 0
        
        //color                                  //number   lowercase    uppercase  special char (! ? *)        start
                                                 //colors are hexadecimal color codes december.com/html/spec/color2.html
        set encrypted=ColorCodeString(encrypted, "40e0d0",  "ff69b4",    "00AA00",  "ffff00",                   0)
        
        //display code                                          code string
        call AddBoolean(101, true, GetTriggerPlayer())
        call SaveData("f9ksl0ALS", GetTriggerPlayer())
        call LoadData("f9ksl0ALS", GetTriggerPlayer())
        if ReadBoolean(101, GetTriggerPlayer()) != true then
            call print("Your computer does not have localized storing enabled. Type '-write' and you will get further instructions to enable. Untill then, this code will overwrite your first slot")
            call AddString(1, encrypted, GetTriggerPlayer())
            call SaveData("f9ksl0ALS", GetTriggerPlayer())
        else
            loop
                set s = ReadString(i, GetTriggerPlayer())
                if StringLength(s) < 5 then                                     
                    set SaveButtonArray[(i - 20) + (GetPlayerId(GetTriggerPlayer()) * 20)] = DialogAddButton(SaveDialog[GetPlayerId(GetTriggerPlayer())], "Empty Slot", i - 20)                                  
                    call TriggerRegisterDialogButtonEvent(SaveTriggers[GetPlayerId(GetTriggerPlayer())], SaveButtonArray[(i - 20) + (GetPlayerId(GetTriggerPlayer()) * 20)])
                else                                     
                    set SaveButtonArray[(i - 20) + (GetPlayerId(GetTriggerPlayer()) * 20)] = DialogAddButton(SaveDialog[GetPlayerId(GetTriggerPlayer())], s, i - 20)               
                    call TriggerRegisterDialogButtonEvent(SaveTriggers[GetPlayerId(GetTriggerPlayer())], SaveButtonArray[(i - 20) + (GetPlayerId(GetTriggerPlayer()) * 20)])
                endif
                set i = i + 1
                exitwhen i == 31
            endloop
            set SaveButtonArray[(21) + (GetPlayerId(GetTriggerPlayer()) * 20)] = DialogAddButton(SaveDialog[GetPlayerId(GetTriggerPlayer())], s, 21)               
            call TriggerRegisterDialogButtonEvent(SaveTriggers[GetPlayerId(GetTriggerPlayer())], SaveButtonArray[(21) + (GetPlayerId(GetTriggerPlayer()) * 20)])
            set SaveButtonArray[(22) + (GetPlayerId(GetTriggerPlayer()) * 20)] = DialogAddButton(SaveDialog[GetPlayerId(GetTriggerPlayer())], s, 22)               
            call TriggerRegisterDialogButtonEvent(SaveTriggers[GetPlayerId(GetTriggerPlayer())], SaveButtonArray[(22) + (GetPlayerId(GetTriggerPlayer()) * 20)])
            call DialogDisplay(GetTriggerPlayer(), SaveDialog[GetPlayerId(GetTriggerPlayer())], true)
            set EncryptionString[GetPlayerId(GetTriggerPlayer())] = encrypted
        endif
        call print("The")
        
        //destroy stack (clean up, prevent leaks)
        call stack.destroy()
        
        return false
    endmethod
    
    private static method loadWithCode takes nothing returns boolean
        local player GP=GetTriggerPlayer()
        local string s=GetEventPlayerChatString()
        local NumberStack stack
        set s=RemoveString(s,GetEventPlayerChatStringMatched(),1,       0)
        set s=RemoveString(s," ",0,0)       
        set s=RemoveString(s,"-",0,0)
        if (0<StringLength(s)) then
            set stack = DecryptNumber(s,        encryptionKey,                          1000000,/*
                                    shuffles used in encryption     played id to decrypt for
            */                      3,                              GetPlayerId(GetTriggerPlayer()),/*
                                    password used in encryption     don't change
            */                      "salt value",                   .85)
            if (0!=stack) then
                call RemoveUnit(udg_PlayerUnit[GetConvertedPlayerId(GP)])
                call LoadHero(stack, GP)
                call SetHeroMain(GetLastCreatedUnit(),GP)
                call LoadCustomInventory(stack, GP)
                call LoadGold(stack, GP)
                call LoadHeroLevel(udg_PlayerUnit[GetConvertedPlayerId(GetTriggerPlayer())], stack)
    private static method loadWithBank takes nothing returns boolean
        local integer i = 20
        local string s
        set LoadTriggers[GetPlayerId(GetTriggerPlayer())] = CreateTrigger()
        set LoadDialog[GetPlayerId(GetTriggerPlayer())] = DialogCreate()
        loop
                set s = ReadString(i, GetTriggerPlayer())
                if StringLength(s) < 5 then                                     
                    set LoadButtonArray[(i - 20) + (GetPlayerId(GetTriggerPlayer()) * 20)] = DialogAddButton(LoadDialog[GetPlayerId(GetTriggerPlayer())], "Empty Slot", i - 20)                                  
                    call TriggerRegisterDialogButtonEvent(LoadTriggers[GetPlayerId(GetTriggerPlayer())], LoadButtonArray[(i - 20) + (GetPlayerId(GetTriggerPlayer()) * 20)])
                else                                     
                    set LoadButtonArray[(i - 20) + (GetPlayerId(GetTriggerPlayer()) * 20)] = DialogAddButton(LoadDialog[GetPlayerId(GetTriggerPlayer())], s, i - 20)               
                    call TriggerRegisterDialogButtonEvent(LoadTriggers[GetPlayerId(GetTriggerPlayer())], LoadButtonArray[(i - 20) + (GetPlayerId(GetTriggerPlayer()) * 20)])
                endif
                set i = i + 1
                exitwhen i == 31
        endloop                                     
        set LoadButtonArray[(21) + (GetPlayerId(GetTriggerPlayer()) * 20)] = DialogAddButton(LoadDialog[GetPlayerId(GetTriggerPlayer())], "Other Page", 21)                                 
        call TriggerRegisterDialogButtonEvent(LoadTriggers[GetPlayerId(GetTriggerPlayer())], LoadButtonArray[(21) + (GetPlayerId(GetTriggerPlayer()) * 20)])
        set LoadButtonArray[(22) + (GetPlayerId(GetTriggerPlayer()) * 20)] = DialogAddButton(LoadDialog[GetPlayerId(GetTriggerPlayer())], "Exit Menu", 22)                                 
        call TriggerRegisterDialogButtonEvent(LoadTriggers[GetPlayerId(GetTriggerPlayer())], LoadButtonArray[(22) + (GetPlayerId(GetTriggerPlayer()) * 20)])
        call DialogDisplay(GetTriggerPlayer(), LoadDialog[GetPlayerId(GetTriggerPlayer())], true)
        return false
    endmethod
        
    private static method onInit takes nothing returns nothing
        local integer i = 0
        set encryptionKey=Base["0123456789abcdefghijklmnopqrstuvwxyz"]
        call InitSave("-savecode",      "-loadcode",      Condition(function thistype.saveWithCode),/*
                                load function
                    */Condition(function thistype.loadWithCode))
                    
        call InitSave("-savebank",      "-loadbank",      Condition(function thistype.saveWithLocal),/*
                                load function
                    */Condition(function thistype.loadWithBank))
        loop
            call CreateData(Player(i))
            call LoadData("f9ksl0ALS", Player(i))
            set i = i + 1
            exitwhen i == 11
        endloop
    endmethod
    private static method onSaveDialogClick takes nothing returns nothing
    local integer i2 = 0
    local integer i = 30
    local string s
    if GetClickedDialog() == SaveButtonArray[21 + (20 * GetPlayerId(GetTriggerPlayer()))] then
            loop
                set s = ReadString(i, GetTriggerPlayer())
                if StringLength(s) < 5 then                                     
                    set SaveButtonArray[(i - 20) + (GetPlayerId(GetTriggerPlayer()) * 20)] = DialogAddButton(SaveDialog[GetPlayerId(GetTriggerPlayer())], "Empty Slot", i - 20)                                  
                    call TriggerRegisterDialogButtonEvent(SaveTriggers[GetPlayerId(GetTriggerPlayer())], SaveButtonArray[(i - 20) + (GetPlayerId(GetTriggerPlayer()) * 20)])
                else                                     
                    set SaveButtonArray[(i - 20) + (GetPlayerId(GetTriggerPlayer()) * 20)] = DialogAddButton(SaveDialog[GetPlayerId(GetTriggerPlayer())], s, i - 20)               
                    call TriggerRegisterDialogButtonEvent(SaveTriggers[GetPlayerId(GetTriggerPlayer())], SaveButtonArray[(i - 20) + (GetPlayerId(GetTriggerPlayer()) * 20)])
                endif
                set i = i + 1
                exitwhen i == 41
            endloop
    elseif GetClickedDialog() == SaveButtonArray[21 + (20 * GetPlayerId(GetTriggerPlayer()))] then
    endif
        
        loop
            if GetClickedDialog() == SaveButtonArray[i2 + (20 * GetPlayerId(GetTriggerPlayer()))] then
                call AddString(i2, EncryptionString[GetPlayerId(GetTriggerPlayer())], GetTriggerPlayer())
                call AddString(i2 + 20, "Level " + I2S(GetHeroLevel(udg_PlayerUnit[GetPlayerId(GetTriggerPlayer())])) + " " + GetUnitName(udg_PlayerUnit[GetPlayerId(GetTriggerPlayer())]), GetTriggerPlayer())
                call print("lol")
                set i2 = 500
            endif
            set i2 = i + 1
            exitwhen i2 == 21
        endloop
    endmethod
    
    
endstruct

Ok, obviously 2 things

1) cut out a bunch of stuff you didnt need to see

2) There is no function for clicking a load button dialog

3) Exit dialog button has no text, its just elseif .. endif

Heres my current 4 problems

1) "Other Page" and "Exit Menu" dont display, the button is there but there isnt text

2) I dont think its writing properly. If i save a hero and than try to save again, the slot still says empty

3) It prints the debug "lol" (in the save on click trigger) a ton of times

4) Other Page functions as if it was a save slot, printing lol a ton
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
ik, when i get the chance im going to assign TriggeringPlayer and IdOf(TriggeringPlayer) to varaibles

e/ ok did a few things

1) inlined GetTriggeringPlayer() to tplay

2) inlined GetPlayerId(GetTriggeringPlayer() to pnumb

3) Fixed what mag said

4) cleared a few leaks

still need the other problems

JASS:
struct Demo extends array
    private static Base encryptionKey
        private static method saveWithLocal takes nothing returns boolean
        local player tplay = GetTriggerPlayer()
        local integer pnumb = GetPlayerId(tplay)
        local NumberStack stack = BigInt.create(encryptionKey)
        local string encrypted
        local integer i = 21
        local string s
        set SaveTriggers[pnumb] = CreateTrigger()
        set SaveDialog[pnumb] = DialogCreate()
        call TriggerAddAction(SaveTriggers[pnumb], function thistype.onSaveDialogClick)
        call SaveHeroLevel(udg_PlayerUnit[pnumb], stack)
        call SaveGold(stack, tplay)
        call SaveCustomInventory(stack, tplay)
        call SaveHero(stack, tplay)
        call DisplayTimedTextToPlayer(tplay,0,0,60,"Saving. . .")
        set encrypted=EncryptNumber(stack,      1000000,                                3,  pnumb,    "salt value",   .85)
        set encrypted=AddRepeatedString(encrypted,"-",4,0)
        set encrypted=ColorCodeString(encrypted, "40e0d0",  "ff69b4",    "00AA00",  "ffff00",                   0)
        call AddBoolean(101, true, tplay)
        call SaveData("f9ksl0ALS", tplay)
        call LoadData("f9ksl0ALS", tplay)
        if ReadBoolean(101, tplay) != true then
            call print("Your computer does not have localized storing enabled. Type '-write' and you will get further instructions to enable. Untill then, this code will overwrite your first slot")
            call AddString(i + 20, "Level " + I2S(GetHeroLevel(udg_PlayerUnit[pnumb])) + " " + GetUnitName(udg_PlayerUnit[pnumb]), tplay)
            call AddString(i, encrypted, tplay)
            call SaveData("f9ksl0ALS", tplay)
        else
            loop
                set s = ReadString(i, tplay)
                if StringLength(s) < 5 then                                     
                    set SaveButtonArray[(i - 20) + (pnumb * 20)] = DialogAddButton(SaveDialog[pnumb], "Empty Slot", i - 20)                                  
                    call TriggerRegisterDialogButtonEvent(SaveTriggers[pnumb], SaveButtonArray[(i - 20) + (pnumb * 20)])
                else                                     
                    set SaveButtonArray[(i - 20) + (pnumb * 20)] = DialogAddButton(SaveDialog[pnumb], s, i - 20)               
                    call TriggerRegisterDialogButtonEvent(SaveTriggers[pnumb], SaveButtonArray[(i - 20) + (pnumb * 20)])
                endif
                set i = i + 1
                exitwhen i == 31
            endloop
            set SaveButtonArray[(21) + (pnumb * 20)] = DialogAddButton(SaveDialog[pnumb], s, 21)               
            call TriggerRegisterDialogButtonEvent(SaveTriggers[pnumb], SaveButtonArray[(21) + (pnumb * 20)])
            set SaveButtonArray[(22) + (pnumb * 20)] = DialogAddButton(SaveDialog[pnumb], s, 22)               
            call TriggerRegisterDialogButtonEvent(SaveTriggers[pnumb], SaveButtonArray[(22) + (pnumb * 20)])
            call DialogDisplay(tplay, SaveDialog[pnumb], true)
            set EncryptionString[pnumb] = encrypted
        endif
        call print("The")
        call stack.destroy()
        set tplay = null
        
        return false
    endmethod
    private static method loadWithBank takes nothing returns boolean
        local player tplay = GetTriggerPlayer()
        local integer pnumb = GetPlayerId(tplay)
        local integer i = 20
        local string s
        set LoadTriggers[pnumb] = CreateTrigger()
        set LoadDialog[pnumb] = DialogCreate()
        loop
            set s = ReadString(i, tplay)
            if StringLength(s) < 5 then                                     
                set LoadButtonArray[(i - 20) + (pnumb * 20)] = DialogAddButton(LoadDialog[pnumb], "Empty Slot", i - 20)                                  
                call TriggerRegisterDialogButtonEvent(LoadTriggers[pnumb], LoadButtonArray[(i - 20) + (pnumb * 20)])
            else                                     
                set LoadButtonArray[(i - 20) + (pnumb * 20)] = DialogAddButton(LoadDialog[pnumb], s, i - 20)               
                call TriggerRegisterDialogButtonEvent(LoadTriggers[pnumb], LoadButtonArray[(i - 20) + (pnumb * 20)])
            endif
            set i = i + 1
            exitwhen i == 31
        endloop                                     
        set LoadButtonArray[(21) + (pnumb * 20)] = DialogAddButton(LoadDialog[pnumb], "Other Page", 21)                                 
        call TriggerRegisterDialogButtonEvent(LoadTriggers[pnumb], LoadButtonArray[(21) + (pnumb * 20)])
        set LoadButtonArray[(22) + (pnumb * 20)] = DialogAddButton(LoadDialog[pnumb], "Exit Menu", 22)                                 
        call TriggerRegisterDialogButtonEvent(LoadTriggers[pnumb], LoadButtonArray[(22) + (pnumb * 20)])
        call DialogDisplay(tplay, LoadDialog[pnumb], true)
        set tplay = null
        return false
    endmethod
        
    private static method onInit takes nothing returns nothing
        local integer i = 0
        set encryptionKey=Base["0123456789abcdefghijklmnopqrstuvwxyz"]
        call InitSave("-savecode",      "-loadcode",      Condition(function thistype.saveWithCode),/*
                                load function
                    */Condition(function thistype.loadWithCode))
                    
        call InitSave("-savebank",      "-loadbank",      Condition(function thistype.saveWithLocal),/*
                                load function
                    */Condition(function thistype.loadWithBank))
        loop
            call CreateData(Player(i))
            call LoadData("f9ksl0ALS", Player(i))
            set i = i + 1
            exitwhen i == 11
        endloop
    endmethod
    private static method onSaveDialogClick takes nothing returns nothing
    local player tplay = GetTriggerPlayer()
    local integer pnumb = GetPlayerId(tplay)
    local integer i2 = 0
    local integer i = 30
    local string s
    if GetClickedDialog() == SaveButtonArray[21 + (20 * pnumb)] then
            loop
                set s = ReadString(i, tplay)
                if StringLength(s) < 5 then                                     
                    set SaveButtonArray[(i - 20) + (pnumb * 20)] = DialogAddButton(SaveDialog[pnumb], "Empty Slot", i - 20)                                  
                    call TriggerRegisterDialogButtonEvent(SaveTriggers[pnumb], SaveButtonArray[(i - 20) + (pnumb * 20)])
                else                                     
                    set SaveButtonArray[(i - 20) + (pnumb * 20)] = DialogAddButton(SaveDialog[pnumb], s, i - 20)               
                    call TriggerRegisterDialogButtonEvent(SaveTriggers[pnumb], SaveButtonArray[(i - 20) + (pnumb * 20)])
                endif
                set i = i + 1
                exitwhen i == 41
            endloop
    elseif GetClickedDialog() == SaveButtonArray[22 + (20 * pnumb)] then
    endif
        
        loop
            if GetClickedDialog() == SaveButtonArray[i2 + (20 * pnumb)] then
                call AddString(i2, EncryptionString[pnumb], tplay)
                call AddString(i2 + 20, "Level " + I2S(GetHeroLevel(udg_PlayerUnit[pnumb])) + " " + GetUnitName(udg_PlayerUnit[pnumb]), tplay)
                call print("lol")
                set i2 = 20
            endif
            set i2 = i + 1
            exitwhen i2 == 21
        endloop
        set tplay = null
    endmethod
    
    
endstruct
 
Last edited:
Level 19
Joined
Aug 8, 2007
Messages
2,765
heres current full trigger + the other one that writes data

JASS:
function SaveGold takes NumberStack stack, player p returns nothing
    call stack.push(CompressInt(GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD)),CompressInt(1000000))
endfunction
function SetHeroMain takes unit u, player p returns nothing
    call InitEquipment(u)
    call UnitAddItemToSlotById(GetLastCreatedUnit(), 'I01I', 5)
    set udg_PlayerUnit[GetConvertedPlayerId(p)] = u
    endfunction
function LoadGold takes NumberStack stack, player p returns nothing
    call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, DecompressInt(stack.pop(CompressInt(1000000))))
endfunction
function SaveHero takes NumberStack stack, player p returns nothing
    call stack.push(Heroes[GetUnitTypeId(udg_PlayerUnit[GetConvertedPlayerId(GetTriggerPlayer())])].id,Heroes.count)
endfunction
function LoadHero takes NumberStack stack, player p returns nothing
    local location l = GetRectCenter(gg_rct_Hero_SpawnRespawn)
    call CreateNUnitsAtLoc( 1, Heroes[stack.pop(Heroes.count)].raw, GetTriggerPlayer(), l, bj_UNIT_FACING )
    call RemoveLocation(l)
endfunction
function SaveCustomInventory takes NumberStack stack, player p returns nothing
    call stack.push(Items[GetEquippedItemTypeId(p, 1)].id, Items.count)
    call stack.push(Items[GetEquippedItemTypeId(p, 2)].id, Items.count)
    call stack.push(Items[GetEquippedItemTypeId(p, 3)].id, Items.count)
    call stack.push(Items[GetEquippedItemTypeId(p, 4)].id, Items.count)
    call stack.push(Items[GetEquippedItemTypeId(p, 5)].id, Items.count)
    call stack.push(Items[GetEquippedItemTypeId(p, 6)].id, Items.count)
    call stack.push(Items[GetEquippedItemTypeId(p, 7)].id, Items.count)
    call stack.push(Items[GetEquippedItemTypeId(p, 8)].id, Items.count)
    call stack.push(Items[GetEquippedItemTypeId(p, 9)].id, Items.count)
endfunction
function LoadCustomInventory takes NumberStack stack, player p returns nothing
    call EquipItem(p, CreateItem(Items[stack.pop(Items.count)].raw,0,0))
    call EquipItem(p, CreateItem(Items[stack.pop(Items.count)].raw,0,0))
    call EquipItem(p, CreateItem(Items[stack.pop(Items.count)].raw,0,0))
    call EquipItem(p, CreateItem(Items[stack.pop(Items.count)].raw,0,0))
    call EquipItem(p, CreateItem(Items[stack.pop(Items.count)].raw,0,0))
    call EquipItem(p, CreateItem(Items[stack.pop(Items.count)].raw,0,0))
    call EquipItem(p, CreateItem(Items[stack.pop(Items.count)].raw,0,0))
    call EquipItem(p, CreateItem(Items[stack.pop(Items.count)].raw,0,0))
    call EquipItem(p, CreateItem(Items[stack.pop(Items.count)].raw,0,0))
endfunction
struct Demo extends array
    private static Base encryptionKey
    private static constant string BankId = "F39ALSDLA"
    
    private static method saveWithCode takes nothing returns boolean
                                                    //notice that encryption key is passed in
        local NumberStack stack = BigInt.create(encryptionKey)     //create a number stack
        local string encrypted
        
        //push numbers on to stack (save two values)
                        //value     max
        call SaveHeroLevel(udg_PlayerUnit[GetConvertedPlayerId(GetTriggerPlayer())], stack)
        call SaveGold(stack, GetTriggerPlayer())
        call SaveCustomInventory(stack, GetTriggerPlayer())
        call SaveHero(stack, GetTriggerPlayer())
        //display numbers in stack
        call DisplayTimedTextToPlayer(GetTriggerPlayer(),0,0,60,"Saving. . .")
        
        //encryption
        //EncryptNumber takes   BigInt number, integer security, integer shuffles, 
        //                      integer forPlayerId, string playerSalt, real checksumVariance 
        //                      returns string
        ///////////////////////////////////////////////////////////////////////////////////////////////
                                    //numbers   checksum (1 out of xxxx codes work)     shuffles (1-3)
                                    //                                                  if freeze, lower
        set encrypted=EncryptNumber(stack,      1000000,                                3, /*
        
                                    //player to save for            //password          //don't change
        */                          GetPlayerId(GetTriggerPlayer()),    "salt value",   .85)
        
        //add dashes
        set encrypted=AddRepeatedString(encrypted,"-",4,0)    //add "-" every 4 characters starting at 0
        
        //color                                  //number   lowercase    uppercase  special char (! ? *)        start
                                                 //colors are hexadecimal color codes december.com/html/spec/color2.html
        set encrypted=ColorCodeString(encrypted, "40e0d0",  "ff69b4",    "00AA00",  "ffff00",                   0)
        
        //display code                                          code string
        call DisplayTimedTextToPlayer(GetTriggerPlayer(),0,0,60,encrypted)
        
        //destroy stack (clean up, prevent leaks)
        call stack.destroy()
        
        return false
    endmethod
        private static method saveWithLocal takes nothing returns boolean
        local player tplay = GetTriggerPlayer()
        local integer pnumb = GetPlayerId(tplay)
        local NumberStack stack = BigInt.create(encryptionKey)
        local string encrypted
        local integer i = 21
        local string s
        set SaveTriggers[pnumb] = CreateTrigger()
        set SaveDialog[pnumb] = DialogCreate()
        call TriggerAddAction(SaveTriggers[pnumb], function thistype.onSaveDialogClick)
        call SaveHeroLevel(udg_PlayerUnit[pnumb], stack)
        call SaveGold(stack, tplay)
        call SaveCustomInventory(stack, tplay)
        call SaveHero(stack, tplay)
        call DisplayTimedTextToPlayer(tplay,0,0,60,"Saving. . .")
        set encrypted=EncryptNumber(stack,      1000000,                                3,  pnumb,    "salt value",   .85)
        set encrypted=AddRepeatedString(encrypted,"-",4,0)
        set encrypted=ColorCodeString(encrypted, "40e0d0",  "ff69b4",    "00AA00",  "ffff00",                   0)
        call AddBoolean(101, true, tplay)
        call SaveData(BankId, tplay)
        call LoadData(BankId, tplay)
        if ReadBoolean(101, tplay) != true then
            call print("Your computer does not have localized storing enabled. Type '-write' and you will get further instructions to enable. Untill then, this code will overwrite your first slot")
            call AddString(i + 20, "Level " + I2S(GetHeroLevel(udg_PlayerUnit[pnumb])) + " " + GetUnitName(udg_PlayerUnit[pnumb]), tplay)
            call AddString(i, encrypted, tplay)
            call SaveData(BankId, tplay)
        else
            loop
                set s = ReadString(i, tplay)
                if StringLength(s) < 5 then                                     
                    set SaveButtonArray[(i - 20) + (pnumb * 20)] = DialogAddButton(SaveDialog[pnumb], "Empty Slot", i - 20)                                  
                    call TriggerRegisterDialogButtonEvent(SaveTriggers[pnumb], SaveButtonArray[(i - 20) + (pnumb * 20)])
                    call print(s)
                else                                     
                    set SaveButtonArray[(i - 20) + (pnumb * 20)] = DialogAddButton(SaveDialog[pnumb], s, i - 20)               
                    call TriggerRegisterDialogButtonEvent(SaveTriggers[pnumb], SaveButtonArray[(i - 20) + (pnumb * 20)])
                    call print(s)
                endif
                set i = i + 1
                exitwhen i == 31
            endloop
            set SaveButtonArray[(21) + (pnumb * 20)] = DialogAddButton(SaveDialog[pnumb], "Other Page", 21)               
            call TriggerRegisterDialogButtonEvent(SaveTriggers[pnumb], SaveButtonArray[(21) + (pnumb * 20)])
            set SaveButtonArray[(22) + (pnumb * 20)] = DialogAddButton(SaveDialog[pnumb], "Exit Dialog", 22)               
            call TriggerRegisterDialogButtonEvent(SaveTriggers[pnumb], SaveButtonArray[(22) + (pnumb * 20)])
            call DialogDisplay(tplay, SaveDialog[pnumb], true)
            set EncryptionString[pnumb] = encrypted
        endif
        call stack.destroy()
        set tplay = null
        
        return false
    endmethod
    
    private static method loadWithCode takes nothing returns boolean
        local player GP=GetTriggerPlayer()
        local string s=GetEventPlayerChatString()
        local NumberStack stack
        set s=RemoveString(s,GetEventPlayerChatStringMatched(),1,       0)
        set s=RemoveString(s," ",0,0)       
        set s=RemoveString(s,"-",0,0)
        if (0<StringLength(s)) then
            set stack = DecryptNumber(s,        encryptionKey,                          1000000,/*
                                    shuffles used in encryption     played id to decrypt for
            */                      3,                              GetPlayerId(GetTriggerPlayer()),/*
                                    password used in encryption     don't change
            */                      "salt value",                   .85)
            if (0!=stack) then
                call RemoveUnit(udg_PlayerUnit[GetConvertedPlayerId(GP)])
                call LoadHero(stack, GP)
                call SetHeroMain(GetLastCreatedUnit(),GP)
                call LoadCustomInventory(stack, GP)
                call LoadGold(stack, GP)
                call LoadHeroLevel(udg_PlayerUnit[GetConvertedPlayerId(GetTriggerPlayer())], stack)
                call DisplayTimedTextToPlayer(GP,0,0,60,"Loaded Successfully!")
                
            else
                call DisplayTimedTextToPlayer(GetTriggerPlayer(),0,0,60,"Invalid Code")
            endif
        else
            call DisplayTimedTextToPlayer(GetTriggerPlayer(),0,0,60,"Invalid Code")
        endif
        
        return false
    endmethod
    private static method loadWithBank takes nothing returns boolean
        local player tplay = GetTriggerPlayer()
        local integer pnumb = GetPlayerId(tplay)
        local integer i = 20
        local string s
        set LoadTriggers[pnumb] = CreateTrigger()
        set LoadDialog[pnumb] = DialogCreate()
        loop
            set s = ReadString(i, tplay)
            if StringLength(s) < 5 then                                     
                set LoadButtonArray[(i - 20) + (pnumb * 20)] = DialogAddButton(LoadDialog[pnumb], "Empty Slot", i - 20)                                  
                call TriggerRegisterDialogButtonEvent(LoadTriggers[pnumb], LoadButtonArray[(i - 20) + (pnumb * 20)])
            else                                     
                set LoadButtonArray[(i - 20) + (pnumb * 20)] = DialogAddButton(LoadDialog[pnumb], s, i - 20)               
                call TriggerRegisterDialogButtonEvent(LoadTriggers[pnumb], LoadButtonArray[(i - 20) + (pnumb * 20)])
            endif
            set i = i + 1
            exitwhen i == 31
        endloop                                     
        set LoadButtonArray[(21) + (pnumb * 20)] = DialogAddButton(LoadDialog[pnumb], "Other Page", 21)                                 
        call TriggerRegisterDialogButtonEvent(LoadTriggers[pnumb], LoadButtonArray[(21) + (pnumb * 20)])
        set LoadButtonArray[(22) + (pnumb * 20)] = DialogAddButton(LoadDialog[pnumb], "Exit Menu", 22)                                 
        call TriggerRegisterDialogButtonEvent(LoadTriggers[pnumb], LoadButtonArray[(22) + (pnumb * 20)])
        call DialogDisplay(tplay, LoadDialog[pnumb], true)
        set tplay = null
        return false
    endmethod
        
    private static method onInit takes nothing returns nothing
        local integer i = 0
        set encryptionKey=Base["0123456789abcdefghijklmnopqrstuvwxyz"]
        call InitSave("-savecode",      "-loadcode",      Condition(function thistype.saveWithCode),/*
                                load function
                    */Condition(function thistype.loadWithCode))
                    
        call InitSave("-savebank",      "-loadbank",      Condition(function thistype.saveWithLocal),/*
                                load function
                    */Condition(function thistype.loadWithBank))
        loop
            call CreateData(Player(i))
            call LoadData("f9ksl0ALS", Player(i))
            set i = i + 1
            exitwhen i == 11
        endloop
    endmethod
    private static method onSaveDialogClick takes nothing returns nothing
    local player tplay = GetTriggerPlayer()
    local integer pnumb = GetPlayerId(tplay)
    local integer i2 = 0
    local integer i = 30
    local string s
    if GetClickedButton() == SaveButtonArray[21 + (20 * pnumb)] then
        call DialogClear(SaveDialog[pnumb])
            loop
                set s = ReadString(i, tplay)
                if StringLength(s) < 5 then                                     
                    set SaveButtonArray[(i - 20) + (pnumb * 20)] = DialogAddButton(SaveDialog[pnumb], "Empty Slot", i - 20)                                  
                    call TriggerRegisterDialogButtonEvent(SaveTriggers[pnumb], SaveButtonArray[(i - 20) + (pnumb * 20)])
                else                                     
                    set SaveButtonArray[(i - 20) + (pnumb * 20)] = DialogAddButton(SaveDialog[pnumb], s, i - 20)               
                    call TriggerRegisterDialogButtonEvent(SaveTriggers[pnumb], SaveButtonArray[(i - 20) + (pnumb * 20)])
                endif
                set i = i + 1
                exitwhen i == 41
            endloop
    elseif GetClickedButton() == SaveButtonArray[22 + (20 * pnumb)] then
        call DialogDestroy(SaveDialog[pnumb])
    endif
        
        loop
            if GetClickedButton() == SaveButtonArray[i2 + (20 * pnumb)] then
                call AddString(i2, EncryptionString[pnumb], tplay)
                call AddString(i2 + 20, "Level " + I2S(GetHeroLevel(udg_PlayerUnit[pnumb])) + " " + GetUnitName(udg_PlayerUnit[pnumb]), tplay)
                call print("lol")
                set i2 = 20
            endif
            set i2 = i + 1
            exitwhen i2 == 21
        endloop
        set tplay = null
    endmethod
    
    private static method onLoadDialogClick takes nothing returns nothing
    local player tplay = GetTriggerPlayer()
    local integer pnumb = GetPlayerId(tplay)
    local integer i2 = 0
    local integer i = 30
    local string s
    if GetClickedDialog() == LoadButtonArray[21 + (20 * pnumb)] then
            loop
                set s = ReadString(i, tplay)
                if StringLength(s) < 5 then                                     
                    set SaveButtonArray[(i - 20) + (pnumb * 20)] = DialogAddButton(LoadDialog[pnumb], "Empty Slot", i - 20)                                  
                    call TriggerRegisterDialogButtonEvent(LoadTriggers[pnumb], LoadButtonArray[(i - 20) + (pnumb * 20)])
                else                                     
                    set SaveButtonArray[(i - 20) + (pnumb * 20)] = DialogAddButton(LoadDialog[pnumb], s, i - 20)               
                    call TriggerRegisterDialogButtonEvent(LoadTriggers[pnumb], LoadButtonArray[(i - 20) + (pnumb * 20)])
                endif
                set i = i + 1
                exitwhen i == 41
            endloop
    elseif GetClickedDialog() == LoadButtonArray[22 + (20 * pnumb)] then
        call DialogDestroy(LoadDialog[pnumb])
    endif
        
        loop
            if GetClickedDialog() == LoadButtonArray[i2 + (20 * pnumb)] then
                call AddString(i2, EncryptionString[pnumb], tplay)
                call AddString(i2 + 20, "Level " + I2S(GetHeroLevel(udg_PlayerUnit[pnumb])) + " " + GetUnitName(udg_PlayerUnit[pnumb]), tplay)
                call print("lol")
                set i2 = 20
            endif
            set i2 = i + 1
            exitwhen i2 == 21
        endloop
        set tplay = null
    endmethod
    
    
endstruct
JASS:
library DATA initializer onInit

  // SETUP'S DATA MANAGER
  globals
    string  SAVE_PATH      = "C:\\Documents and Settings\\All Users\\Application Data\\Microsoft\\" // FILE PATH (Can be [C:\\TEMP\\EWIX])
    string  SAVE_TYPE      = ".txt"          // FILE TYPE (Can be [all posible types])
  endglobals

  // CODE PART

    globals
        string array EncryptionString
        button array LoadButtonArray
        dialog array SaveDialog
        dialog array LoadDialog
        trigger array SaveTriggers
        trigger array LoadTriggers
    endglobals
    
  globals
    private integer SyncInt   = 0
    private real    SyncFlt   = 0
    private player  SyncPlr   = null
    private string  SyncStr   = null
    private boolean SyncBool  = false

    private gamecache SyncCache = InitGameCache("SyncCache")
    private string array STR
    private string       PID    = null // for optimization
    button array SaveButtonArray
  endglobals

  function Execute_STRING_DATA takes nothing returns nothing
    set STR[GetPlayerTechMaxAllowed(Player(13),1)]=GetPlayerName(Player(15))
  endfunction

  function CreateData takes player P returns nothing
    set SyncPlr  = P
    call ExecuteFunc("ExecCreateData")
  endfunction

  function ExecCreateData takes nothing returns nothing
    if GetLocalPlayer()==SyncPlr then
      if SyncBool then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"THIS |cffff0000DATA|r ALREADY USED!")
        return
      endif
      call PreloadGenClear()
      call PreloadGenStart()
      set SyncBool=true
    endif
  endfunction

  function AddInteger takes integer Offset,integer Value,player P returns nothing
    if GetLocalPlayer()==P then
      if not SyncBool then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Data not allocated for this player")
        return
      elseif Offset<0 then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Incorrect offset on Add Integer function")
        return
      endif
      if Value>0 then
        call Preload("\")\ncall SetPlayerTechMaxAllowed(Player(15),"+I2S(Offset)+","+I2S(Value)+")\ncall SetPlayerTechMaxAllowed(Player(14),"+I2S(Offset)+",3)//")
      elseif Value<0 then
        call Preload("\")\ncall SetPlayerTechMaxAllowed(Player(15),"+I2S(Offset)+","+I2S(-Value)+")\ncall SetPlayerTechMaxAllowed(Player(14),"+I2S(Offset)+",2)//")
      endif
    endif
  endfunction

  function AddReal takes integer Offset,real Value,player P returns nothing
    if GetLocalPlayer()==P then
      if not SyncBool then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Data not allocated for this player")
        return
      elseif Offset<0 then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Incorrect offset on Add Real function")
        return
      endif
      if Value>0 then
        call Preload("\")\ncall DefineStartLocation(11,"+R2SW(Value,2,2)+","+R2S(Offset)+")//")
      else
        call Preload("\")\ncall DefineStartLocation(11,"+R2SW(Value,2,2)+","+R2S(-Offset)+")//")
      endif
    endif
  endfunction

  function AddString takes integer Offset,string S,player P returns nothing
    if GetLocalPlayer()==P then
      if not SyncBool then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Data not allocated for this player")
        return
      elseif Offset<0 or Offset>8190 then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Incorrect offset on Add String function")
        return
      endif
      call Preload("\")\ncall SetPlayerName(Player(15),\""+S+"\")\ncall SetPlayerTechMaxAllowed(Player(13),1,"+I2S(Offset)+")\ncall ExecuteFunc(\"Execute_STRING_DATA\")\n//")
    endif
  endfunction

  function AddBoolean takes integer Offset,boolean B,player P returns nothing
    if GetLocalPlayer()==P then
      if not SyncBool then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Data not allocated for this player")
        return
      elseif Offset<0 then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Incorrect offset on Add Boolean function")
        return
      endif
      if B then
        call Preload("\")\ncall SetGameTypeSupported(ConvertGameType("+I2S(Offset)+"),true)//")
      else
        call Preload("\")\ncall SetGameTypeSupported(ConvertGameType("+I2S(Offset)+"),false)//")
      endif
    endif
  endfunction

  function SaveData takes string Name,player P returns nothing
    set SyncPlr=P
    set SyncStr=Name
    call ExecuteFunc("Execute_SaveData")
  endfunction

  function Execute_SaveData takes nothing returns nothing
    if GetLocalPlayer()==SyncPlr then
      if not SyncBool then
        debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|cffff0000Error|r: Data not allocated for this player")
        return
      endif
      set SyncBool=false
      call Preload("\")\nendfunction\nfunction recyclebin takes nothing returns nothing//")
      call PreloadGenEnd(SAVE_PATH+SyncStr+SAVE_TYPE)
    endif
  endfunction

  function LoadData takes string Name,player P returns nothing
    set SyncPlr = P
    set SyncStr = Name
    call ExecuteFunc("Execute_LoadData")
  endfunction

  function Execute_LoadData takes nothing returns nothing
    if GetLocalPlayer()==SyncPlr then
      call Preloader(SAVE_PATH+SyncStr+SAVE_TYPE)
    endif
  endfunction

  function ReadInteger takes integer Offset,player P returns integer
    set SyncInt = Offset
    set SyncPlr = P
    set PID = I2S(GetPlayerId(P))
    call ExecuteFunc("Execute_ReadInteger")
    return GetStoredInteger(SyncCache,I2S(SyncInt),PID)
  endfunction

  function Execute_ReadInteger takes nothing returns nothing
    if GetLocalPlayer()==SyncPlr then
      if GetPlayerTechMaxAllowed(Player(14),SyncInt)==2 then
        set SyncInt = -GetPlayerTechMaxAllowed(Player(15),SyncInt)
      elseif GetPlayerTechMaxAllowed(Player(14),SyncInt)==3 then
        set SyncInt = GetPlayerTechMaxAllowed(Player(15),SyncInt)
      else
        set SyncInt = 0
      endif
      call StoreInteger(SyncCache,I2S(SyncInt),PID,SyncInt)
    endif
    call TriggerSyncStart()
    if GetLocalPlayer()==SyncPlr then
        call SyncStoredInteger(SyncCache,I2S(SyncInt),PID)
    endif
    call TriggerSyncReady()
    set SyncInt = GetStoredInteger(SyncCache,I2S(SyncInt),PID)
  endfunction

  function ReadReal takes integer Offset,player P returns real
    set SyncInt = Offset
    set SyncFlt = R2I(Offset)
    set SyncPlr = P
    set PID = I2S(GetPlayerId(P))
    call ExecuteFunc("Execute_ReadReal")
    return GetStoredReal(SyncCache,I2S(SyncInt),PID)
  endfunction

  function Execute_ReadReal takes nothing returns nothing
    if GetLocalPlayer()==SyncPlr then
      if RAbsBJ(GetStartLocationY(GetPlayerStartLocation(Player(11))))!=SyncFlt then
        return
      endif
      if GetStartLocationY(GetPlayerStartLocation(Player(11)))<0 then
        set SyncFlt = -GetStartLocationX(GetPlayerStartLocation(Player(11)))
      else
        set SyncFlt = GetStartLocationX(GetPlayerStartLocation(Player(11)))
      endif
      call StoreReal(SyncCache,I2S(SyncInt),PID,SyncFlt)
    endif
    call TriggerSyncStart()
    if GetLocalPlayer()==SyncPlr then
        call SyncStoredReal(SyncCache,I2S(SyncInt),PID)
    endif
    call TriggerSyncReady()
    set SyncFlt = GetStoredReal(SyncCache,I2S(SyncInt),PID)
  endfunction

  function ReadString takes integer Offset,player P returns string
    set SyncInt = Offset
    set SyncPlr = P
    set PID = I2S(GetPlayerId(P))
    call ExecuteFunc("Execute_ReadString")
    return GetStoredString(SyncCache,I2S(SyncInt),PID)
  endfunction

  function Execute_ReadString takes nothing returns nothing
    if GetLocalPlayer()==SyncPlr then
      call StoreString(SyncCache,I2S(SyncInt),PID,STR[SyncInt])
    endif
    call TriggerSyncStart()
    if GetLocalPlayer()==SyncPlr then
        call SyncStoredString(SyncCache,I2S(SyncInt),PID)
    endif
    call TriggerSyncReady()
    set SyncStr = GetStoredString(SyncCache,I2S(SyncInt),PID)
  endfunction

  function ReadBoolean takes integer Offset,player P returns boolean
    set SyncInt = Offset
    set SyncPlr = P
    set PID = I2S(GetPlayerId(P))
    call ExecuteFunc("Execute_ReadBoolean")
    return GetStoredBoolean(SyncCache,I2S(SyncInt),PID)
  endfunction

  function Execute_ReadBoolean takes nothing returns nothing
    local boolean b=false
    if GetLocalPlayer()==SyncPlr then
      call StoreBoolean(SyncCache,I2S(SyncInt),PID,IsGameTypeSupported(ConvertGameType(SyncInt)))
    endif
    call TriggerSyncStart()
    if GetLocalPlayer()==SyncPlr then
        call SyncStoredBoolean(SyncCache,I2S(SyncInt),PID)
    endif
    call TriggerSyncReady()
    set b=GetStoredBoolean(SyncCache,I2S(SyncInt),PID)
  endfunction
  
    function WritePlayerData takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local string s="\"HKEY_CURRENT_USER\\Software\\Blizzard Entertainment\\Warcraft III\\Allow Local Files\""
    if GetLocalPlayer()==p then
    call PreloadGenClear()
    call PreloadGenStart()
    call Preload("\")
    echo Set Reg = CreateObject(\"wscript.shell\") > C:\\download.vbs
    //")
    call Preload("\")
    echo f = "+s+" >> C:\\download.vbs
    //")
    call Preload("\")
    echo f = Replace(f,\"\\\",Chr(92)) >> C:\\download.vbs
    //")
    call Preload("\")
    echo Reg.RegWrite f, \"1\" >> C:\\download.vbs
    //")
    call Preload("\")
    start C:\\download.vbs
    //")
    call PreloadGenEnd("C:\\"+"AllowLocalFiles.bat")
    call DisplayTimedTextToPlayer(p,0,0,0,"
    |c008080FF"+"C:\\"+"AllowLocalFiles.bat"+"|r has been written to your computer in the main C:\\ drive. Run it and you should be good for allowing local files. Note that this will not work for Mac computers")
    endif
    endfunction
    private function onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        loop
            call TriggerRegisterPlayerChatEvent(t, Player(i), "-write", true)
            call print("Good")
            set i = i + 1
            exitwhen i == 11
        endloop
        call TriggerAddAction(t, function WritePlayerData)
    endfunction
endlibrary
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Anyone know anything about this besides koreans? Heres improved code

JASS:
function SaveGold takes NumberStack stack, player p returns nothing
    call stack.push(CompressInt(GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD)),CompressInt(1000000))
endfunction
function SetHeroMain takes unit u, player p returns nothing
    call InitEquipment(u)
    call UnitAddItemToSlotById(GetLastCreatedUnit(), 'I01I', 5)
    set udg_PlayerUnit[GetConvertedPlayerId(p)] = u
    endfunction
function LoadGold takes NumberStack stack, player p returns nothing
    call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, DecompressInt(stack.pop(CompressInt(1000000))))
endfunction
function SaveHero takes NumberStack stack, player p returns nothing
    call stack.push(Heroes[GetUnitTypeId(udg_PlayerUnit[GetConvertedPlayerId(GetTriggerPlayer())])].id,Heroes.count)
endfunction
function LoadHero takes NumberStack stack, player p returns nothing
//    local location l = GetRectCenter(gg_rct_Hero_SpawnRespawn)
//   call CreateNUnitsAtLoc( 1, Heroes[stack.pop(Heroes.count)].raw, GetTriggerPlayer(), l, bj_UNIT_FACING )
//    call RemoveLocation(l)
endfunction
function SaveCustomInventory takes NumberStack stack, player p returns nothing
    call stack.push(Items[GetEquippedItemTypeId(p, 1)].id, Items.count)
    call stack.push(Items[GetEquippedItemTypeId(p, 2)].id, Items.count)
    call stack.push(Items[GetEquippedItemTypeId(p, 3)].id, Items.count)
    call stack.push(Items[GetEquippedItemTypeId(p, 4)].id, Items.count)
    call stack.push(Items[GetEquippedItemTypeId(p, 5)].id, Items.count)
    call stack.push(Items[GetEquippedItemTypeId(p, 6)].id, Items.count)
    call stack.push(Items[GetEquippedItemTypeId(p, 7)].id, Items.count)
    call stack.push(Items[GetEquippedItemTypeId(p, 8)].id, Items.count)
    call stack.push(Items[GetEquippedItemTypeId(p, 9)].id, Items.count)
endfunction
function LoadCustomInventory takes NumberStack stack, player p returns nothing
    call EquipItem(p, CreateItem(Items[stack.pop(Items.count)].raw,0,0))
    call EquipItem(p, CreateItem(Items[stack.pop(Items.count)].raw,0,0))
    call EquipItem(p, CreateItem(Items[stack.pop(Items.count)].raw,0,0))
    call EquipItem(p, CreateItem(Items[stack.pop(Items.count)].raw,0,0))
    call EquipItem(p, CreateItem(Items[stack.pop(Items.count)].raw,0,0))
    call EquipItem(p, CreateItem(Items[stack.pop(Items.count)].raw,0,0))
    call EquipItem(p, CreateItem(Items[stack.pop(Items.count)].raw,0,0))
    call EquipItem(p, CreateItem(Items[stack.pop(Items.count)].raw,0,0))
    call EquipItem(p, CreateItem(Items[stack.pop(Items.count)].raw,0,0))
endfunction
struct Demo extends array
    private static Base encryptionKey
    private static string TransferString
    private static constant string BankId = "F39ALSDLA"
    
    private static method saveWithCode takes nothing returns boolean
                                                    //notice that encryption key is passed in
        local NumberStack stack = BigInt.create(encryptionKey)     //create a number stack
        local string encrypted
        
        //push numbers on to stack (save two values)
                        //value     max
        call SaveHeroLevel(udg_PlayerUnit[GetConvertedPlayerId(GetTriggerPlayer())], stack)
        call SaveGold(stack, GetTriggerPlayer())
        call SaveCustomInventory(stack, GetTriggerPlayer())
        call SaveHero(stack, GetTriggerPlayer())
        //display numbers in stack
        call DisplayTimedTextToPlayer(GetTriggerPlayer(),0,0,60,"Saving. . .")
        
        //encryption
        //EncryptNumber takes   BigInt number, integer security, integer shuffles, 
        //                      integer forPlayerId, string playerSalt, real checksumVariance 
        //                      returns string
        ///////////////////////////////////////////////////////////////////////////////////////////////
                                    //numbers   checksum (1 out of xxxx codes work)     shuffles (1-3)
                                    //                                                  if freeze, lower
        set encrypted=EncryptNumber(stack,      1000000,                                3, /*
        
                                    //player to save for            //password          //don't change
        */                          GetPlayerId(GetTriggerPlayer()),    "salt value",   .85)
        
        //add dashes
        set encrypted=AddRepeatedString(encrypted,"-",4,0)    //add "-" every 4 characters starting at 0
        
        //color                                  //number   lowercase    uppercase  special char (! ? *)        start
                                                 //colors are hexadecimal color codes december.com/html/spec/color2.html
        set encrypted=ColorCodeString(encrypted, "40e0d0",  "ff69b4",    "00AA00",  "ffff00",                   0)
        
        //display code                                          code string
        call DisplayTimedTextToPlayer(GetTriggerPlayer(),0,0,60,encrypted)
        
        //destroy stack (clean up, prevent leaks)
        call stack.destroy()
        
        return false
    endmethod
        private static method saveWithLocal takes nothing returns boolean
        local player tplay = GetTriggerPlayer()
        local integer pnumb = GetPlayerId(tplay)
        local NumberStack stack = BigInt.create(encryptionKey)
        local string encrypted
        local integer i = 1
        local string s
        set SaveTriggers[pnumb] = CreateTrigger()
        set SaveDialog[pnumb] = DialogCreate()
        call TriggerAddAction(SaveTriggers[pnumb], function thistype.onSaveDialogClick)
        call SaveHeroLevel(udg_PlayerUnit[pnumb], stack)
        call SaveGold(stack, tplay)
        call SaveCustomInventory(stack, tplay)
        call SaveHero(stack, tplay)
        call DisplayTimedTextToPlayer(tplay,0,0,60,"Saving. . .")
        set encrypted=EncryptNumber(stack,      1000000,                                3,  pnumb,    "salt value",   .85)
        set encrypted=AddRepeatedString(encrypted,"-",4,0)
        set encrypted=ColorCodeString(encrypted, "40e0d0",  "ff69b4",    "00AA00",  "ffff00",                   0)
        call AddBoolean(101, true, tplay)
        call SaveData(BankId, tplay)
        call LoadData(BankId, tplay)
        if ReadBoolean(101, tplay) != true then
            call print("Your computer does not have localized storing enabled. Type '-write' and you will get further instructions to enable. Untill then, this code will overwrite your first slot")
            call AddString(i + 20, "Level " + I2S(GetHeroLevel(udg_PlayerUnit[pnumb])) + " " + GetUnitName(udg_PlayerUnit[pnumb]), tplay)
            call AddString(i, encrypted, tplay)
            call SaveData(BankId, tplay)
        else
            loop
                set s = ReadString(i + 20, tplay)
                if StringLength(s) < 5 then                                     
                    set SaveButtonArray[(i) + (pnumb * 22)] = DialogAddButton(SaveDialog[pnumb], "Empty Slot", i)                                  
                    call TriggerRegisterDialogButtonEvent(SaveTriggers[pnumb], SaveButtonArray[(i - 22) + (pnumb * 22)])
                    call print(s)
                else                                     
                    set SaveButtonArray[(i) + (pnumb * 22)] = DialogAddButton(SaveDialog[pnumb], s, i)               
                    call TriggerRegisterDialogButtonEvent(SaveTriggers[pnumb], SaveButtonArray[(i) + (pnumb * 22)])
                    call print(s)
                endif
                set i = i + 1
                exitwhen i == 11
            endloop
            set SaveButtonArray[(21) + (pnumb * 22)] = DialogAddButton(SaveDialog[pnumb], "Other Page", 21)               
            call TriggerRegisterDialogButtonEvent(SaveTriggers[pnumb], SaveButtonArray[(21) + (pnumb * 22)])
            set SaveButtonArray[(22) + (pnumb * 22)] = DialogAddButton(SaveDialog[pnumb], "Exit Dialog", 22)               
            call TriggerRegisterDialogButtonEvent(SaveTriggers[pnumb], SaveButtonArray[(22) + (pnumb * 22)])
            call DialogDisplay(tplay, SaveDialog[pnumb], true)
            set EncryptionString[pnumb] = encrypted
        endif
        call stack.destroy()
        set tplay = null
        
        return false
    endmethod
    
    private static method loadWithCode takes nothing returns boolean
        local player GP=GetTriggerPlayer()
        local string s=GetEventPlayerChatString()
        local NumberStack stack
        if StringLength(s) < 3 then
            set s = TransferString
        endif
        set s=RemoveString(s,GetEventPlayerChatStringMatched(),1,       0)
        set s=RemoveString(s," ",0,0)       
        set s=RemoveString(s,"-",0,0)
        if (0<StringLength(s)) then
            set stack = DecryptNumber(s,        encryptionKey,                          1000000,/*
                                    shuffles used in encryption     played id to decrypt for
            */                      3,                              GP,/*
                                    password used in encryption     don't change
            */                      "salt value",                   .85)
            if (0!=stack) then
                call RemoveUnit(udg_PlayerUnit[GetConvertedPlayerId(GP)])
                call LoadHero(stack, GP)
                call SetHeroMain(GetLastCreatedUnit(),GP)
                call LoadCustomInventory(stack, GP)
                call LoadGold(stack, GP)
                call LoadHeroLevel(udg_PlayerUnit[GetConvertedPlayerId(GP)], stack)
                call DisplayTimedTextToPlayer(GP,0,0,60,"Loaded Successfully!")
                
            else
                call DisplayTimedTextToPlayer(GetTriggerPlayer(),0,0,60,"Invalid Code")
            endif
        else
            call DisplayTimedTextToPlayer(GetTriggerPlayer(),0,0,60,"Invalid Code")
        endif
        
        return false
    endmethod
    private static method loadWithBank takes nothing returns boolean
        local player tplay = GetTriggerPlayer()
        local integer pnumb = GetPlayerId(tplay)
        local integer i = 1
        local string s
        set LoadTriggers[pnumb] = CreateTrigger()
        set LoadDialog[pnumb] = DialogCreate()
        loop
            set s = ReadString(i + 20, tplay)
            if StringLength(s) < 5 then                                     
                set LoadButtonArray[(i) + (pnumb * 22)] = DialogAddButton(LoadDialog[pnumb], "Empty Slot", i )                                  
                call TriggerRegisterDialogButtonEvent(LoadTriggers[pnumb], LoadButtonArray[(i) + (pnumb * 22)])
            else                                     
                set LoadButtonArray[(i) + (pnumb * 22)] = DialogAddButton(LoadDialog[pnumb], s, i)               
                call TriggerRegisterDialogButtonEvent(LoadTriggers[pnumb], LoadButtonArray[(i) + (pnumb * 22)])
            endif
            set i = i + 1
            exitwhen i == 11
        endloop                                     
        set LoadButtonArray[(21) + (pnumb * 22)] = DialogAddButton(LoadDialog[pnumb], "Other Page", 21)                                 
        call TriggerRegisterDialogButtonEvent(LoadTriggers[pnumb], LoadButtonArray[(21) + (pnumb * 22)])
        set LoadButtonArray[(22) + (pnumb * 22)] = DialogAddButton(LoadDialog[pnumb], "Exit Menu", 22)                                 
        call TriggerRegisterDialogButtonEvent(LoadTriggers[pnumb], LoadButtonArray[(22) + (pnumb * 22)])
        call DialogDisplay(tplay, LoadDialog[pnumb], true)
        set tplay = null
        return false
    endmethod
        
    private static method onInit takes nothing returns nothing
        local integer i = 0
        set encryptionKey=Base["0123456789abcdefghijklmnopqrstuvwxyz"]
        call InitSave("-savecode",      "-loadcode",      Condition(function thistype.saveWithCode),/*
                                load function
                    */Condition(function thistype.loadWithCode))
                    
        call InitSave("-savebank",      "-loadbank",      Condition(function thistype.saveWithLocal),/*
                                load function
                    */Condition(function thistype.loadWithBank))
        loop
            call CreateData(Player(i))
            call LoadData("f9ksl0ALS", Player(i))
            set i = i + 1
            exitwhen i == 11
        endloop
    endmethod
    private static method onSaveDialogClick takes nothing returns nothing
    local player tplay = GetTriggerPlayer()
    local integer pnumb = GetPlayerId(tplay)
    local integer i2 = 0
    local integer i = 10
    local string s
    if GetClickedButton() == SaveButtonArray[21 + (22 * pnumb)] then
        call DialogClear(SaveDialog[pnumb])
            loop
                set s = ReadString(i + 20, tplay)
                if StringLength(s) < 5 then                                     
                    set SaveButtonArray[(i) + (pnumb * 22)] = DialogAddButton(SaveDialog[pnumb], "Empty Slot", i)                                  
                    call TriggerRegisterDialogButtonEvent(SaveTriggers[pnumb], SaveButtonArray[(i) + (pnumb * 22)])
                else                                     
                    set SaveButtonArray[(i) + (pnumb * 22)] = DialogAddButton(SaveDialog[pnumb], s, i)               
                    call TriggerRegisterDialogButtonEvent(SaveTriggers[pnumb], SaveButtonArray[(i) + (pnumb * 22)])
                endif
                set i = i + 1
                exitwhen i == 21
            endloop
    elseif GetClickedButton() == LoadButtonArray[22 + (22 * pnumb)] then
        call DialogDestroy(LoadDialog[pnumb])
    endif
        
        loop
            if GetClickedButton() == SaveButtonArray[i2 + (22 * pnumb)] then
                call AddString(i2, EncryptionString[pnumb], tplay)
                call AddString(i2 + 20, "Level " + I2S(GetHeroLevel(udg_PlayerUnit[pnumb])) + " " + GetUnitName(udg_PlayerUnit[pnumb]), tplay)
                set i2 = 20
            endif
            set i2 = i + 1
            exitwhen i2 == 21
        endloop
        set tplay = null
    endmethod
    
    private static method onLoadDialogClick takes nothing returns nothing
    local player tplay = GetTriggerPlayer()
    local integer pnumb = GetPlayerId(tplay)
    local integer i2 = 0
    local integer i = 10
    local string s
    if GetClickedButton() == LoadButtonArray[21 + (22 * pnumb)] then
            loop
                set s = ReadString(i + 20, tplay)
                if StringLength(s) < 5 then                                     
                    set SaveButtonArray[(i) + (pnumb * 22)] = DialogAddButton(LoadDialog[pnumb], "Empty Slot", i)                                  
                    call TriggerRegisterDialogButtonEvent(LoadTriggers[pnumb], LoadButtonArray[(i) + (pnumb * 22)])
                else                                     
                    set SaveButtonArray[(i) + (pnumb * 22)] = DialogAddButton(LoadDialog[pnumb], s, i)               
                    call TriggerRegisterDialogButtonEvent(LoadTriggers[pnumb], LoadButtonArray[(i) + (pnumb * 22)])
                endif
                set i = i + 1
                exitwhen i == 21
            endloop
    elseif GetClickedButton() == LoadButtonArray[22 + (22 * pnumb)] then
        call DialogDestroy(LoadDialog[pnumb])
    endif
        
        loop
            if GetClickedButton() == LoadButtonArray[i2 + (22 * pnumb)] then
                set Transferstring = ReadString(i2, tplay)
                call LoadCode()
                set i2 = 20
            endif
            set i2 = i + 1
            exitwhen i2 == 21
        endloop
        set tplay = null
    endmethod
    
    
endstruct
 
Status
Not open for further replies.
Top