• 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.

[Trigger] unit trigger

Status
Not open for further replies.
Level 5
Joined
Nov 6, 2008
Messages
150
Can i make a trigger so evertime i kill a unit will that be on the units team who have kill the killed unit can i do that and if i can so how?:confused:
plzzz HELP!
 
Level 13
Joined
May 11, 2008
Messages
1,198
  • Untitled Trigger 002
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Unit - Replace (Triggering unit) with a (Unit-type of (Triggering unit)) using The new unit's max life and mana
      • Unit - Change ownership of (Last replaced unit) to (Owner of (Killing unit)) and Change color
yeah, this works pretty good i think.
you probably want to set the conditions to check to see that triggering unit is not a hero...

if you want all the units to go to like player 1 or player 12 instead of to the killing unit player then set up an if then action and put in that condition owner of killing unit is an ally of player 1 then change ownership to player 1 else change ownership to player 12.
 
Level 5
Joined
Nov 6, 2008
Messages
150
ty that helps(=
that is i make a trigger map and so i think that cloud be fun to add something like that
 
Level 9
Joined
Apr 3, 2008
Messages
700
Na, it doesn't leak but they forgot to null two handles :O
2 locals leaks in my line of code? Where? o_O

Need_O2 said:
Day-Elven: Why did you say that RepleaceUnitBJ cause leaks ? Id like to learn if it does

Maybe I'm not true, but It seem to be one of the most the most weird BJs, that leaks 3 handles: unit, unit and item. Even if it doesn't leak, the following script isn't the most effecticient way to create a new unit and to delete the old one. So, that's what this function do:

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 (oldUnit == null) then
        set bj_lastReplacedUnit = oldUnit
        return oldUnit
    endif
    set wasHidden = IsUnitHidden(oldUnit)
    call ShowUnit(oldUnit, false)
    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
    if (unitStateMethod == bj_UNIT_STATE_METHOD_RELATIVE) then
        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
        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
    elseif (unitStateMethod == bj_UNIT_STATE_METHOD_MAXIMUM) then
        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
    endif
    call SetResourceAmount(newUnit, GetResourceAmount(oldUnit))
    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
    if wasHidden then
        call KillUnit(oldUnit)
        call RemoveUnit(oldUnit)
    else
        call RemoveUnit(oldUnit)
    endif
    set bj_lastReplacedUnit = newUnit
    return newUnit
endfunction
 
Status
Not open for further replies.
Top