• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] (GUI) Simple Respawn system index error

Status
Not open for further replies.
Level 10
Joined
Nov 24, 2010
Messages
546
Hello everyone,

I have tried to make simple unit respawn system what remeber unit's original position (working only for placed units, I can divide units spawned during game/by spells from system).

Using Bribe's Indexing system works fine at start, but during respawn time (10 seconds) every custom value of respawning unit is set to latest killed unit.

Any ideas to improve effecienty/remove leaks/make it working would be handy.

  • RespawnAdd
    • Events
      • Time - Elapsed game time is 0.01 seconds
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Owner of (Picked unit)) Equal to Neutral Hostile
            • Then - Actions
              • Set Res_i = (Custom value of (Picked unit))
              • Set Res_p[Res_i] = (Position of (Picked unit))
              • Game - Display to (All players) the text: (String(Res_i))
            • Else - Actions

  • RespawnDie
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
    • Actions
      • Set Res_i = (Custom value of (Triggering unit))
      • Game - Display to (All players) the text: (String(Res_i))
      • Wait 10.00 seconds
      • Unit - Create 1 (Unit-type of (Triggering unit)) for Neutral Hostile at Res_p[Res_i] facing (Random real number between 0.00 and 360.00) degrees
      • Game - Display to (All players) the text: (String(Res_i))
      • Special Effect - Create a special effect attached to the origin of (Last created unit) using Abilities\Spells\NightElf\Blink\BlinkTarget.mdl
      • Special Effect - Destroy (Last created special effect)
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
  • RespawnDie
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
    • Actions
      • Wait 10.00 seconds
      • Unit - Create 1 (Unit-type of (Triggering unit)) for Neutral Hostile at Res_p[(Custom value of (Triggering unit))] facing (Random real number between 0.00 and 360.00) degrees
      • Game - Display to (All players) the text: (String((Custom value of (Triggering unit))))
      • Special Effect - Create a special effect attached to the origin of (Last created unit) using Abilities\Spells\NightElf\Blink\BlinkTarget.mdl
      • Special Effect - Destroy (Last created special effect)
 
Level 10
Joined
Nov 24, 2010
Messages
546
Thanks, work now, but custom value of respawned unit still changes to last killed unit value (something tells me that bribe's indexing won't work in this case but not sure), and since I have got most of spells and stuff based on this system I'm afraid it will corrupt them.
 
Level 11
Joined
Nov 15, 2007
Messages
781
I suspect you're running into a problem with the indexer recycling indexes of dying units. I'm sure there's a way to set it up to not recycle indexes of preplaced units, but if not you can use a hash table instead.
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
Thanks, work now, but custom value of respawned unit still changes to last killed unit value (something tells me that bribe's indexing won't work in this case but not sure), and since I have got most of spells and stuff based on this system I'm afraid it will corrupt them.

its work like sunshine :D

i use it

JASS:
function Trig_Give_Defence_to_creeps_Conditions takes nothing returns boolean
    return udg_UDexUnits[udg_UDex] != udg_Hero[GetPlayerId(GetOwningPlayer(udg_UDexUnits[udg_UDex]))+1] and IsUnitType(udg_UDexUnits[udg_UDex], UNIT_TYPE_SUMMONED)==false
endfunction

function Trig_Give_Defence_to_creeps_Actions takes nothing returns nothing
    local unit u = udg_UDexUnits[udg_UDex]
    set udg_Creep_X[udg_UDex] = GetUnitX(u) 
    set udg_Creep_Y[udg_UDex] = GetUnitY(u) 
    set u = null
endfunction

//===========================================================================
function InitTrig_Indexer_event takes nothing returns nothing
    set gg_trg_Indexer_event = CreateTrigger(  )
    call TriggerRegisterVariableEvent( gg_trg_Indexer_event, "udg_UnitIndexEvent", EQUAL, 1.00 )
    call TriggerAddCondition( gg_trg_Indexer_event, Condition( function Trig_Give_Defence_to_creeps_Conditions ) )
    call TriggerAddAction( gg_trg_Indexer_event, function Trig_Give_Defence_to_creeps_Actions )
endfunction

(dont see my function name :D i forget to change that)

JASS:
function Trig_Respawn_Actions takes nothing returns nothing
    local unit du = GetDyingUnit()
    local unit u = GetKillingUnit()
    local integer dutype = GetUnitTypeId(du)
    local player duplayer = GetOwningPlayer(du)
    local integer ulv
    local boolean h
    local integer itnr
    local integer outit
    local integer k = GetPlayerId(GetOwningPlayer(u))+1
    local integer cv = GetUnitUserData(du)
//--------------------this part for u
    local real x = udg_Creep_X[cv]
    local real y = udg_Creep_Y[cv]
//--------------------till here
    local real x1 = GetUnitX(du)
    local real y1 = GetUnitY(du)
    local real z = GetUnitFacing(du)
    local integer exp = R2I(udg_Global_Exp[cv] * udg_Difficulty * (100+udg_Stat_Exp[k] + udg_B_Exp[GetUnitUserData(u)])/100.00)
    local item it = null
    set outit = 0

    if ( IsUnitType(du, UNIT_TYPE_HERO) == true ) then
               set ulv = GetHeroLevel(du)
               set h = true
               else
               set ulv = GetUnitLevel(du)
               set h = false
    endif
    
    if k < 10 then
          call SuspendHeroXP( udg_Hero[k], not true )
          call AddHeroXP( udg_Hero[k], exp, false )
          call FT ("+"+I2S(exp)+" exp", 1.2 , du, 200, 200, 255, 255)
          call SuspendHeroXP( udg_Hero[k], not false )
    endif
 
    if ( ( GetRandomInt(1, 100) < (1 + udg_Difficulty * 5) ) ) then
        if (GetRandomInt(1, 100) < 75 ) then
        set it =  CreateItem(udg_Item_Type[(GetRandomInt(20, 33))], x1, y1)
        else
    loop
        exitwhen outit > 0
           set itnr = GetRandomInt(100, 1000)
          if ( itnr > 549 and itnr < 600 ) then
          else
          if ( udg_Item_Lv[itnr] - 10 < ulv ) then
          if ( udg_Item_Lv[itnr] + 10 > ulv ) then
          if ( udg_Item_Lv[itnr] != 0 ) then
          if (h == true) then
             set outit = itnr
          else
          if (itnr - (itnr / 25) * 25 < 10) then
            set outit = itnr
          endif
          endif
          endif
          endif
          endif
          endif
    endloop
        set it = CreateItem(udg_Item_Type[(GetRandomInt(20, 33))], x1, y1)
        call SetItemUserData( it, (120 + k) )
        endif
    endif
    call TriggerSleepAction(GetRandomReal(25.00, 55.00))
//----------------------then here
    set du = CreateUnit(duplayer, dutype, x, y, z)
//----------------------till here
    if ( h == true ) then
     call SetHeroLevel( du, ulv, false )
    endif
   set it = null
   set du = null
   set u = null
   set duplayer = null

endfunction

//===========================================================================
function InitTrig_Respawn takes nothing returns nothing
    set gg_trg_Respawn = CreateTrigger(  )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Respawn, Player(PLAYER_NEUTRAL_AGGRESSIVE), EVENT_PLAYER_UNIT_DEATH )
    call TriggerRegisterPlayerUnitEventSimple( gg_trg_Respawn, Player(10), EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_Respawn, function Trig_Respawn_Actions )
endfunction

dont matter if the new unit got new custom value because when new created unit appear the indexer again store the x,y coord and since new unit was created to dying unit starter position its mean new unit also get same starter position than dying unit starter position

so udg_X[dying unit custom value] == udg_X[new unit custom value] thx to indexer what do the job
 
I suspect you're running into a problem with the indexer recycling indexes of dying units. I'm sure there's a way to set it up to not recycle indexes of preplaced units, but if not you can use a hash table instead.

The index doesn't get recycled for dead units. It only recycles the index once the unit is (irretrievably) removed from the game (ie. explodes, is removed or fully decays past the point of revival)
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
then location not stored well or something with that...
try that way how i did just dont forget the events in InitTrig_Respawn coz for me only neutral hostile units/and player 11 units coordinates was stored.

if u do a event where UnitIndexEvent = 1.00 then u can save there the unit position like pos[UDEX] (so unit indexer this way a nice thing) then no problem when u want respawn the creep in dying unit trigger, dont need to set unit custom value or anything, just use that variables thats all
 
Level 10
Joined
Nov 24, 2010
Messages
546
Level 17
Joined
Nov 13, 2006
Messages
1,814
i made a demo map, u just copy the 2 trigger(if ur map already have unit indexer) to ur map and its work

but i also attach the code too

this respawn the dead unit to his original position & faceing angle, same level than when he died, example if a neutral hostile hero die at lv5 then its level back him to level 5 when respawn :p

  • Set the unit coordinate
    • Events
      • Game - UnitIndexEvent becomes Equal to 1.00
    • Conditions
    • Actions
      • Custom script: local unit u = udg_UDexUnits[udg_UDex]
      • Custom script: set udg_CreepX[udg_UDex]=GetUnitX(u)
      • Custom script: set udg_CreepY[udg_UDex]=GetUnitY(u)
      • Custom script: set udg_CreepAng[udg_UDex] = GetUnitFacing(u)
      • Custom script: set u = null
  • Respawn
    • Events
      • Unit - A unit owned by Neutral Hostile Dies
    • Conditions
    • Actions
      • Custom script: local unit u = GetDyingUnit()
      • Custom script: local integer id = GetUnitTypeId(u)
      • Custom script: local integer lv = GetHeroLevel(u)
      • Custom script: local integer cv = GetUnitUserData(u)
      • Wait 5.00 seconds
      • Custom script: call RemoveUnit( u )
      • Custom script: set u = CreateUnit(GetTriggerPlayer(),id,udg_CreepX[cv],udg_CreepY[cv],udg_CreepAng[cv])
      • Custom script: if lv > 1 then
      • Custom script: call SetHeroLevel(u,lv,false)
      • Custom script: endif
      • Custom script: set u = null
 

Attachments

  • demo_respawn.w3x
    21.8 KB · Views: 52
Level 10
Joined
Nov 24, 2010
Messages
546
Do I have to copy map init too?


And this is how I set every unit type I don't want to be respawned?
  • Respawn
    • Events
      • Unit - A unit owned by Neutral Hostile Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Not equal to Footman
      • (Unit-type of (Triggering unit)) Not equal to Rifleman
    • Actions
      • Custom script: local unit u = GetDyingUnit()
      • Custom script: local integer id = GetUnitTypeId(u)
      • Custom script: local real ang = GetUnitFacing(u)
      • Custom script: local integer lv = GetHeroLevel(u)
      • Custom script: local integer cv = GetUnitUserData(u)
      • Wait 5.00 seconds
      • Custom script: set u = CreateUnit(GetTriggerPlayer(),id,udg_CreepX[cv],udg_CreepY[cv],ang)
      • Custom script: if lv > 1 then
      • Custom script: call SetHeroLevel(u,lv,false)
      • Custom script: endif
      • Custom script: set u = null
And thanks for demo map :)
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
Do I have to copy map init too?


And this is how I set every unit type I don't want to be respawned?
  • Respawn
    • Events
      • Unit - A unit owned by Neutral Hostile Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Not equal to Footman
      • (Unit-type of (Triggering unit)) Not equal to Rifleman
    • Actions
      • Custom script: local unit u = GetDyingUnit()
      • Custom script: local integer id = GetUnitTypeId(u)
      • Custom script: local real ang = GetUnitFacing(u)
      • Custom script: local integer lv = GetHeroLevel(u)
      • Custom script: local integer cv = GetUnitUserData(u)
      • Wait 5.00 seconds
      • Custom script: set u = CreateUnit(GetTriggerPlayer(),id,udg_CreepX[cv],udg_CreepY[cv],ang)
      • Custom script: if lv > 1 then
      • Custom script: call SetHeroLevel(u,lv,false)
      • Custom script: endif
      • Custom script: set u = null
And thanks for demo map :)

i guess dying unit instead trigger unit but yes, in condition u configuare as u want.

(Unit-type of (Dying unit)) Not equal to Footman
(Unit-type of (Dying unit)) Not equal to Rifleman

map init dont need, if u create manually the CreepX,CreepY and CreepAng real variable array
 
Status
Not open for further replies.
Top