• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Respawn system not working for the 99th time

Status
Not open for further replies.
Level 19
Joined
Aug 8, 2007
Messages
2,765
First of all, why doesn't the init work

2nd, it prints "successful" but not the 2nd print and the units dont respawn

JASS:
library Respawning

globals
    hashtable RespawnTable
endglobals
function IsNeutralHostile takes nothing returns boolean
    return ( GetOwningPlayer(GetFilterUnit()) == Player(PLAYER_NEUTRAL_AGGRESSIVE) )
endfunction

function Trig_Respawn_Copy_Func006Func003C takes nothing returns boolean
    return true
endfunction

function IsBoss takes unit u returns boolean
    if ( ( GetUnitTypeId(u) == 'nhef' ) ) then
        return true
    endif
    if ( ( GetUnitTypeId(u) == 'hspt' ) ) then
        return true
    endif
    if ( ( GetUnitTypeId(u) == 'hmpr' ) ) then
        return true
    endif
    return false
endfunction

function RespawnActions takes nothing returns nothing
    local unit Dying = GetDyingUnit()
    local integer UData = GetUnitUserData(Dying)
    local integer DyingHandle = GetHandleId(Dying)
    local integer xCord =  LoadInteger(RespawnTable, DyingHandle, 0)
    local integer yCord =  LoadInteger(RespawnTable, DyingHandle, 1)
    local real facing = GetUnitFacing(Dying)
    if IsBoss(Dying) then
 //       call  TriggerSleepAction(30)
        call CreateUnitAtLoc(GetOwningPlayer(Dying), GetUnitTypeId(Dying), Location(xCord, yCord), facing)
    else
 //       call TriggerSleepAction(15)
        call CreateUnitAtLoc(GetOwningPlayer(Dying), GetUnitTypeId(Dying), Location(xCord, yCord), facing)
    endif
    set Dying = null
endfunction
function SetHashtableData takes nothing returns nothing
    local unit Enum = GetEnumUnit()
    local integer EnumData = GetHandleId(Enum)
    local location l = GetUnitLoc(Enum)
    call SaveReal(RespawnTable,EnumData, 0,GetLocationX(l))
    call SaveReal(RespawnTable,EnumData, 1,GetLocationY(l))
    call SaveReal(RespawnTable,EnumData, 2,GetUnitFacing(Enum))
    set Enum = null
    call RemoveLocation(l)
    call print("Unit Data Set for " + I2S(EnumData) + " Unit")
endfunction

function FormHashtables takes nothing returns nothing
    local group getUnitspp = GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function IsNeutralHostile))
    call ForGroupBJ(getUnitspp, function SetHashtableData )
    set getUnitspp = null
endfunction
//===========================================================================
function StartRespawnTables takes nothing returns nothing
    local trigger t = CreateTrigger()
    set gg_trg_Respawn_Copy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Respawn_Copy, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Respawn_Copy, function IsNeutralHostile )
    call TriggerAddAction( gg_trg_Respawn_Copy, function RespawnActions )   
    call TriggerAddAction(t, function FormHashtables )
    call print("Successful!")
    set t = null
endfunction

endlibrary
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
hashtables still return 0

JASS:
library Respawning initializer StartRespawnTables

globals
    hashtable RespawnTable = InitHashtable()
endglobals
function IsNeutralHostile takes nothing returns boolean
    return ( GetOwningPlayer(GetFilterUnit()) == Player(PLAYER_NEUTRAL_AGGRESSIVE) )
endfunction

function Trig_Respawn_Copy_Func006Func003C takes nothing returns boolean
    return true
endfunction

function IsBoss takes unit u returns boolean
    if ( ( GetUnitTypeId(u) == 'nhef' ) ) then
        return true
    endif
    if ( ( GetUnitTypeId(u) == 'hspt' ) ) then
        return true
    endif
    if ( ( GetUnitTypeId(u) == 'hmpr' ) ) then
        return true
    endif
    return false
endfunction

function RespawnActions takes nothing returns nothing
    local unit Dying = GetDyingUnit()
    local integer UData = GetUnitUserData(Dying)
    local integer DyingHandle = GetHandleId(Dying)
    local integer FreshHandle
    local integer xCord =  LoadInteger(RespawnTable, DyingHandle, 0)
    local integer yCord =  LoadInteger(RespawnTable, DyingHandle, 1)
    local real facing = LoadInteger(RespawnTable, DyingHandle, 2)
    local integer newHandleData
    call print("Dying unit is" + I2S(GetHandleId(Dying)) + " While Dying Handle is " + I2S(DyingHandle) + " And Data is "  +  I2S(UData))
    call print("xCord is " + I2S(xCord) + " While yCord is " + I2S(yCord))
    if IsBoss(Dying) then
 //       call  TriggerSleepAction(30)
        call CreateUnitAtLoc(GetOwningPlayer(Dying), GetUnitTypeId(Dying), Location(xCord, yCord), facing)
        set FreshHandle = GetHandleId(GetLastCreatedUnit())
        call SaveReal(RespawnTable,FreshHandle, 0, xCord)
        call SaveReal(RespawnTable,FreshHandle, 1, yCord)
        call SaveReal(RespawnTable,FreshHandle, 2, facing)
        call FlushChildHashtable(RespawnTable, DyingHandle )
    else
 //       call TriggerSleepAction(15)
        call CreateUnitAtLoc(GetOwningPlayer(Dying), GetUnitTypeId(Dying), Location(xCord, yCord), facing)
        set FreshHandle = GetHandleId(GetLastCreatedUnit())
        call SaveReal(RespawnTable,FreshHandle, 0, xCord)
        call SaveReal(RespawnTable,FreshHandle, 1, yCord)
        call SaveReal(RespawnTable,FreshHandle, 2, facing)
        call FlushChildHashtable(RespawnTable, DyingHandle )
    endif
    set Dying = null
endfunction
function SetHashtableData takes nothing returns nothing
    local unit Enum = GetEnumUnit()
    local integer EnumData = GetHandleId(Enum)
    local location l = GetUnitLoc(Enum)
    call SaveReal(RespawnTable,EnumData, 0,GetLocationX(l))
    call print("X is " + R2S(LoadReal(RespawnTable, EnumData, 0)))
    call SaveReal(RespawnTable,EnumData, 1,GetLocationY(l))
    call print("Y is " + R2S(LoadReal(RespawnTable, EnumData, 1)))
    call SaveReal(RespawnTable,EnumData, 2,GetUnitFacing(Enum))
    call print("Z is " + R2S(LoadReal(RespawnTable, EnumData, 2)))
    call print("Unit Data Set for " + I2S(EnumData) + " Unit at X " + R2S(GetLocationX(l)) + " And Y " + R2S(GetLocationY(l)))
    set Enum = null
    call RemoveLocation(l)
endfunction

function FormHashtables takes nothing returns nothing
    local group getUnits = GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function IsNeutralHostile))
    call ForGroupBJ(getUnits, function SetHashtableData )
    set getUnits = null
endfunction
//===========================================================================
function StartRespawnTables takes nothing returns nothing
    set gg_trg_Respawn_Copy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Respawn_Copy, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Respawn_Copy, function IsNeutralHostile )
    call TriggerAddAction( gg_trg_Respawn_Copy, function RespawnActions )  
    call FormHashtables()
    call print("Successful!")
endfunction

endlibrary
 
Status
Not open for further replies.
Top