Save/Load - Saving Integers

General talk about editing, cheating, and deprotecting maps.

Moderator: Cheaters

User avatar
Crazy-Host
Newcomer
Posts: 17
Joined: February 12th, 2011, 8:02 pm
Title: Just Another Newbie
Location: Behind You

Save/Load - Saving Integers

Post by Crazy-Host »

Hi, Im trying to create a save/load system similiar to Dawn Of The Dead's code system.
Dawn of the Dead uses experience ( not hero bar experience ) that is shown on a multiboard.
As you kill more zombies or complete a mission, you obtain more experience.
Could anyone help me with how to create a save/load system that saves the experience integer?
You do not have the required permissions to view my awesome signature.
User avatar
Nuuby
Forum Staff
Posts: 519
Joined: October 18th, 2010, 8:43 am

Re: Save/Load - Saving Integers

Post by Nuuby »

Use AceHart's
Did it before using some minor edits to the jass. Not too sure about GUI though.
And AFAIK, DotD uses this.
User avatar
Crazy-Host
Newcomer
Posts: 17
Joined: February 12th, 2011, 8:02 pm
Title: Just Another Newbie
Location: Behind You

Re: Save/Load - Saving Integers

Post by Crazy-Host »

Could you help me edit it like DotD? Im not really good with JASS.
I for some reason destroy the map if I edit with jass :O
You do not have the required permissions to view my awesome signature.
owner123
Super Moderator
Posts: 1943
Joined: February 3rd, 2009, 11:28 pm
Been thanked: 1 time

Re: Save/Load - Saving Integers

Post by owner123 »

If you post your map here I'll do it for you.
And tell me what the experience integer is.
Lifee00
Newcomer
Posts: 13
Joined: May 10th, 2010, 2:16 pm

Re: Save/Load - Saving Integers

Post by Lifee00 »

http://www.thehelper.net/forums/showthr ... t+Saveload go there,download the demo map,copy the jass from the map name in trigger editor into your map and then copy the save/load triggers,set the heros you want the system to save and you are ready,also be sure Automatically creating unknown variables while pasting trigger data from Preferences is on.This save/load system will save the Heros EXACTLY experience not the level,also gold and items and hero position(and u may edit it to make save more stuffs.This is want you want isn't it ? Simple huh.Hi there owner,and i don't think u need to do anything.
User avatar
Crazy-Host
Newcomer
Posts: 17
Joined: February 12th, 2011, 8:02 pm
Title: Just Another Newbie
Location: Behind You

Re: Save/Load - Saving Integers

Post by Crazy-Host »

I dont mean by HERO experience. I mean by something similiar to DotD, using experience as a seperate integer.
I'll PM u the map in a bit owner123.
Edit by owner-
Could you input the save/load into this map? This map is a rank system
I got off from hiveworkshop, I just need a save/load. Then im going to
copy it over to my map.
You do not have the required permissions to view the files attached to this post.
You do not have the required permissions to view my awesome signature.
owner123
Super Moderator
Posts: 1943
Joined: February 3rd, 2009, 11:28 pm
Been thanked: 1 time

Re: Save/Load - Saving Integers

Post by owner123 »

That system gives me errors.
Oh and dont double post. Use the edit button. I merged those.
...Btw are you the Crazy-Host from that werewolf clan (VoF or something) ;p?
User avatar
Crazy-Host
Newcomer
Posts: 17
Joined: February 12th, 2011, 8:02 pm
Title: Just Another Newbie
Location: Behind You

Re: Save/Load - Saving Integers

Post by Crazy-Host »

Errors? How?! Well, I'll try to find another way for a using a save/load like that.

and... yes, I am the mega ultra lord Crazy-Host.
You do not have the required permissions to view my awesome signature.
User avatar
Nuuby
Forum Staff
Posts: 519
Joined: October 18th, 2010, 8:43 am

Re: Save/Load - Saving Integers

Post by Nuuby »

I had a save/load integer system in jass *3 parts CP style lol*
It's probably gone somewhere, I guess I could try and do another.
All you would have to do is replace an integer~

EDIT:
Spoiler for globals:
string udg_SaveLoad_Alphabet
integer array udg_Save
integer udg_SaveCount=0
string udg_Code
boolean udg_Validate=false
boolean udg_SaveLoad_CaseSensitive=false
integer udg_TempUnitType=0
integer udg_TempItemType=0
integer array udg_SaveLoad_Heroes
integer array udg_SaveLoad_Items
integer udg_SaveLoad_Heroes_LastIndex=0
integer udg_SaveLoad_Items_LastIndex=0
boolean udg_SaveLoad_Initialized=false
integer array udg_SaveLoad_Compress
integer array udg_SaveLoad_Uncompress
group udg_UnitGroup=null
boolean udg_SaveLoad_UsePlayername=false
item udg_TempItem=null
unit udg_TempUnit=null
integer array udg_SaveLoad_Abilities
integer udg_SaveLoad_Abilities_LastIndex=0
integer udg_TempInteger=0
integer array udg_ExpInteger
trigger gg_trg_SaveLoad_Initialization=null
trigger gg_trg_SaveLoad_Save=null
trigger gg_trg_SaveLoad_Load=null
Spoiler for functions:
function InitGlobals takes nothing returns nothing
local integer i=0
set udg_SaveLoad_Alphabet=""
set i=0
loop
exitwhen(i>1)
set udg_Save=0
set i=i+1
endloop
set udg_SaveCount=0
set udg_Code=""
set udg_Validate=false
set udg_SaveLoad_CaseSensitive=false
set udg_SaveLoad_Heroes_LastIndex=0
set udg_SaveLoad_Items_LastIndex=0
set udg_SaveLoad_Initialized=false
set i=0
loop
exitwhen(i>1)
set udg_SaveLoad_Compress=0
set i=i+1
endloop
set i=0
loop
exitwhen(i>1)
set udg_SaveLoad_Uncompress=0
set i=i+1
endloop
set udg_UnitGroup=CreateGroup()
set udg_SaveLoad_UsePlayername=false
set udg_SaveLoad_Abilities_LastIndex=0
set udg_TempInteger=0
set i=0
loop
exitwhen(i>12)
set udg_ExpInteger=0
set i=i+1
endloop
endfunction
function SaveLoad_InitialSetup takes nothing returns nothing
local integer i=0
local integer j=0
loop
set udg_SaveLoad_Compress[i+48]=j
set udg_SaveLoad_Uncompress=i+48
set j=j+1
set i=i+1
exitwhen i>=10
endloop
set i=0
loop
set udg_SaveLoad_Compress[i+97]=j
set udg_SaveLoad_Compress[i+65]=j+26
set udg_SaveLoad_Uncompress[i+10]=i+97
set udg_SaveLoad_Uncompress[i+26+10]=i+65
set j=j+1
set i=i+1
exitwhen i>=26
endloop
endfunction
function SaveLoad_Id2CId takes integer n returns integer
local integer i=n/(256*256*256)
local integer r
set n=n-i*(256*256*256)
set r=udg_SaveLoad_Compress
set i=n/(256*256)
set n=n-i*(256*256)
set r=r*64+udg_SaveLoad_Compress
set i=n/ 256
set r=r*64+udg_SaveLoad_Compress
return r*64+udg_SaveLoad_Compress[n-i*256]
endfunction
function SaveLoad_CId2Id takes integer n returns integer
local integer i=n/(64*64*64)
local integer r
set n=n-i*(64*64*64)
set r=udg_SaveLoad_Uncompress
set i=n/(64*64)
set n=n-i*(64*64)
set r=r*256+udg_SaveLoad_Uncompress
set i=n/ 64
set r=r*256+udg_SaveLoad_Uncompress[i]
return r*256+udg_SaveLoad_Uncompress[n-i*64]
endfunction
function SaveLoad_Unit2Integer takes unit u returns integer
local integer i=0
local integer n=GetUnitTypeId(u)
if udg_SaveLoad_Initialized==false then
set udg_SaveLoad_Initialized=true
call SaveLoad_InitialSetup()
endif
loop
set i=i+1
exitwhen i>udg_SaveLoad_Heroes_LastIndex
if udg_SaveLoad_Heroes[i]==n then
return i
endif
endloop
return SaveLoad_Id2CId(n)
endfunction
function SaveLoad_Integer2Unit takes integer i returns integer
if udg_SaveLoad_Initialized==false then
set udg_SaveLoad_Initialized=true
call SaveLoad_InitialSetup()
endif
if i<=udg_SaveLoad_Heroes_LastIndex then
return udg_SaveLoad_Heroes[i]
endif
return SaveLoad_CId2Id(i)
endfunction
function SaveLoad_Item2Integer takes item t returns integer
local integer i=0
local integer n=GetItemTypeId(t)
if udg_SaveLoad_Initialized==false then
set udg_SaveLoad_Initialized=true
call SaveLoad_InitialSetup()
endif
loop
set i=i+1
exitwhen i>udg_SaveLoad_Items_LastIndex
if udg_SaveLoad_Items[i]==n then
return i
endif
endloop
return SaveLoad_Id2CId(n)
endfunction
function SaveLoad_Integer2Item takes integer i returns integer
if udg_SaveLoad_Initialized==false then
set udg_SaveLoad_Initialized=true
call SaveLoad_InitialSetup()
endif
if i<=udg_SaveLoad_Items_LastIndex then
return udg_SaveLoad_Items[i]
endif
return SaveLoad_CId2Id(i)
endfunction
function SaveLoad_Ability2Integer takes integer a returns integer
local integer i=0
if udg_SaveLoad_Initialized==false then
set udg_SaveLoad_Initialized=true
call SaveLoad_InitialSetup()
endif
loop
set i=i+1
exitwhen i>udg_SaveLoad_Abilities_LastIndex
if udg_SaveLoad_Abilities[i]==a then
return i
endif
endloop
return SaveLoad_Id2CId(a)
endfunction
function SaveLoad_Integer2Ability takes integer i returns integer
if udg_SaveLoad_Initialized==false then
set udg_SaveLoad_Initialized=true
call SaveLoad_InitialSetup()
endif
if i<=udg_SaveLoad_Abilities_LastIndex then
return udg_SaveLoad_Abilities[i]
endif
return SaveLoad_CId2Id(i)
endfunction
function SaveLoad_Color takes string s returns string
local integer i=StringLength(s)
local string c
local string r=""
loop
set i=i-1
set c=SubString(s,i,i+1)
if c=="0" or c=="1" or c=="2" or c=="3" or c=="4" or c=="5" or c=="6" or c=="7" or c=="8" or c=="9" then
set r="|cffffcc00"+c+"|r"+r
elseif c=="-" then
set r="|cffdddddd-|r"+r
else
set r=c+r
endif
exitwhen i<=0
endloop
return r
endfunction
function SaveLoad_EncodeChar takes string n returns integer
local integer i=0
local string s1="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
local string s2="abcdefghijklmnopqrstuvwxyz"
local string s3="0123456789"
loop
if SubString(s1,i,i+1)==n then
return i
endif
if SubString(s2,i,i+1)==n then
return i
endif
set i=i+1
exitwhen i>=26
endloop
set i=0
loop
if SubString(s3,i,i+1)==n then
return i
endif
set i=i+1
exitwhen i>=10
endloop
return 0
endfunction
function SaveLoad_EncodeVerify takes string buffer returns integer
local integer i=0
local integer j=0
local string name=GetPlayerName(GetTriggerPlayer())
if udg_SaveLoad_UsePlayername==true then
loop
set j=j+SaveLoad_EncodeChar(SubString(name,i,i+1))
set i=i+1
exitwhen i>=StringLength(name)
endloop
endif
set i=0
loop
set j=j+SaveLoad_EncodeChar(SubString(buffer,i,i+1))
set i=i+1
exitwhen i>=StringLength(buffer)
endloop
return j
endfunction
function SaveLoad_EncodeValues takes nothing returns string
local integer i
local integer j
local integer k
local integer l
local integer m
local integer CodeLength=StringLength(udg_SaveLoad_Alphabet)
local integer array a
local string buffer=""
local string c=""
local integer skip=0
local integer CONST=1000000
local string abc="0123456789"
set i=0
loop
set i=i+1
exitwhen i>udg_SaveCount
set buffer=buffer+I2S(udg_Save[i])+"-"
endloop
set buffer=buffer+I2S(SaveLoad_EncodeVerify(buffer))
if udg_Save[1]==0 then
set buffer="-"+buffer
endif
set i=0
loop
set a[i]=0
set i=i+1
exitwhen i>=100
endloop
set m=0
set i=0
loop
set j=0
loop
set a[j]=a[j]*11
set j=j+1
exitwhen j>m
endloop
set l=0
set c=SubString(buffer,i,i+1)
loop
exitwhen SubString(abc,l,l+1)==c
set l=l+1
exitwhen l>9
endloop
set a[0]=a[0]+l
set j=0
loop
set k=a[j]/ CONST
set a[j]=a[j]-k*CONST
set a[j+1]=a[j+1]+k
set j=j+1
exitwhen j>m
endloop
if k>0 then
set m=m+1
endif
set i=i+1
exitwhen i>=StringLength(buffer)
endloop
set buffer=""
loop
exitwhen m<0
set j=m
loop
exitwhen j<=0
set k=a[j]/ CodeLength
set a[j-1]=a[j-1]+(a[j]-k*CodeLength)*CONST
set a[j]=k
set j=j-1
endloop
set k=a[j]/ CodeLength
set i=a[j]-k*CodeLength
set buffer=buffer+SubString(udg_SaveLoad_Alphabet,i,i+1)
set a[j]=k
if a[m]==0 then
set m=m-1
endif
endloop
set i=StringLength(buffer)
set skip=0
set c=""
loop
set i=i-1
set c=c+SubString(buffer,i,i+1)
set skip=skip+1
if skip==4 and i>0 then
set c=c+"-"
set skip=0
endif
exitwhen i<=0
endloop
return c
endfunction
function SaveLoad_DecodeValues takes string s returns boolean
local integer i
local integer j
local integer k
local integer l
local integer SaveCode=0
local integer m
local integer array a
local string buffer=""
local integer CodeLength=StringLength(udg_SaveLoad_Alphabet)
local integer skip=-1
local integer CONST=1000000
local string abc="0123456789-"
local string c
set i=0
loop
set a[i]=0
set i=i+1
exitwhen i>=100
endloop
set m=0
set i=0
loop
set j=0
loop
set a[j]=a[j]*CodeLength
set j=j+1
exitwhen j>m
endloop
set skip=skip+1
if skip==4 then
set skip=0
set i=i+1
endif
set l=CodeLength
set c=SubString(s,i,i+1)
loop
set l=l-1
exitwhen l<1
exitwhen SubString(udg_SaveLoad_Alphabet,l,l+1)==c
endloop
set a[0]=a[0]+l
set j=0
loop
set k=a[j]/ CONST
set a[j]=a[j]-k*CONST
set a[j+1]=a[j+1]+k
set j=j+1
exitwhen j>m
endloop
if k>0 then
set m=m+1
endif
set i=i+1
exitwhen i>=StringLength(s)
endloop
loop
exitwhen m<0
set j=m
loop
exitwhen j<=0
set k=a[j]/ 11
set a[j-1]=a[j-1]+(a[j]-k*11)*CONST
set a[j]=k
set j=j-1
endloop
set k=a[j]/ 11
set i=a[j]-k*11
set buffer=SubString(abc,i,i+1)+buffer
set a[j]=k
if a[m]==0 then
set m=m-1
endif
endloop
set i=0
set j=0
loop
loop
exitwhen i>=StringLength(buffer)
exitwhen i>0 and SubString(buffer,i,i+1)=="-" and SubString(buffer,i-1,i)!="-"
set i=i+1
endloop
if i<StringLength(buffer)then
set k=i
endif
set SaveCode=SaveCode+1
set udg_Save[SaveCode]=S2I(SubString(buffer,j,i))
set j=i+1
set i=i+1
exitwhen i>=StringLength(buffer)
endloop
set j=SaveLoad_EncodeVerify(SubString(buffer,0,k))
set udg_SaveCount=SaveCode-1
if j==udg_Save[SaveCode]then
return true
endif
return false
endfunction
function SaveLoad_Encode takes nothing returns string
if udg_SaveLoad_CaseSensitive==false then
set udg_SaveLoad_Alphabet=StringCase(udg_SaveLoad_Alphabet,true)
endif
return SaveLoad_Color(SaveLoad_EncodeValues())
endfunction
function SaveLoad_Decode takes string s returns boolean
if udg_SaveLoad_CaseSensitive==false then
set udg_SaveLoad_Alphabet=StringCase(udg_SaveLoad_Alphabet,true)
set s=StringCase(s,true)
endif
if SaveLoad_DecodeValues(s)then
call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"Decoding sucessful")
return true
endif
call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"Decoding failed")
return false
endfunction
function Trig_SaveLoad_Initialization_Actions takes nothing returns nothing
set udg_SaveLoad_Alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
set udg_SaveLoad_CaseSensitive=false
set udg_SaveLoad_UsePlayername=true
set udg_SaveLoad_Initialized=false
set udg_Code=""
set udg_Save[1]=0
set udg_SaveCount=1
set udg_Validate=false
set udg_SaveLoad_Compress[1]=0
set udg_SaveLoad_Uncompress[1]=0
endfunction
function InitTrig_SaveLoad_Initialization takes nothing returns nothing
set gg_trg_SaveLoad_Initialization=CreateTrigger()
call TriggerAddAction(gg_trg_SaveLoad_Initialization,function Trig_SaveLoad_Initialization_Actions)
endfunction
function Trig_SaveLoad_Save_Actions takes nothing returns nothing
set udg_Save[1]=udg_ExpInteger[GetPlayerId(GetTriggerPlayer())]
set udg_SaveCount=1
set udg_Code=SaveLoad_Encode()
call QuestMessageBJ(GetForceOfPlayer(GetTriggerPlayer()),bj_QUESTMESSAGE_SECRET,"Your code is:")
call DisplayTimedTextToForce(GetForceOfPlayer(GetTriggerPlayer()),60.00,udg_Code)
endfunction
function InitTrig_SaveLoad_Save takes nothing returns nothing
set gg_trg_SaveLoad_Save=CreateTrigger()
call TriggerRegisterPlayerChatEvent(gg_trg_SaveLoad_Save,Player(0),"-save",true)
call TriggerRegisterPlayerChatEvent(gg_trg_SaveLoad_Save,Player(1),"-save",true)
call TriggerRegisterPlayerChatEvent(gg_trg_SaveLoad_Save,Player(2),"-save",true)
call TriggerRegisterPlayerChatEvent(gg_trg_SaveLoad_Save,Player(3),"-save",true)
call TriggerAddAction(gg_trg_SaveLoad_Save,function Trig_SaveLoad_Save_Actions)
endfunction
function Trig_SaveLoad_Load_Conditions takes nothing returns boolean
if(not(SubStringBJ(GetEventPlayerChatString(),1,6)==GetEventPlayerChatStringMatched()))then
return false
endif
if(not(StringLength(GetEventPlayerChatString())>6))then
return false
endif
return true
endfunction
function Trig_SaveLoad_Load_Func004C takes nothing returns boolean
if(not(udg_Validate==true))then
return false
endif
return true
endfunction
function Trig_SaveLoad_Load_Actions takes nothing returns nothing
set udg_Code=SubStringBJ(GetEventPlayerChatString(),7,StringLength(GetEventPlayerChatString()))
set udg_Validate=SaveLoad_Decode(udg_Code)
if(Trig_SaveLoad_Load_Func004C())then
set bj_forLoopAIndex=1
set bj_forLoopAIndexEnd=udg_SaveCount
loop
exitwhen bj_forLoopAIndex>bj_forLoopAIndexEnd
call DisplayTextToForce(GetForceOfPlayer(GetTriggerPlayer()),("Decode: "+I2S(udg_Save[GetForLoopIndexA()])))
set udg_ExpInteger[GetPlayerId(GetTriggerPlayer())]=udg_Save[GetForLoopIndexA()]
set bj_forLoopAIndex=bj_forLoopAIndex+1
endloop
else
call DisplayTextToForce(GetForceOfPlayer(GetTriggerPlayer()),"Invalid code")
endif
endfunction
function InitTrig_SaveLoad_Load takes nothing returns nothing
set gg_trg_SaveLoad_Load=CreateTrigger()
call TriggerRegisterPlayerChatEvent(gg_trg_SaveLoad_Load,Player(0),"-load ",false)
call TriggerRegisterPlayerChatEvent(gg_trg_SaveLoad_Load,Player(1),"-load ",false)
call TriggerRegisterPlayerChatEvent(gg_trg_SaveLoad_Load,Player(2),"-load ",false)
call TriggerRegisterPlayerChatEvent(gg_trg_SaveLoad_Load,Player(3),"-load ",false)
call TriggerAddCondition(gg_trg_SaveLoad_Load,Condition(function Trig_SaveLoad_Load_Conditions))
call TriggerAddAction(gg_trg_SaveLoad_Load,function Trig_SaveLoad_Load_Actions)
endfunction
function InitCustomTriggers takes nothing returns nothing
call InitTrig_SaveLoad_Initialization()
call InitTrig_SaveLoad_Save()
call InitTrig_SaveLoad_Load()
endfunction
function RunInitializationTriggers takes nothing returns nothing
call ConditionalTriggerExecute(gg_trg_SaveLoad_Initialization)
endfunction
Spoiler for initialization:
function InitGlobals takes nothing returns nothing
local integer i=0
set udg_SaveLoad_Alphabet=""
set i=0
loop
exitwhen(i>1)
set udg_Save[i]=0
set i=i+1
endloop
set udg_SaveCount=0
set udg_Code=""
set udg_Validate=false
set udg_SaveLoad_CaseSensitive=false
set udg_SaveLoad_Heroes_LastIndex=0
set udg_SaveLoad_Items_LastIndex=0
set udg_SaveLoad_Initialized=false
set i=0
loop
exitwhen(i>1)
set udg_SaveLoad_Compress[i]=0
set i=i+1
endloop
set i=0
loop
exitwhen(i>1)
set udg_SaveLoad_Uncompress[i]=0
set i=i+1
endloop
set udg_UnitGroup=CreateGroup()
set udg_SaveLoad_UsePlayername=false
set udg_SaveLoad_Abilities_LastIndex=0
set udg_TempInteger=0
set i=0
loop
exitwhen(i>12)
set udg_ExpInteger[i]=0
set i=i+1
endloop
endfunction
function SaveLoad_InitialSetup takes nothing returns nothing
local integer i=0
local integer j=0
loop
set udg_SaveLoad_Compress[i+48]=j
set udg_SaveLoad_Uncompress[i]=i+48
set j=j+1
set i=i+1
exitwhen i>=10
endloop
set i=0
loop
set udg_SaveLoad_Compress[i+97]=j
set udg_SaveLoad_Compress[i+65]=j+26
set udg_SaveLoad_Uncompress[i+10]=i+97
set udg_SaveLoad_Uncompress[i+26+10]=i+65
set j=j+1
set i=i+1
exitwhen i>=26
endloop
endfunction
function SaveLoad_Id2CId takes integer n returns integer
local integer i=n/(256*256*256)
local integer r
set n=n-i*(256*256*256)
set r=udg_SaveLoad_Compress[i]
set i=n/(256*256)
set n=n-i*(256*256)
set r=r*64+udg_SaveLoad_Compress[i]
set i=n/ 256
set r=r*64+udg_SaveLoad_Compress[i]
return r*64+udg_SaveLoad_Compress[n-i*256]
endfunction
function SaveLoad_CId2Id takes integer n returns integer
local integer i=n/(64*64*64)
local integer r
set n=n-i*(64*64*64)
set r=udg_SaveLoad_Uncompress[i]
set i=n/(64*64)
set n=n-i*(64*64)
set r=r*256+udg_SaveLoad_Uncompress[i]
set i=n/ 64
set r=r*256+udg_SaveLoad_Uncompress[i]
return r*256+udg_SaveLoad_Uncompress[n-i*64]
endfunction
function SaveLoad_Unit2Integer takes unit u returns integer
local integer i=0
local integer n=GetUnitTypeId(u)
if udg_SaveLoad_Initialized==false then
set udg_SaveLoad_Initialized=true
call SaveLoad_InitialSetup()
endif
loop
set i=i+1
exitwhen i>udg_SaveLoad_Heroes_LastIndex
if udg_SaveLoad_Heroes[i]==n then
return i
endif
endloop
return SaveLoad_Id2CId(n)
endfunction
function SaveLoad_Integer2Unit takes integer i returns integer
if udg_SaveLoad_Initialized==false then
set udg_SaveLoad_Initialized=true
call SaveLoad_InitialSetup()
endif
if i<=udg_SaveLoad_Heroes_LastIndex then
return udg_SaveLoad_Heroes[i]
endif
return SaveLoad_CId2Id(i)
endfunction
function SaveLoad_Item2Integer takes item t returns integer
local integer i=0
local integer n=GetItemTypeId(t)
if udg_SaveLoad_Initialized==false then
set udg_SaveLoad_Initialized=true
call SaveLoad_InitialSetup()
endif
loop
set i=i+1
exitwhen i>udg_SaveLoad_Items_LastIndex
if udg_SaveLoad_Items[i]==n then
return i
endif
endloop
return SaveLoad_Id2CId(n)
endfunction
function SaveLoad_Integer2Item takes integer i returns integer
if udg_SaveLoad_Initialized==false then
set udg_SaveLoad_Initialized=true
call SaveLoad_InitialSetup()
endif
if i<=udg_SaveLoad_Items_LastIndex then
return udg_SaveLoad_Items[i]
endif
return SaveLoad_CId2Id(i)
endfunction
function SaveLoad_Ability2Integer takes integer a returns integer
local integer i=0
if udg_SaveLoad_Initialized==false then
set udg_SaveLoad_Initialized=true
call SaveLoad_InitialSetup()
endif
loop
set i=i+1
exitwhen i>udg_SaveLoad_Abilities_LastIndex
if udg_SaveLoad_Abilities[i]==a then
return i
endif
endloop
return SaveLoad_Id2CId(a)
endfunction
function SaveLoad_Integer2Ability takes integer i returns integer
if udg_SaveLoad_Initialized==false then
set udg_SaveLoad_Initialized=true
call SaveLoad_InitialSetup()
endif
if i<=udg_SaveLoad_Abilities_LastIndex then
return udg_SaveLoad_Abilities[i]
endif
return SaveLoad_CId2Id(i)
endfunction
function SaveLoad_Color takes string s returns string
local integer i=StringLength(s)
local string c
local string r=""
loop
set i=i-1
set c=SubString(s,i,i+1)
if c=="0" or c=="1" or c=="2" or c=="3" or c=="4" or c=="5" or c=="6" or c=="7" or c=="8" or c=="9" then
set r="|cffffcc00"+c+"|r"+r
elseif c=="-" then
set r="|cffdddddd-|r"+r
else
set r=c+r
endif
exitwhen i<=0
endloop
return r
endfunction
function SaveLoad_EncodeChar takes string n returns integer
local integer i=0
local string s1="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
local string s2="abcdefghijklmnopqrstuvwxyz"
local string s3="0123456789"
loop
if SubString(s1,i,i+1)==n then
return i
endif
if SubString(s2,i,i+1)==n then
return i
endif
set i=i+1
exitwhen i>=26
endloop
set i=0
loop
if SubString(s3,i,i+1)==n then
return i
endif
set i=i+1
exitwhen i>=10
endloop
return 0
endfunction
function SaveLoad_EncodeVerify takes string buffer returns integer
local integer i=0
local integer j=0
local string name=GetPlayerName(GetTriggerPlayer())
if udg_SaveLoad_UsePlayername==true then
loop
set j=j+SaveLoad_EncodeChar(SubString(name,i,i+1))
set i=i+1
exitwhen i>=StringLength(name)
endloop
endif
set i=0
loop
set j=j+SaveLoad_EncodeChar(SubString(buffer,i,i+1))
set i=i+1
exitwhen i>=StringLength(buffer)
endloop
return j
endfunction
function SaveLoad_EncodeValues takes nothing returns string
local integer i
local integer j
local integer k
local integer l
local integer m
local integer CodeLength=StringLength(udg_SaveLoad_Alphabet)
local integer array a
local string buffer=""
local string c=""
local integer skip=0
local integer CONST=1000000
local string abc="0123456789"
set i=0
loop
set i=i+1
exitwhen i>udg_SaveCount
set buffer=buffer+I2S(udg_Save[i])+"-"
endloop
set buffer=buffer+I2S(SaveLoad_EncodeVerify(buffer))
if udg_Save[1]==0 then
set buffer="-"+buffer
endif
set i=0
loop
set a[i]=0
set i=i+1
exitwhen i>=100
endloop
set m=0
set i=0
loop
set j=0
loop
set a[j]=a[j]*11
set j=j+1
exitwhen j>m
endloop
set l=0
set c=SubString(buffer,i,i+1)
loop
exitwhen SubString(abc,l,l+1)==c
set l=l+1
exitwhen l>9
endloop
set a[0]=a[0]+l
set j=0
loop
set k=a[j]/ CONST
set a[j]=a[j]-k*CONST
set a[j+1]=a[j+1]+k
set j=j+1
exitwhen j>m
endloop
if k>0 then
set m=m+1
endif
set i=i+1
exitwhen i>=StringLength(buffer)
endloop
set buffer=""
loop
exitwhen m<0
set j=m
loop
exitwhen j<=0
set k=a[j]/ CodeLength
set a[j-1]=a[j-1]+(a[j]-k*CodeLength)*CONST
set a[j]=k
set j=j-1
endloop
set k=a[j]/ CodeLength
set i=a[j]-k*CodeLength
set buffer=buffer+SubString(udg_SaveLoad_Alphabet,i,i+1)
set a[j]=k
if a[m]==0 then
set m=m-1
endif
endloop
set i=StringLength(buffer)
set skip=0
set c=""
loop
set i=i-1
set c=c+SubString(buffer,i,i+1)
set skip=skip+1
if skip==4 and i>0 then
set c=c+"-"
set skip=0
endif
exitwhen i<=0
endloop
return c
endfunction
function SaveLoad_DecodeValues takes string s returns boolean
local integer i
local integer j
local integer k
local integer l
local integer SaveCode=0
local integer m
local integer array a
local string buffer=""
local integer CodeLength=StringLength(udg_SaveLoad_Alphabet)
local integer skip=-1
local integer CONST=1000000
local string abc="0123456789-"
local string c
set i=0
loop
set a[i]=0
set i=i+1
exitwhen i>=100
endloop
set m=0
set i=0
loop
set j=0
loop
set a[j]=a[j]*CodeLength
set j=j+1
exitwhen j>m
endloop
set skip=skip+1
if skip==4 then
set skip=0
set i=i+1
endif
set l=CodeLength
set c=SubString(s,i,i+1)
loop
set l=l-1
exitwhen l<1
exitwhen SubString(udg_SaveLoad_Alphabet,l,l+1)==c
endloop
set a[0]=a[0]+l
set j=0
loop
set k=a[j]/ CONST
set a[j]=a[j]-k*CONST
set a[j+1]=a[j+1]+k
set j=j+1
exitwhen j>m
endloop
if k>0 then
set m=m+1
endif
set i=i+1
exitwhen i>=StringLength(s)
endloop
loop
exitwhen m<0
set j=m
loop
exitwhen j<=0
set k=a[j]/ 11
set a[j-1]=a[j-1]+(a[j]-k*11)*CONST
set a[j]=k
set j=j-1
endloop
set k=a[j]/ 11
set i=a[j]-k*11
set buffer=SubString(abc,i,i+1)+buffer
set a[j]=k
if a[m]==0 then
set m=m-1
endif
endloop
set i=0
set j=0
loop
loop
exitwhen i>=StringLength(buffer)
exitwhen i>0 and SubString(buffer,i,i+1)=="-" and SubString(buffer,i-1,i)!="-"
set i=i+1
endloop
if i<StringLength(buffer)then
set k=i
endif
set SaveCode=SaveCode+1
set udg_Save[SaveCode]=S2I(SubString(buffer,j,i))
set j=i+1
set i=i+1
exitwhen i>=StringLength(buffer)
endloop
set j=SaveLoad_EncodeVerify(SubString(buffer,0,k))
set udg_SaveCount=SaveCode-1
if j==udg_Save[SaveCode]then
return true
endif
return false
endfunction
function SaveLoad_Encode takes nothing returns string
if udg_SaveLoad_CaseSensitive==false then
set udg_SaveLoad_Alphabet=StringCase(udg_SaveLoad_Alphabet,true)
endif
return SaveLoad_Color(SaveLoad_EncodeValues())
endfunction
function SaveLoad_Decode takes string s returns boolean
if udg_SaveLoad_CaseSensitive==false then
set udg_SaveLoad_Alphabet=StringCase(udg_SaveLoad_Alphabet,true)
set s=StringCase(s,true)
endif
if SaveLoad_DecodeValues(s)then
call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"Decoding sucessful")
return true
endif
call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"Decoding failed")
return false
endfunction
function Trig_SaveLoad_Initialization_Actions takes nothing returns nothing
set udg_SaveLoad_Alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
set udg_SaveLoad_CaseSensitive=false
set udg_SaveLoad_UsePlayername=true
set udg_SaveLoad_Initialized=false
set udg_Code=""
set udg_Save[1]=0
set udg_SaveCount=1
set udg_Validate=false
set udg_SaveLoad_Compress[1]=0
set udg_SaveLoad_Uncompress[1]=0
endfunction
function InitTrig_SaveLoad_Initialization takes nothing returns nothing
set gg_trg_SaveLoad_Initialization=CreateTrigger()
call TriggerAddAction(gg_trg_SaveLoad_Initialization,function Trig_SaveLoad_Initialization_Actions)
endfunction
function Trig_SaveLoad_Save_Actions takes nothing returns nothing
set udg_Save[1]=udg_ExpInteger[GetPlayerId(GetTriggerPlayer())]
set udg_SaveCount=1
set udg_Code=SaveLoad_Encode()
call QuestMessageBJ(GetForceOfPlayer(GetTriggerPlayer()),bj_QUESTMESSAGE_SECRET,"Your code is:")
call DisplayTimedTextToForce(GetForceOfPlayer(GetTriggerPlayer()),60.00,udg_Code)
endfunction
function InitTrig_SaveLoad_Save takes nothing returns nothing
set gg_trg_SaveLoad_Save=CreateTrigger()
call TriggerRegisterPlayerChatEvent(gg_trg_SaveLoad_Save,Player(0),"-save",true)
call TriggerRegisterPlayerChatEvent(gg_trg_SaveLoad_Save,Player(1),"-save",true)
call TriggerRegisterPlayerChatEvent(gg_trg_SaveLoad_Save,Player(2),"-save",true)
call TriggerRegisterPlayerChatEvent(gg_trg_SaveLoad_Save,Player(3),"-save",true)
call TriggerAddAction(gg_trg_SaveLoad_Save,function Trig_SaveLoad_Save_Actions)
endfunction
function Trig_SaveLoad_Load_Conditions takes nothing returns boolean
if(not(SubStringBJ(GetEventPlayerChatString(),1,6)==GetEventPlayerChatStringMatched()))then
return false
endif
if(not(StringLength(GetEventPlayerChatString())>6))then
return false
endif
return true
endfunction
function Trig_SaveLoad_Load_Func004C takes nothing returns boolean
if(not(udg_Validate==true))then
return false
endif
return true
endfunction
function Trig_SaveLoad_Load_Actions takes nothing returns nothing
set udg_Code=SubStringBJ(GetEventPlayerChatString(),7,StringLength(GetEventPlayerChatString()))
set udg_Validate=SaveLoad_Decode(udg_Code)
if(Trig_SaveLoad_Load_Func004C())then
set bj_forLoopAIndex=1
set bj_forLoopAIndexEnd=udg_SaveCount
loop
exitwhen bj_forLoopAIndex>bj_forLoopAIndexEnd
call DisplayTextToForce(GetForceOfPlayer(GetTriggerPlayer()),("Decode: "+I2S(udg_Save[GetForLoopIndexA()])))
set udg_ExpInteger[GetPlayerId(GetTriggerPlayer())]=udg_Save[GetForLoopIndexA()]
set bj_forLoopAIndex=bj_forLoopAIndex+1
endloop
else
call DisplayTextToForce(GetForceOfPlayer(GetTriggerPlayer()),"Invalid code")
endif
endfunction
function InitTrig_SaveLoad_Load takes nothing returns nothing
set gg_trg_SaveLoad_Load=CreateTrigger()
call TriggerRegisterPlayerChatEvent(gg_trg_SaveLoad_Load,Player(0),"-load ",false)
call TriggerRegisterPlayerChatEvent(gg_trg_SaveLoad_Load,Player(1),"-load ",false)
call TriggerRegisterPlayerChatEvent(gg_trg_SaveLoad_Load,Player(2),"-load ",false)
call TriggerRegisterPlayerChatEvent(gg_trg_SaveLoad_Load,Player(3),"-load ",false)
call TriggerAddCondition(gg_trg_SaveLoad_Load,Condition(function Trig_SaveLoad_Load_Conditions))
call TriggerAddAction(gg_trg_SaveLoad_Load,function Trig_SaveLoad_Load_Actions)
endfunction
function InitCustomTriggers takes nothing returns nothing
call InitTrig_SaveLoad_Initialization()
call InitTrig_SaveLoad_Save()
call InitTrig_SaveLoad_Load()
endfunction
function RunInitializationTriggers takes nothing returns nothing
call ConditionalTriggerExecute(gg_trg_SaveLoad_Initialization)
endfunction

Using the integer array "udg_ExpInteger" with player id's, not converted.
User avatar
Crazy-Host
Newcomer
Posts: 17
Joined: February 12th, 2011, 8:02 pm
Title: Just Another Newbie
Location: Behind You

Re: Save/Load - Saving Integers

Post by Crazy-Host »

Could you code this in GUI?
Just create a variable named "Points"
Just input the code into this sample save/load map.
You do not have the required permissions to view the files attached to this post.
You do not have the required permissions to view my awesome signature.