hello
i've been using Nestharus's awesome Encoder
but this save function keep freezes the game... would appreciate some help
a question : can i put conditions within the function?
i've been using Nestharus's awesome Encoder
but this save function keep freezes the game... would appreciate some help
a question : can i put conditions within the function?
JASS:
private function Save takes nothing returns boolean
local player p = GetTriggerPlayer()
local integer pid = GetPlayerId(p)
local DataBuffer buffer
local unit u = hero[pid]
local integer i
local integer array items
local item array it
local integer ic = 5
local integer t
local ItemCatalog1 cat
local integer uid
local timer ti
local MBData mb
if pdata[pid] then
set buffer = GetCurrentEncoder().write(pid)
set u = hero[pid]
set uid = GetUnitTypeId(u)
if uid == 'H00P' or uid == 'H00Q' then
set cat = ItemCatalog1[0]
elseif uid == 'H025' then
set cat = ItemCatalog1[1]
elseif uid == 'H00C' or uid == 'H00E' or uid == 'H00H' then
set cat = ItemCatalog1[2]
elseif uid == 'H00D' or uid == 'H01I' then
set cat = ItemCatalog1[3]
elseif uid == 'H00B' or uid == 'H01E' then
set cat = ItemCatalog1[4]
elseif uid == 'H024' then
set cat = ItemCatalog1[5]
endif
call buffer.write(HeroCatalog1[uid].id)
call buffer.write(GetHeroLevel(u))
if GetHeroLevel(u) < 126 then
call buffer.write(GetPercentHeroXP(u))
endif
call buffer.write(GetHeroStr(u,false))
call buffer.write(GetHeroAgi(u,false))
call buffer.write(GetHeroInt(u,false))
call buffer.write(Stat[u].token1)
call buffer.write(Stat[u].token2)
set i = 5
loop
set t = cat.id(GetItemTypeId(UnitItemInSlot(u,i)))
if (t != 0) then
set items[ic] = t
set it[ic] = UnitItemInSlot(u, i)
set ic = ic - 1
endif
exitwhen i == 0
set i = i - 1
endloop
set ic = 5
loop
call buffer.write(items[ic])
set it[ic] = null
exitwhen ic == 0 or items[ic] == 0
set ic = ic - 1
endloop
set i = GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)/100
if i > 1000 then
set i = 1000
endif
call buffer.write(i)
call DisplayTimedTextToPlayer(p, 0, 0, 60, buffer.code)
set i = UnitInventorySize(u)
loop
exitwhen i == 0
set i = i - 1
call RI(UnitItemInSlot(u,i))
endloop
set ti = Stat[u].t
set mb = GetTimerData(ti)
call ReleaseTimer(ti)
call mb.destroy()
call Stat[u].mb.clear()
call Stat[u].mb.destroy()
call RemoveUnit(u)
call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,0)
set u = null
set pdata[pid] = false
endif
return false
endfunction