• 🏆 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!

Trigger creates 2 units instead of one and doesnt give item

Status
Not open for further replies.
Level 3
Joined
Feb 27, 2011
Messages
39
I overlooked something. You can delete/lock this thread.
for reference here is the multislot replace unit trigger.
  • when unit pick up item replace multislot
  • Events
    • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Claws of Attack +15
      • (Unit-type of (Triggering unit)) Equal to Test footman
    • Actions
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • Set UnitsItems[(Integer A)] = (Item carried by (Triggering unit) in slot (Integer A))
          • Hero - Drop the item from slot (Integer A) of (Triggering unit)
      • Unit - Replace (Triggering unit) with a Mountain King using The old unit's relative life and mana
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • Hero - Give UnitsItems[(Integer A)] to (Last replaced unit)
 

Attachments

  • replace trigger testmap.w3x
    13 KB · Views: 74
Last edited:
Level 28
Joined
Jan 26, 2007
Messages
4,789
Because it's an infinite loop perhaps?

The trigger activates when a unit picks up an item.
The trigger gives the unit an item --> calls itself (to infinity).

No: only use arrays when you actually need them.
The simple solution is to use "Trigger - turn off (this trigger)" at the beginning and turn it back on after all the other actions.
 
Level 3
Joined
Feb 27, 2011
Messages
39
Yes it was an infinite loop. But the array is needed when making the trigger multislot using integer A.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Try this ?
  • Actions
    • Set Items = (Item-type of (Item being manipulated))
    • Item - Remove (Item being manipulated)
    • Unit - Replace (Triggering unit) with a Paladin using The old unit's relative life and mana
    • Hero - Create Items and give it to (Last replaced unit)
 
Level 11
Joined
Sep 12, 2008
Messages
657
You guys realise what Replace unit does right?

JASS:
function ReplaceUnitBJ takes unit whichUnit, integer newUnitId, integer unitStateMethod returns unit
    local unit    oldUnit = whichUnit
    local unit    newUnit
    local boolean wasHidden
    local integer index
    local item    indexItem
    local real    oldRatio

    // If we have bogus data, don't attempt the replace.
    if (oldUnit == null) then
        set bj_lastReplacedUnit = oldUnit
        return oldUnit
    endif

    // Hide the original unit.
    set wasHidden = IsUnitHidden(oldUnit)
    call ShowUnit(oldUnit, false)

    // Create the replacement unit.
    if (newUnitId == 'ugol') then
        set newUnit = CreateBlightedGoldmine(GetOwningPlayer(oldUnit), GetUnitX(oldUnit), GetUnitY(oldUnit), GetUnitFacing(oldUnit))
    else
        set newUnit = CreateUnit(GetOwningPlayer(oldUnit), newUnitId, GetUnitX(oldUnit), GetUnitY(oldUnit), GetUnitFacing(oldUnit))
    endif

    // Set the unit's life and mana according to the requested method.
    if (unitStateMethod == bj_UNIT_STATE_METHOD_RELATIVE) then
        // Set the replacement's current/max life ratio to that of the old unit.
        // If both units have mana, do the same for mana.
        if (GetUnitState(oldUnit, UNIT_STATE_MAX_LIFE) > 0) then
            set oldRatio = GetUnitState(oldUnit, UNIT_STATE_LIFE) / GetUnitState(oldUnit, UNIT_STATE_MAX_LIFE)
            call SetUnitState(newUnit, UNIT_STATE_LIFE, oldRatio * GetUnitState(newUnit, UNIT_STATE_MAX_LIFE))
        endif

        if (GetUnitState(oldUnit, UNIT_STATE_MAX_MANA) > 0) and (GetUnitState(newUnit, UNIT_STATE_MAX_MANA) > 0) then
            set oldRatio = GetUnitState(oldUnit, UNIT_STATE_MANA) / GetUnitState(oldUnit, UNIT_STATE_MAX_MANA)
            call SetUnitState(newUnit, UNIT_STATE_MANA, oldRatio * GetUnitState(newUnit, UNIT_STATE_MAX_MANA))
        endif
    elseif (unitStateMethod == bj_UNIT_STATE_METHOD_ABSOLUTE) then
        // Set the replacement's current life to that of the old unit.
        // If the new unit has mana, do the same for mana.
        call SetUnitState(newUnit, UNIT_STATE_LIFE, GetUnitState(oldUnit, UNIT_STATE_LIFE))
        if (GetUnitState(newUnit, UNIT_STATE_MAX_MANA) > 0) then
            call SetUnitState(newUnit, UNIT_STATE_MANA, GetUnitState(oldUnit, UNIT_STATE_MANA))
        endif
    elseif (unitStateMethod == bj_UNIT_STATE_METHOD_DEFAULTS) then
        // The newly created unit should already have default life and mana.
    elseif (unitStateMethod == bj_UNIT_STATE_METHOD_MAXIMUM) then
        // Use max life and mana.
        call SetUnitState(newUnit, UNIT_STATE_LIFE, GetUnitState(newUnit, UNIT_STATE_MAX_LIFE))
        call SetUnitState(newUnit, UNIT_STATE_MANA, GetUnitState(newUnit, UNIT_STATE_MAX_MANA))
    else
        // Unrecognized unit state method - ignore the request.
    endif

    // Mirror properties of the old unit onto the new unit.
    //call PauseUnit(newUnit, IsUnitPaused(oldUnit))
    call SetResourceAmount(newUnit, GetResourceAmount(oldUnit))

    // If both the old and new units are heroes, handle their hero info.
    if (IsUnitType(oldUnit, UNIT_TYPE_HERO) and IsUnitType(newUnit, UNIT_TYPE_HERO)) then
        call SetHeroXP(newUnit, GetHeroXP(oldUnit), false)

        set index = 0
        loop
            set indexItem = UnitItemInSlot(oldUnit, index)
            if (indexItem != null) then
                call UnitRemoveItem(oldUnit, indexItem)
                call UnitAddItem(newUnit, indexItem)
            endif

            set index = index + 1
            exitwhen index >= bj_MAX_INVENTORY
        endloop
    endif

    // Remove or kill the original unit.  It is sometimes unsafe to remove
    // hidden units, so kill the original unit if it was previously hidden.
    if wasHidden then
        call KillUnit(oldUnit)
        call RemoveUnit(oldUnit)
    else
        call RemoveUnit(oldUnit)
    endif

    set bj_lastReplacedUnit = newUnit
    return newUnit
endfunction

if you dont know jass, it will take the unit, recreate him, hidden if he was, etc.
AND take all his items, and recreate them. you dont have to take care of it, cuz it will automaticly do it.. (it should atleast)
 
Level 11
Joined
Sep 12, 2008
Messages
657
mm.. never happend to me.. ill try it out and edit..
possibly be with undropable.. if it does happend, ill post here the fixed version..

edit: didnt finish creating the undropable item in the object editor,
but a nice intresting thing showed up..
i did this:

  • Replace Hero
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • HeroNumber1 Equal to True
        • Then - Actions
          • Unit Group - Pick every unit in (Units owned by Player 1 (Red)) and do (Actions)
            • Loop - Actions
              • Unit - Replace (Picked unit) with a Paladin using The old unit's relative life and mana
          • Set HeroNumber1 = False
        • Else - Actions
          • Unit Group - Pick every unit in (Units owned by Player 1 (Red)) and do (Actions)
            • Loop - Actions
              • Unit - Replace (Picked unit) with a Archmage using The old unit's relative life and mana
          • Set HeroNumber1 = True
NOTE: i realise it leaks, i really dont care atm, its just for test purpose..

but something very odd happend, i pressed it twice or 3 times fast, it created twice the same units!..
i started with 1 unit, got 2, 2 into 4, 4 into 8, 8 into 16, and so on..
got my map full of those little bastards switching heroes every time.. it lagged like shit :p

EDIT:
fail on that, nothing bugged out there.. the item was undropable, it was still created.

http://www.hiveworkshop.com/forums/pastebin.php?id=eena1k

try it yourself =]
 
Status
Not open for further replies.
Top