retaining items when reviving non-hero units

Discussion in 'World Editor Help' started by PrisonLove, Sep 30, 2009.

  1. PrisonLove

    PrisonLove Hard Realist

    Ratings:
    +78 / 0 / -0
    EDIT: Okay so now I have a stranger problem. These triggers work, but if an item has more than one charge, it creates duplicates of that item and gives them to the dummy unit, but then the dummy unit drops them. It's bizarre and I need to know why this happens. Other than that the trigger works normally. Here are the triggers as they are now.

    This initializes the item holder dummy unit
    Trigger:
    • 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
    Trigger:
    • 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 - Create (Item-type of (Item being manipulated)) and give it to ItemHolder[(Player number of (Owner of (Triggering unit)))]
        • Item - Remove (Item being manipulated)

    **Note, I think this is where the dummy gets multiples of the same item. Don't know why though.


    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 UnitAddItemById( u2, GetItemTypeId(UnitItemInSlot(udg_ItemHolder[GetConvertedPlayerId(p)], j)) )
            call RemoveItem( UnitItemInSlot(udg_ItemHolder[GetConvertedPlayerId(p)], j) )
            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
     
  2. JuiceBox

    JuiceBox New Member

    Ratings:
    +13 / 0 / -0
    Hmm, not sure if this could work:
    Have the item(s) be transferred to a dummy once a unit dies. And when the unit revives, transfer the item(s) back. :)
     
  3. PrisonLove

    PrisonLove Hard Realist

    Ratings:
    +78 / 0 / -0
    That's exactly what's going on in these triggers.

    I need to find out why it's not working.
     
  4. JuiceBox

    JuiceBox New Member

    Ratings:
    +13 / 0 / -0
    How 'bout this one:

    Trigger 1 -
    Event:
    Every 0.01 seconds of game-time

    Action:
    Pick every unit in Playable Area and
    If - Picked unit's health percentage is less than or equal to 1%
    Then - Make unit's items undroppable
    Else - Do nothing

    Trigger 2 -
    Event:
    Unit revives

    Action:
    Make triggering unit's items droppable.

    >>>>>>>>>>>>>>>>>>

    Hmmm... could this work? :confused:
     
  5. PrisonLove

    PrisonLove Hard Realist

    Ratings:
    +78 / 0 / -0
    No it can't, because unit revives doesn't work on normal units (only works on heroes) and making the items undroppaple does nothing for my purposes anyway. Thanks for the effort though.
     
  6. JuiceBox

    JuiceBox New Member

    Ratings:
    +13 / 0 / -0
    Not sure if this is it but:
    When your picking the players in your first trigger: "Player Group - Pick every player in (All allies of Player 1 (Red)) and do (Actions)", does this include Player 1 itself? Or just the allies? :confused:

    'Cause in the world editor, whenever you test it out, you're always Player 1. Have you tried using the other players?
     
  7. PrisonLove

    PrisonLove Hard Realist

    Ratings:
    +78 / 0 / -0
    All Allies of Player 1 (Red) does in fact include Player 1. Good suggestion though, but that's not it. I personally think it has something to do with the initialization trigger, but I don't know what.
     
  8. JuiceBox

    JuiceBox New Member

    Ratings:
    +13 / 0 / -0
    Maybe it's the TempPoint being used twice right when the Map Initialization trigger is fired? Try using 2 different TempPoint.

    And...

    Just to be sure, maybe instead of using just 1 trigger, do 2.
    One making the item holder for allies of player 1 at 0.5 second of game-time.
    And one making the item holder for the enemies at 1.0 second of game-time.

    Sorry if I'm of no help at all... :(
     
  9. PrisonLove

    PrisonLove Hard Realist

    Ratings:
    +78 / 0 / -0
    Okay so I just tested it with game messages and the unit ItemHolder[] is in face created and set to a variable.

    So that means the second trigger is what isn't working. I need to find out why. Any thoughts?

    EDIT: solved some issues but found others. Look at the original post.
     
  10. JuiceBox

    JuiceBox New Member

    Ratings:
    +13 / 0 / -0
    Hmm... it's probably because of the item-type trigger. I think it's better if you just use the original item instead of creating new ones.

    I got an idea. Why not make the Item Holder pick it up? Instead of giving the items to it? So like whenever a unit dies, you move the Item Holder of it's owner to the position of that unit and make it pick up all the items. And when you create a unit, just move the Item Holder again beside that unit and give all the items back. Give the Item Holder a movement speed so it could pick up all the items. I think this should work... :T
     
  11. PrisonLove

    PrisonLove Hard Realist

    Ratings:
    +78 / 0 / -0
    Bump
     

Share This Page