• 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.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Get your art tools and paintbrushes ready and enter Hive's 34th Texturing Contest: Void! Click here to enter!

Replace Unit not Firing, What's wrong with Trigger?

Status
Not open for further replies.
Level 6
Joined
Aug 12, 2007
Messages
201
  • RockReplaceFireball
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units owned by Player 1 (Red) of type Pyrelogs) and do (Actions)
        • Loop - Actions
          • Set TempRock2 = (Picked unit)
          • Unit Group - Pick every unit in (Units within 96.00 of (Position of TempRock2)) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to Rock
                • Then - Actions
                  • Set TempReplaceRock = (Picked unit)
                  • For each (Integer A) from 0 to 4, do (Actions)
                    • Loop - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Rows[(Integer A)] contains TempReplaceRock) Equal to True
                        • Then - Actions
                          • Unit - Replace TempReplaceRock with a Rock (On Fire) using The old unit's relative life and mana
                          • Unit - Order (Last replaced unit) to Move To (Center of Spawns[(Integer A)])
                        • Else - Actions
                • Else - Actions
Whenever any rocks pass near my firepit, I want them to be replaced with Rocks (on Fire), but for some reason nothing happens, even though a similar trigger functions fine to make my creeps attack things when they come near certain objects. What part of this is preventing it from working? The Integer A is absolutely necessary because after the rock is replaced, I need to identify what row the rock is in and order it to continue down the necessary path for that row, not to have it fly off in some other direction.
 
Ok, let's clear this up:
  • RockReplaceFireball
  • Events
    • Time - Every 0.1 seconds of game-time
  • Conditions
  • Actions
    • Set Temp_Group = (Units owned by Player 1 (Red) of type Pyrelogs)
    • Unit Group - Pick up every unit in (Temp_Group) and do (Actions)
      • Loop - Actions
        • Set TempRockPoint = (Position of (Picked unit))
        • Set Temp_Group2 = (Units within 150.00 of (TempRockPoint) matching ((Unit-type of (Matching unit) Equal to Rock))
        • Unit Group - Pick every unit in (Temp_Group2) and do (Actions)
          • Loop - Actions
            • Set Temp_Rock_Point = (Position of (Picked unit))
            • For each (Integer A) from 0 to 4, do (Actions)
              • Loop - Actions
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Rows[(Integer A)] contains (Temp_Rock_Point)) Equal to True
                  • Then - Actions
                    • Unit - Replace (Picked unit) with a Rock (On Fire) using the old unit's relative life and mana
                    • Set Point1 = (Center of (Spawns[(IntegerA)])
                    • Unit - Order (Last replaced unit) to Move to (Point)
                    • Custom script: call RemoveLocation (udg_Point1)
            • Custom script: call RemoveLocation (udg_Temp_Rock_Point)
        • Custom script: call RemoveLocation (udg_TempRockPoint)
        • Custom script: call DestroyGroup (udg_Temp_Group2)
    • Custom script: call DestroyGroup (udg_Temp_Group)
I think the problem is the "Units within 96.00". 96 is way too low, it's almost the unit's position. I gave you 150.00, try that.
 
Level 6
Joined
Aug 12, 2007
Messages
201
@ Pharaoh_ It has to be low, in fact I had it as low as 64 before as if it is too high it starts to grab rocks that it isn't suppose to and convert them. And besides throwing in a bunch of variables to clean up leaks, I don't see how the trigger is different in any way that would cause it to function.

@Ciebron How is it inefficient? It does exactly what I need in a single trigger, I'd call it efficient.
 
Level 11
Joined
Apr 6, 2008
Messages
760
this is how replace unit works

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

you call that effiecent?
 
Status
Not open for further replies.
Top