HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Does this leak & is this inefficient (jass gamecache thing)

02-08-2007, 06:55 AM#1
Mythic Fr0st
I wrote this by myself, but have received help for a few things, until I figured out I had to store my unit into a game cache, which I have

I need to know if this is inefficient (what can I do to make it efficient) and does it leak, (including any need to flush my values from gamecache)

I ALSO need to know if this can be used like 11 times in a row without mucking up

What it does

A unit dies, it stores it into a gamecache
Along with its abilities, items, level, so on,
then restores it..

also can you null an integer as such (x) being the integer

x = S2I(""), and does it have any effect?



Collapse JASS:
globals
unit array udg_Backpack_Unit
timerdialog array udg_TimerWind
rect gg_rct_Rect_035
trigger gg_trg_Reviving_Heroes
gamecache udg_Game_Cache
unit array udg_Hero
endglobals

function Revive_Func0X20 takes nothing returns boolean
return (GetUnitTypeId(GetTriggerUnit()) == 'H001' or GetUnitTypeId(GetTriggerUnit()) == 'N00U' or GetUnitTypeId(GetTriggerUnit()) == 'H002' or GetUnitTypeId(GetTriggerUnit()) == 'E003' or GetUnitTypeId(GetTriggerUnit()) == 'N01J' or GetUnitTypeId(GetTriggerUnit()) == 'N00R') and (UnitHasItemOfTypeBJ(udg_Backpack_Unit[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))+1], 'I00N') == false)


endfunction

function Func_1 takes nothing returns nothing
 local timer t = GetExpiredTimer()
 local integer x = GetStoredInteger(udg_Game_Cache, "player", "x")
 local string s = GetStoredString(udg_Game_Cache, "player", "s")
 local unit u = RestoreUnit(udg_Game_Cache, "player", s, Player(x), GetRectCenterX(gg_rct_Rect_035), GetRectCenterY(gg_rct_Rect_035), 270.00)
 local integer i = 0
 local integer array st
 local string array hero_item
 local integer actalvl
 local string array utcode
 local location loc = GetRectCenter(gg_rct_Rect_035)
 local integer lvl
 local integer loop_through
    set st[0] = GetStoredInteger(udg_Game_Cache, "player", "att")
    set st[1] = GetStoredInteger(udg_Game_Cache, "player", "str")
    set st[2] = GetStoredInteger(udg_Game_Cache, "player", "mag")
    loop
        exitwhen i > 5
        set hero_item[i] = GetStoredString(udg_Game_Cache, "player", "item"+I2S(i))
        call UnitAddItemToSlotById(u, S2I(hero_item[i]), i)
        call FlushStoredString(udg_Game_Cache, "player", "item"+I2S(i))
    endloop
    set lvl = GetStoredInteger(udg_Game_Cache, "player", "lvl")
    call SetHeroLevel(u, lvl, false)
    set actalvl = GetStoredInteger(udg_Game_Cache, "player", "abl_lvl")       
    call BJDebugMsg(GetUnitName(u))
    call BJDebugMsg(I2S(x))
    call ShowUnit(udg_Backpack_Unit[x], true)
    call SetUnitPositionLoc(udg_Backpack_Unit[x], loc)
    call PanCameraToTimedLocForPlayer(GetOwningPlayer(u), loc, 0.00)
    call RemoveLocation(loc)
    set loc = null
    call DestroyTimerDialog(udg_TimerWind[x])
    call DestroyTimer(t)
    set t = null
    call FlushStoredInteger(udg_Game_Cache, "player", "x")
    call FlushStoredInteger(udg_Game_Cache, "player", "lvl")
    call FlushStoredInteger(udg_Game_Cache, "player", "abl_lvl")
    call FlushStoredString(udg_Game_Cache, "player", "s")
    call FlushStoredUnit(udg_Game_Cache, "player", s)
    call FlushStoredInteger(udg_Game_Cache, "player", "att")
    call FlushStoredInteger(udg_Game_Cache, "player", "str")
    call FlushStoredInteger(udg_Game_Cache, "player", "mag")
    set x = S2I("")//(Does this null an integer?)
    set u = null
    set s = ""
    set i = S2I("")
    loop
        exitwhen loop_through > 1
            set st[loop_through] = S2I("")
    endloop
    set loop_through = 1
    loop
       exitwhen loop_through > 5
           set hero_item[loop_through] = ""
    endloop
    set loop_through = 1
    set lvl = S2I("")
    set loop_through = S2I("")
    set x = S2I("") //(Does this null the variable ?)
    set actalvl = S2I("")
    
endfunction

function Revive takes nothing returns nothing
 local timer t = CreateTimer()
 local unit u = GetTriggerUnit()
 local integer x = GetPlayerId(GetOwningPlayer(u))+1
 local string s = I2S(x) + GetUnitName(u)
 local string pn = GetPlayerName(GetOwningPlayer(u))
 local integer i = 1
 local integer array st
 local string array hero_item
 local integer array abl_lvl
 local string array utcode
 local integer lvl = GetHeroLevel(u)
 local integer loop_through = 0
 local integer actalvl
    call BJDebugMsg("Initilized_begin == true")
    set st[0] = GetHeroAgi(u, false)
    set st[1] = GetHeroStr(u, false)
    set st[2] = GetHeroInt(u, false)
    loop
        exitwhen i > 5
            set hero_item[i] = I2S(GetItemTypeId(UnitItemInSlot(u, i)))
            call StoreString(udg_Game_Cache, "players", "item"+I2S(i), hero_item[i])
            set i = i + 1
    endloop
    set abl_lvl[0] = GetUnitAbilityLevel(u, 'A01H')
    set utcode[0] = "H002"
    set abl_lvl[1] = GetUnitAbilityLevel(u, 'A01E')
    set utcode[1] = "N00R"
    set abl_lvl[2] = GetUnitAbilityLevel(u, 'A013')
    set utcode[2] = "E003"
    set abl_lvl[3] = GetUnitAbilityLevel(u, 'A01F')
    set utcode[3] = "H001"
    set abl_lvl[4] = GetUnitAbilityLevel(u, 'A01G')
    set utcode[4] = "N00U"
    set abl_lvl[5] = GetUnitAbilityLevel(u, 'A014')
    set utcode[5] = "N01J"
    set i = 0
    loop
        exitwhen i > 5
            if I2S(GetUnitTypeId(u)) == utcode[i] then
                set actalvl = abl_lvl[i]
                call StoreString(udg_Game_Cache, "player", "abl_lvl", I2S(actalvl))
                set abl_lvl[i] = S2I("")
            endif
    endloop
               
    call StoreUnit(udg_Game_Cache, "player", s, u)
    call StoreInteger(udg_Game_Cache, "player", "x", x-1)
    call StoreInteger(udg_Game_Cache, "player", "lvl", lvl)
    call StoreInteger(udg_Game_Cache, "player", "att", st[0])
    call StoreInteger(udg_Game_Cache, "player", "str", st[1])
    call StoreInteger(udg_Game_Cache, "player", "mag", st[2])
    call StoreString(udg_Game_Cache, "player", "s", s)
    call TimerStart(t, 5, false, function Func_1)
    set udg_TimerWind[x] = CreateTimerDialogBJ(t, pn + "'s Revive")
    call ShowUnitHide(udg_Backpack_Unit[x])
    set t = null
    call RemoveUnit(u)
    set u = null
    set s = ""
    set pn = ""
    set i = S2I("")
    loop
        exitwhen loop_through > 1
            set st[loop_through] = S2I("")
    endloop
    set loop_through = 1
    loop
       exitwhen loop_through > 5
           set hero_item[loop_through] = ""
    endloop
    set loop_through = 1
    loop
        exitwhen loop_through > 4
            set abl_lvl[loop_through] = S2I("")
            set utcode[loop_through] = ""
    endloop
    set lvl = S2I("")
    set loop_through = S2I("")
    set x = S2I("") //(Does this null the variable ?)
    set actalvl = S2I("")
    call BJDebugMsg("Initilized_end == true")  
endfunction

//===========================================================================
function InitTrig_Reviving_Heroes takes nothing returns nothing
    set gg_trg_Reviving_Heroes = CreateTrigger(  )
    call TriggerAddCondition(gg_trg_Reviving_Heroes,Condition(function Revive_Func0X20))
    call TriggerAddAction( gg_trg_Reviving_Heroes, function Revive )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Reviving_Heroes, EVENT_PLAYER_UNIT_DEATH)
endfunction


PS, it doesn't work (did before) my debug msg doesn't show
02-08-2007, 12:04 PM#2
Vexorian
hmmm there was no need for a new thread, I kind of answered everything in the other one, so let me close this one.