scope savehero initializer init
//! textmacro ToSave takes player
set ToSave = udg_Geroi[GetConvertedPlayerId(GetTriggerPlayer())]
//! endtextmacro
//! textmacro ToLoad takes player
call RemoveUnit(udg_Geroi[GetConvertedPlayerId(GetTriggerPlayer())])
set udg_Geroi[GetConvertedPlayerId(GetTriggerPlayer())] = ToSave
//! endtextmacro
globals
unit ToSave = null
endglobals
private constant function abs takes integer i returns integer
if i<0 then
return -i
endif
return i
endfunction
private constant function modulo takes integer i returns integer
return abs(i-(i/1000)*1000)
endfunction
globals
private integer array spl[8][1000]
endglobals
function RegisterHeroSpell takes integer hero_id,integer id,integer spell returns nothing
set spl[id][modulo(hero_id)]=spell
endfunction
private function LoadHero takes nothing returns nothing
local integer i = 0
local integer id = 0
local integer a = 0
local player p = GetTriggerPlayer()
call LoadData("save_load",p)
set i = ReadInteger(0x01,p)
if i==0 then
call DisplayTextToPlayer(p,0,0,"Hero not saved")
return
endif
debug call BJDebugMsg("Load Hero : " + I2S(i))
set ToSave = CreateUnit(p,i,0,0,0)
set i = ReadInteger(0x02,p)
call SetHeroStr(ToSave,i,true)
set i = ReadInteger(0x03,p)
call SetHeroAgi(ToSave,i,true)
set i = ReadInteger(0x04,p)
call SetHeroInt(ToSave,i,true)
set i = ReadInteger(0x05,p)
call SetHeroXP(ToSave,i,true)
set id = GetUnitTypeId(ToSave)
set a = spl[0][modulo(id)]
if a>0 then
set i = ReadInteger(0x06,p)
if i>0 then
call UnitAddAbility(ToSave,a)
call SetUnitAbilityLevel(ToSave,a,i)
endif
endif
set a = spl[1][modulo(id)]
if a>0 then
set i = ReadInteger(0x07,p)
if i>0 then
call UnitAddAbility(ToSave,a)
call SetUnitAbilityLevel(ToSave,a,i)
endif
endif
set a = spl[2][modulo(id)]
if a>0 then
set i = ReadInteger(0x08,p)
if i>0 then
call UnitAddAbility(ToSave,a)
call SetUnitAbilityLevel(ToSave,a,i)
endif
endif
set a = spl[3][modulo(id)]
if a>0 then
set i = ReadInteger(0x09,p)
if i>0 then
call UnitAddAbility(ToSave,a)
call SetUnitAbilityLevel(ToSave,a,i)
endif
endif
set a = spl[4][modulo(id)]
if a>0 then
set i = ReadInteger(0x0A,p)
if i>0 then
call UnitAddAbility(ToSave,a)
call SetUnitAbilityLevel(ToSave,a,i)
endif
endif
set a = spl[5][modulo(id)]
if a!=0 then
set i = ReadInteger(0x0B,p)
if i>0 then
call UnitAddAbility(ToSave,a)
call SetUnitAbilityLevel(ToSave,a,i)
endif
endif
set a = spl[6][modulo(id)]
if a!=0 then
set i = ReadInteger(0x0C,p)
if i>0 then
call UnitAddAbility(ToSave,a)
call SetUnitAbilityLevel(ToSave,a,i)
endif
endif
set a = spl[7][modulo(id)]
if a!=0 then
set i = ReadInteger(0x0D,p)
if i>0 then
call UnitAddAbility(ToSave,a)
call SetUnitAbilityLevel(ToSave,a,i)
endif
endif
set i = ReadInteger(0x0E,p)
if i!=0 then
call UnitAddItemToSlotById(ToSave,i,0)
endif
set i = ReadInteger(0x0F,p)
if i!=0 then
call UnitAddItemToSlotById(ToSave,i,1)
endif
set i = ReadInteger(0x10,p)
if i!=0 then
call UnitAddItemToSlotById(ToSave,i,2)
endif
set i = ReadInteger(0x11,p)
if i!=0 then
call UnitAddItemToSlotById(ToSave,i,3)
endif
set i = ReadInteger(0x12,p)
if i!=0 then
call UnitAddItemToSlotById(ToSave,i,4)
endif
set i = ReadInteger(0x13,p)
if i!=0 then
call UnitAddItemToSlotById(ToSave,i,5)
endif
set i = ReadInteger(0x14,p)
call UnitModifySkillPoints(ToSave,i-GetHeroSkillPoints(ToSave))
//! runtextmacro HeroSaverPlugin_OnLoad("p")
//! runtextmacro ToLoad("p")
set ToSave = null
endfunction
private function SaveHero takes nothing returns nothing
local integer id = 0
local player p = GetTriggerPlayer()
//! runtextmacro ToSave("GetPlayerId(p)")
set id = GetUnitTypeId(ToSave)
debug call BJDebugMsg("Save Hero : " + I2S(id))
call CreateData(p)
call AddInteger(0x01,id,p)
call AddInteger(0x02,GetHeroStr(ToSave,false),p)
call AddInteger(0x03,GetHeroAgi(ToSave,false),p)
call AddInteger(0x04,GetHeroInt(ToSave,false),p)
call AddInteger(0x05,GetHeroXP(ToSave),p)
call AddInteger(0x06,GetUnitAbilityLevel(ToSave,spl[0][modulo(id)]),p)
call AddInteger(0x07,GetUnitAbilityLevel(ToSave,spl[1][modulo(id)]),p)
call AddInteger(0x08,GetUnitAbilityLevel(ToSave,spl[2][modulo(id)]),p)
call AddInteger(0x09,GetUnitAbilityLevel(ToSave,spl[3][modulo(id)]),p)
call AddInteger(0x0A,GetUnitAbilityLevel(ToSave,spl[4][modulo(id)]),p)
call AddInteger(0x0B,GetUnitAbilityLevel(ToSave,spl[5][modulo(id)]),p)
call AddInteger(0x0C,GetUnitAbilityLevel(ToSave,spl[6][modulo(id)]),p)
call AddInteger(0x0D,GetUnitAbilityLevel(ToSave,spl[7][modulo(id)]),p)
call AddInteger(0x0E,GetItemTypeId(UnitItemInSlot(ToSave,0)),p)
call AddInteger(0x0F,GetItemTypeId(UnitItemInSlot(ToSave,1)),p)
call AddInteger(0x10,GetItemTypeId(UnitItemInSlot(ToSave,2)),p)
call AddInteger(0x11,GetItemTypeId(UnitItemInSlot(ToSave,3)),p)
call AddInteger(0x12,GetItemTypeId(UnitItemInSlot(ToSave,4)),p)
call AddInteger(0x13,GetItemTypeId(UnitItemInSlot(ToSave,5)),p)
call AddInteger(0x14,GetHeroSkillPoints(ToSave),p)
//! runtextmacro HeroSaverPlugin_OnSave("p")
call SaveData("save_load",p)
endfunction
function initSaveLoad takes nothing returns nothing
local trigger t=CreateTrigger()
local integer i=0
loop
call TriggerRegisterPlayerChatEvent(t,Player(i),"-save",true)
set i=i+1
exitwhen i>11
endloop
call TriggerAddAction(t,function SaveHero)
set t=CreateTrigger()
set i=0
loop
call TriggerRegisterPlayerChatEvent(t,Player(i),"-load",true)
set i=i+1
exitwhen i>11
endloop
call TriggerAddAction(t,function LoadHero)
endfunction
private function init takes nothing returns nothing
call ExecuteFunc("initSaveLoad")
call RegisterHeroSpell('H00B',0,'A00H')
call RegisterHeroSpell('H00B',1,'A00I')
endfunction
endscope