- Joined
- Jul 10, 2007
- Messages
- 6,306
Just a demonstration of simple save using a variety of small resources.
Using snippets is easier than using a save/load system, more dynamic than using a save/load system, and has more power than using a save/load system. All save/load systems are officially deprecated to save/load snippets.
Using snippets is easier than using a save/load system, more dynamic than using a save/load system, and has more power than using a save/load system. All save/load systems are officially deprecated to save/load snippets.
JASS:
struct Demo extends array
private static Base encryptionKey
private static method save takes nothing returns boolean
local NumberStack stack = NumberStack.create(encryptionKey) //create a number stack
local string encrypted
//push numbers on to stack
call stack.push(10,64) //10
call stack.push(20,31) //20,10
//display numbers in stack
call DisplayTimedTextToPlayer(GetTriggerPlayer(),0,0,60,"Saving: 10,20")
//encrypt number as a string
set encrypted=EncryptNumber(stack,1000000,3,GetPlayerId(GetTriggerPlayer()),"salt value",.85)
//add dashes
set encrypted=AddRepeatedString(encrypted,"-",4)
//color
set encrypted=ColorCodeString(encrypted, "40e0d0", "ff69b4", "00AA00", "ffff00")
//display code
call DisplayTimedTextToPlayer(GetTriggerPlayer(),0,0,60,encrypted)
//destroy stack
call stack.destroy()
return false
endmethod
private static method load takes nothing returns boolean
local string s=GetEventPlayerChatString() //retrieve string
local NumberStack stack
set s=RemoveString(s,GetEventPlayerChatStringMatched(),1) //remove "-load "
set s=RemoveString(s," ",0) //remove " "
set s=RemoveString(s,"-",0) //remove "-"
if (IsStringLengthInRange(s,5,9)) then
//retrieve stack of numbers
set stack = DecryptNumber(s,encryptionKey,1000000,3,GetPlayerId(GetTriggerPlayer()),"salt value",.85)
//if stack isn't 0, code is valid
if (0!=stack) then
//display values stored in stack (reverse order)
call DisplayTimedTextToPlayer(GetTriggerPlayer(),0,0,60,"Loaded: "+I2S(stack.pop(31))+","+I2S(stack.pop(64)))
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 onInit takes nothing returns nothing
//register save/load commands
local integer i=11
local trigger t=CreateTrigger() //save
local trigger t2=CreateTrigger() //load
call TriggerAddCondition(t,Condition(function thistype.save))
call TriggerAddCondition(t2,Condition(function thistype.load))
loop
call TriggerRegisterPlayerChatEvent(t,Player(i),"-save",true)
call TriggerRegisterPlayerChatEvent(t2,Player(i),"-load ",false)
exitwhen 0==i
set i=i-1
endloop
//this is the encryption key
set encryptionKey=Base["0123456789abcdefghijklmnopqrstuvwxyz"]
endmethod
endstruct
Attachments
Last edited: