• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

retaining items when reviving non-hero units

Status
Not open for further replies.
Level 10
Joined
Sep 29, 2006
Messages
447
In my map you control normal units (NOT HEROES) and they can buy items. I want to make it so that when your unit dies and a new one spawns for you, it has any items the old unit has when it died.

These triggers pass all items dropped on death to a dummy unit and then when a new unit is created (in the revive trigger) the items are passed to the newly created unit. The items just stay on the ground when the original unit dies and they are never passed to the dummy. Why?

This initializes the item holder dummy unit
  • random shit
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Create Item holders --------
      • Set TempPoint = (Center of DwarfItemHolderSpawn <gen>)
      • Player Group - Pick every player in (All allies of Player 1 (Red)) and do (Actions)
        • Loop - Actions
          • Unit - Create 1 Item Holder for (Picked player) at TempPoint facing 270.00 degrees
          • Set ItemHolder[(Player number of (Picked player))] = (Last created unit)
      • Custom script: call RemoveLocation(udg_TempPoint)
      • Set TempPoint = (Center of GoblinItemHolderSpawn <gen>)
      • Player Group - Pick every player in (All enemies of Player 1 (Red)) and do (Actions)
        • Loop - Actions
          • Unit - Create 1 Item Holder for (Picked player) at TempPoint facing 270.00 degrees
          • Set ItemHolder[(Player number of (Picked player))] = (Last created unit)
      • Custom script: call RemoveLocation(udg_TempPoint)

This stores items to the item holder on death
  • dont drop items on death
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • ((Triggering unit) is dead) Equal to True
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Dwarven Mortar Team (Custom)
          • (Unit-type of (Triggering unit)) Equal to Goblin Mortar Team (Custom)
    • Actions
      • Hero - Give (Item being manipulated) to ItemHolder[(Player number of (Owner of (Triggering unit)))]
**Note, this works if the action is to remove the (Item being manipulated) so the conditions are not causing a problem, it has to be something with either the ItemHolder[] initialization, or with this particular action.


This revives the unit (creates a new unit) and then the loop is what gives the items back.
JASS:
function reviveConditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) == 'h004' or GetUnitTypeId(GetTriggerUnit()) == 'h005'
endfunction

function reviveActions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit u2
    local player p = GetOwningPlayer(u)
    local integer i = GetUnitTypeId(u)
    local timerdialog w
    local timer t = CreateTimer()
    local location l
    local real r = 8.00
    local integer j = 1
    call TimerStart(t, r, false, null)
    call CreateTimerDialogBJ(t, GetPlayerName(p))
    set w = GetLastCreatedTimerDialogBJ()
    call TimerDialogDisplay( w, false )
    call TimerDialogDisplayForPlayerBJ(true, w, p)
    call PolledWait(r)
    if ( IsPlayerAlly(p, Player(0)) ) then
        set l = GetRandomLocInRect(gg_rct_DwarfReviveZone)
        set u2 = CreateUnitAtLoc(p, i, l, 270.00)
        call SelectUnitForPlayerSingle(u2, p)
    endif
    if ( IsPlayerEnemy(p, Player(0)) ) then
        set l = GetRandomLocInRect(gg_rct_GoblinReviveZone)
        set u2 = CreateUnitAtLoc(p, i, l, 270.00)
        call SelectUnitForPlayerSingle(u2, p)
    endif
    loop
        exitwhen j == 4
        call UnitRemoveItemFromSlot( udg_ItemHolder[GetConvertedPlayerId(p)], j )
        call UnitAddItem( u2, GetLastRemovedItem() )
        set j = j + 1
    endloop
    call PanCameraToTimedLocForPlayer(p,l,0.60)
    call DestroyTimerDialog(w)
    call RemoveLocation(l)
    set u = null
    set u2 = null
    set t = null
endfunction

//===========================================================================
function InitTrig_revive takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( t, Condition( function reviveConditions ) )
    call TriggerAddAction( t, function reviveActions )
endfunction
 
Level 4
Joined
Apr 16, 2009
Messages
85
i wouldn't do it with a dummy (as it can only hold 6 items and all the others would be lost) just remove the item and save its id in an array when you then spawn a unit just recreate it and give it to the unit
 
Level 6
Joined
Oct 31, 2008
Messages
229
why dnt you try it with hashtables, were with 1 is the unit and 2 to 7 are the items
The code is like:
When unit dies
unit not equal to hero,
save the unit and his items, create a same unit, and give back items
 
Level 6
Joined
Oct 31, 2008
Messages
229
well... you need 7 udg since u use triggers
one for the unit
and one array of six for the items
and an integer also
And you make it like a stack, means that you get in top the unit that is about to resurrect first and when you rez it, you move the next in top and so on.
I cant write the trigger right now since i don't have an editor, but i think it will help you.
 
Status
Not open for further replies.
Top