My idea was basically this, make a version of Nestharus's vJass code system so that a GUI user (using jngp) could input variables inside of a GUI trigger and the vJass would handle the rest. The problem is im terribad at vJass so can anyone look over my trigger and give me any feedback? I haven't tested it yet.
One of the main points of the listing phase in this trigger is that, when you make a new version and add items, you can just say set saveAbilNextVersion = Your first item of the next version and older versions will still be compatible.
This is the main vJass counterpart to the trigger
My self-creating iteem catalog (its after the onInit trigger so it will fire with the correct variables)
Ability Catalog
and Hero Cat
and a temporary struct, i might ditch this and inline it myself
One of the main points of the listing phase in this trigger is that, when you make a new version and add items, you can just say set saveAbilNextVersion = Your first item of the next version and older versions will still be compatible.
Save Load onInit
Events
Map initialization
Conditions
Actions
-------- Basic Variables --------
Set savedHero[1] = Blood Mage 0009 <gen>
Set savedBackpack[1] = Mountain King 0001 <gen>
Set saveItemsBackpack = True
Set saveItemsHero = True
-------- You need to set savedHero and/or savedBackpack if they are ever changed mid-game. Same with PointWhereHeroLoads --------
Set saveExp = True
Set saveLevel = True
Set saveMaxHeroLevel = 4000
Set savePointWhereHeroLoads = (Position of (Triggering unit))
-------- Setting only XP will result in a level 1 hero with # exp --------
Set saveAbilities = True
Set saveHeroStats = True
Set saveInitialStatMax = 10
Set saveStatMaxPerLevel = 5
-------- Self Explanatory. Note that it will only count added stats, NOT base stats --------
Set saveGold = True
Set saveWood = True
Set saveGoldMax = 1000000
Set saveWoodMax = 1000000
-------- States the maximum for a player's gold, wood, and a unit's three stats --------
Set saveMessage = Saving.
Set saveOnLoadMessage = Loaded
-------- Messages on Loading and Saving --------
Set saveRepeatedCharacter = -
Set saveRepeatingCharacterDelay = 4
-------- The character "repeatedCharacter" shows every "repeatingCharacterDelay" characters --------
Set savePassword = Af9gk3
-------- Change this to wipe codes --------
Set saveColorNumber = 40e0d0
Set saveColorLowercase = ff69b4
Set saveColoruppercase = 00AA00
Set saveColorSpecial = ffff00
-------- Color codes. Must be hexadecimal or codes will be messed up --------
Set saveAlphabet = 0123456789abcdefghijklmnopqrstuvwxyz
Custom script:
-------- Begin Listing Phase --------
Custom script:
-------- Items --------
Set saveItems[0] = Claws of Attack +15
Set saveItems[1] = Scroll of Animate Dead
Set saveItemCharges[1] = True
-------- The variable with "Charges" states that it should not only save the item but the item charges as well. By default it's false so you don't have to set it for 0 charge iteems --------
Set saveItems[2] = Gem Fragment
Set saveItems[3] = Red Drake Egg
Set saveItemCharges[3] = True
Set newItemVersion[1] = 4
-------- Starts a version with new items. This must be added when you add items onto the list or else the old codes won't work --------
-------- The # indicates the first item to use that version --------
Set saveItems[4] = Skeletal Artifact
Set saveItems[5] = Scroll of Resurrection
Set saveItemCharges[5] = True
Set newItemVersion[2] = 6
Set saveItems[6] = Amulet of the Wild
Set newItemVersionMax = 2
-------- The last version used --------
Set saveItemsMax = 6
-------- From Here On, the listing is the same as above --------
-------- Abilities --------
Set saveAbility[0] = Storm Bolt
Set saveAbility[1] = Storm Bolt
Set newAbilVersion[1] = 2
Set saveAbility[2] = Thunder Clap
Set saveAbility[3] = Bash
Set saveAbility[4] = Avatar
Set newAbilVersionMax = 1
Set saveAbilMax = 3
-------- Heroes --------
Set saveHeroes[0] = Mountain King
Set saveHeroes[1] = Blood Mage
Set newHeroVersion[1] = 2
Set saveHeroes[2] = Paladin
Set saveHeroes[3] = Archmage
Set newHeroVersionMax = 1
Set saveHeroesMax = 3
Events
Map initialization
Conditions
Actions
-------- Basic Variables --------
Set savedHero[1] = Blood Mage 0009 <gen>
Set savedBackpack[1] = Mountain King 0001 <gen>
Set saveItemsBackpack = True
Set saveItemsHero = True
-------- You need to set savedHero and/or savedBackpack if they are ever changed mid-game. Same with PointWhereHeroLoads --------
Set saveExp = True
Set saveLevel = True
Set saveMaxHeroLevel = 4000
Set savePointWhereHeroLoads = (Position of (Triggering unit))
-------- Setting only XP will result in a level 1 hero with # exp --------
Set saveAbilities = True
Set saveHeroStats = True
Set saveInitialStatMax = 10
Set saveStatMaxPerLevel = 5
-------- Self Explanatory. Note that it will only count added stats, NOT base stats --------
Set saveGold = True
Set saveWood = True
Set saveGoldMax = 1000000
Set saveWoodMax = 1000000
-------- States the maximum for a player's gold, wood, and a unit's three stats --------
Set saveMessage = Saving.
Set saveOnLoadMessage = Loaded
-------- Messages on Loading and Saving --------
Set saveRepeatedCharacter = -
Set saveRepeatingCharacterDelay = 4
-------- The character "repeatedCharacter" shows every "repeatingCharacterDelay" characters --------
Set savePassword = Af9gk3
-------- Change this to wipe codes --------
Set saveColorNumber = 40e0d0
Set saveColorLowercase = ff69b4
Set saveColoruppercase = 00AA00
Set saveColorSpecial = ffff00
-------- Color codes. Must be hexadecimal or codes will be messed up --------
Set saveAlphabet = 0123456789abcdefghijklmnopqrstuvwxyz
Custom script:
-------- Begin Listing Phase --------
Custom script:
-------- Items --------
Set saveItems[0] = Claws of Attack +15
Set saveItems[1] = Scroll of Animate Dead
Set saveItemCharges[1] = True
-------- The variable with "Charges" states that it should not only save the item but the item charges as well. By default it's false so you don't have to set it for 0 charge iteems --------
Set saveItems[2] = Gem Fragment
Set saveItems[3] = Red Drake Egg
Set saveItemCharges[3] = True
Set newItemVersion[1] = 4
-------- Starts a version with new items. This must be added when you add items onto the list or else the old codes won't work --------
-------- The # indicates the first item to use that version --------
Set saveItems[4] = Skeletal Artifact
Set saveItems[5] = Scroll of Resurrection
Set saveItemCharges[5] = True
Set newItemVersion[2] = 6
Set saveItems[6] = Amulet of the Wild
Set newItemVersionMax = 2
-------- The last version used --------
Set saveItemsMax = 6
-------- From Here On, the listing is the same as above --------
-------- Abilities --------
Set saveAbility[0] = Storm Bolt
Set saveAbility[1] = Storm Bolt
Set newAbilVersion[1] = 2
Set saveAbility[2] = Thunder Clap
Set saveAbility[3] = Bash
Set saveAbility[4] = Avatar
Set newAbilVersionMax = 1
Set saveAbilMax = 3
-------- Heroes --------
Set saveHeroes[0] = Mountain King
Set saveHeroes[1] = Blood Mage
Set newHeroVersion[1] = 2
Set saveHeroes[2] = Paladin
Set saveHeroes[3] = Archmage
Set newHeroVersionMax = 1
Set saveHeroesMax = 3
This is the main vJass counterpart to the trigger
JASS:
struct SavingvJassCounterpart extends array
private static Base encryptionKey
private static method save takes nothing returns boolean
local NumberStack stack = NumberStack.create(encryptionKey)
local string encrypted
local unit herounit = udg_savedHero[GetPlayerId(GetTriggerPlayer())]
local unit backpackunit = udg_savedBackpack[GetPlayerId(GetTriggerPlayer())]
if udg_saveItemsBackpack then
call SaveValues.SaveHeroInventory(stack, backpackunit)
endif
if udg_saveItemsHero then
call SaveValues.SaveHeroInventory(stack, herounit)
endif
if udg_saveAbilities then
call SaveValues.SaveAbilites(stack, herounit)
endif
if udg_saveHeroStats then
call SaveValues.SaveStats(stack, herounit)
endif
if udg_saveGold then
call SaveValues.SaveGold(stack, GetTriggerPlayer())
endif
if udg_saveWood then
call SaveValues.SaveWood(stack, GetTriggerPlayer())
endif
if udg_saveExp then
call stack.push(CompressInt(GetHeroXP(herounit) - SaveValues.GetRequiredXP(GetHeroLevel(herounit))), CompressInt(SaveValues.GetRequiredXP(udg_saveMaxHeroLevel) - SaveValues.GetRequiredXP(udg_saveMaxHeroLevel - 1)))
endif
if udg_saveLevel then
call stack.push(GetHeroLevel(herounit), udg_saveMaxHeroLevel)
endif
call stack.push(Heroes[GetUnitTypeId(herounit)].id,Heroes.count)
set encrypted=EncryptNumber(stack, 1000000, 3, /*
*/ GetPlayerId(GetTriggerPlayer()), udg_savePassword, .85)
set encrypted=AddRepeatedString(encrypted,udg_saveRepeatedCharacter,udg_saveRepeatingCharacterDelay,0)
set encrypted=ColorCodeString(encrypted, udg_saveColorNumber, udg_saveColorLowercase, udg_saveColoruppercase, udg_saveColorSpecial, 0)
call DisplayTimedTextToPlayer(GetTriggerPlayer(),0,0,60,encrypted)
call stack.destroy()
return false
endmethod
private static method load takes nothing returns boolean
local string s=GetEventPlayerChatString()
local unit herounit
local unit backpackunit
local NumberStack stack
set s=RemoveString(s,GetEventPlayerChatStringMatched(),1, 0)
set s=RemoveString(s," ",0,0)
set s=RemoveString(s, udg_saveRepeatedCharacter,0,0)
if (0<StringLength(s)) then
set stack = DecryptNumber(s, encryptionKey, 1000000,/*
*/ 3, GetPlayerId(GetTriggerPlayer()),/*
*/ udg_savePassword, .85)
if (0!=stack) then
call DisplayTimedTextToPlayer(GetTriggerPlayer(),0,0,60,udg_saveOnLoadMessage)
set herounit = CreateUnitAtLoc(GetTriggerPlayer(), Heroes[stack.pop(Heroes.count)].raw, udg_savePointWhereHeroLoads, 0.)
set backpackunit = udg_savedBackpack[GetPlayerId(GetTriggerPlayer())]
if udg_saveLevel then
call SetHeroLevel(herounit, stack.pop(udg_saveMaxHeroLevel), false)
endif
if udg_saveExp then
call AddHeroXP(herounit, stack.pop(SaveValues.GetRequiredXP(udg_saveMaxHeroLevel) - SaveValues.GetRequiredXP(udg_saveMaxHeroLevel - 1)), false)
endif
if udg_saveWood then
call SetPlayerState(GetTriggerPlayer(),PLAYER_STATE_RESOURCE_LUMBER, stack.pop(DecompressInt(udg_saveWoodMax)))
endif
if udg_saveGold then
call SetPlayerState(GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD, stack.pop(DecompressInt(udg_saveWoodMax)))
endif
if udg_saveHeroStats then
call LoadHeroStats(stack, herounit, udg_saveInitialStatMax + ((GetHeroLevel(herounit) * udg_saveStatMaxPerLevel)))
endif
if udg_saveAbilities then
call LoadHeroAbilities(stack, herounit, Abilites.catalog)
endif
if udg_saveItemsHero then
call LoadInventory(stack, herounit,Items.catalog)
endif
if udg_saveItemsBackpack then
call LoadInventory(stack, herounit,Items.catalog)
endif
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
set encryptionKey=Base[udg_saveAlphabet]
call InitSave("-save", "-load", Condition(function thistype.save),/*
*/Condition(function thistype.load))
endmethod
endstruct
My self-creating iteem catalog (its after the onInit trigger so it will fire with the correct variables)
JASS:
/********************************************************************************************
Item Catalog Creation
********************************************************************************************/
struct Items extends array
private static integer array catalogs
private static integer catalogCount=0
private static integer versionCurrent=1
private static method operator nextVersion takes nothing returns integer
set catalogCount=catalogCount+1
set catalogs[catalogCount]=CatalogCreate()
if (catalogCount>1) then
call CatalogAddCatalog(catalogs[catalogCount],catalogs[catalogCount-1])
endif
return catalogs[catalogCount]
endmethod
private static method isNextVersion takes integer current, integer catalog returns integer
if current == udg_newItemVersion[versionCurrent] then
set versionCurrent = versionCurrent + 1
return nextVersion
endif
return catalog
endmethod
private static method onInit takes nothing returns nothing
local integer catalog=nextVersion
local integer loopingInteger=0
loop
exitwhen loopingInteger==udg_saveItemsMax
if udg_saveItemsHero then
set catalog = isNextVersion(loopingInteger, catalog)
call CatalogAdd(catalog, udg_saveItems[loopingInteger])
endif
endloop
endmethod
static method operator version takes nothing returns integer
return catalogCount
endmethod
method operator count takes nothing returns integer
return CatalogCount(this)
endmethod
static method operator [] takes integer catalogVersion returns thistype
return catalogs[catalogVersion]
endmethod
method catalog takes nothing returns integer
return this
endmethod
method raw takes integer itemId returns integer
return CatalogRaw(this,itemId)
endmethod
method id takes integer itemTypeId returns integer
return CatalogId(this,itemTypeId)
endmethod
//Saving
//Items.version.id('id00')
//Items.version.id(GetItemTypeId(item))
//call stack.push(Items.version.id(GetItemTypeId(item)),Items.version.count)
//using specific version rather than latest
//Items[1].id('id00')
//Loading
//CreateItem(Items.version.raw(itemIdFromCode),0,0)
//call CreateItem(Items.version.raw(stack.pop(Items.count)),0,0)
//keep in mind that this will also work
//catalog1.add('id00')
//catalog2.addCatalog(catalog1)
//catalog1.add('id01')
//catalog 2 will had id00 and id01 and will have 2 total in it
//this is great because it makes hero specific w/ slots item catalogs easy
//can layer just like general item catalogs
endstruct
Ability Catalog
JASS:
/********************************************************************************************
Ability Catalog Creation
********************************************************************************************/
struct Abilites extends array
private static integer array catalogs
private static integer catalogCount=0
private static integer versionCurrent=1
private static method operator nextVersion takes nothing returns integer
set catalogCount=catalogCount+1
set catalogs[catalogCount]=CatalogCreate()
if (catalogCount>1) then
call CatalogAddCatalog(catalogs[catalogCount],catalogs[catalogCount-1])
endif
return catalogs[catalogCount]
endmethod
private static method isNextVersion takes integer current, integer catalog returns integer
if current == udg_newAbilVersion[versionCurrent] then
set versionCurrent = versionCurrent + 1
return nextVersion
endif
return catalog
endmethod
private static method onInit takes nothing returns nothing
local integer catalog=nextVersion
local integer loopingInteger=0
loop
exitwhen loopingInteger==udg_saveAbilMax
if udg_saveAbilities then
set catalog = isNextVersion(loopingInteger, catalog)
call CatalogAdd(catalog, udg_saveAbility[loopingInteger])
endif
endloop
endmethod
static method operator version takes nothing returns integer
return catalogCount
endmethod
method operator count takes nothing returns integer
return CatalogCount(this)
endmethod
static method operator [] takes integer catalogVersion returns thistype
return catalogs[catalogVersion]
endmethod
method catalog takes nothing returns integer
return this
endmethod
method raw takes integer itemId returns integer
return CatalogRaw(this,itemId)
endmethod
method id takes integer itemTypeId returns integer
return CatalogId(this,itemTypeId)
endmethod
//Saving
//Items.version.id('id00')
//Items.version.id(GetItemTypeId(item))
//call stack.push(Items.version.id(GetItemTypeId(item)),Items.version.count)
//using specific version rather than latest
//Items[1].id('id00')
//Loading
//CreateItem(Items.version.raw(itemIdFromCode),0,0)
//call CreateItem(Items.version.raw(stack.pop(Items.count)),0,0)
//keep in mind that this will also work
//catalog1.add('id00')
//catalog2.addCatalog(catalog1)
//catalog1.add('id01')
//catalog 2 will had id00 and id01 and will have 2 total in it
//this is great because it makes hero specific w/ slots item catalogs easy
//can layer just like general item catalogs
endstruct
and Hero Cat
JASS:
/********************************************************************************************
Hero Catalog Creation
********************************************************************************************/
struct Heroes extends array
implement Catalog
private static integer array catalogs
private static integer catalogCount=0
private static integer versionCurrent=1
private static method operator nextVersion takes nothing returns integer
set catalogCount=catalogCount+1
set catalogs[catalogCount]=CatalogCreate()
if (catalogCount>1) then
call CatalogAddCatalog(catalogs[catalogCount],catalogs[catalogCount-1])
endif
return catalogs[catalogCount]
endmethod
private static method isNextVersion takes integer current, integer catalog returns integer
if current == udg_newHeroVersion[versionCurrent] then
set versionCurrent = versionCurrent + 1
return nextVersion
endif
return catalog
endmethod
private static method onInit takes nothing returns nothing
local integer catalog=nextVersion
local integer loopingInteger=0
loop
exitwhen loopingInteger==udg_saveHeroesMax
set catalog = isNextVersion(loopingInteger, catalog)
call CatalogAdd(catalog, udg_saveHeroes[loopingInteger])
endloop
endmethod
//Saving
//Heroes['id00'].id
//Heroes[GetUnitTypeId(hero)].id
//call stack.push(Heroes[GetUnitTypeId(hero)].id,Heroes.count)
//Loading
//CreateUnit(Heroes[unitIdFromCode].raw,0,0)
//call CreateUnit(Heroes[stack.pop(Heroes.count)].raw,0,0)
endstruct
and a temporary struct, i might ditch this and inline it myself
JASS:
struct SaveValues
static method SaveHeroInventory takes NumberStack stack, unit playerUnit returns nothing
call SaveInventory(stack, playerUnit, Items.catalog)
endmethod
static method GetRequiredXP takes integer level returns integer
local integer xp = 0
loop
exitwhen level == 0
set xp = xp + (level + 1) * 100
set level = level - 1
endloop
return xp
endmethod
static method SaveAbilites takes NumberStack stack, unit playerUnit returns nothing
call SaveHeroAbilities(stack, playerUnit, Abilites.catalog)
endmethod
static method SaveStats takes NumberStack stack, unit playerUnit returns nothing
call SaveHeroStats(stack, playerUnit, udg_saveInitialStatMax + (udg_saveStatMaxPerLevel * (GetHeroLevel(playerUnit) - 1)))
endmethod
static method SaveGold takes NumberStack stack, player triggering returns nothing
call stack.push(CompressInt(GetPlayerState(triggering, PLAYER_STATE_RESOURCE_GOLD)), udg_saveGoldMax)
endmethod
static method SaveWood takes NumberStack stack, player triggering returns nothing
call stack.push(CompressInt(GetPlayerState(triggering, PLAYER_STATE_RESOURCE_LUMBER)), udg_saveWoodMax)
endmethod
static method LoadHeroInventory takes NumberStack stack, unit target returns nothing
endmethod
endstruct