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

[General] Some way to change model of unit without changing the unit?

Status
Not open for further replies.
Level 12
Joined
Feb 22, 2010
Messages
1,115
Unless your unit model has an alternate animation set, you have to use some kind of transformation.
 
In init or anywhere else as setup you can make abilites permanent for your unit. Permanent abilites will stay, even when your unit uses something like bear form.

native UnitMakeAbilityPermanent takes unit whichUnit, boolean permanent, integer abilityId returns boolean

GUI friendly it would be:
  • Set unit = YourUnit
  • Set ability = YourAbility
  • Custom script: call UnitMakeAbilityPermanent(udg_unit, true, udg_ability)
 
1. Yes, you are right. It won't work with replacing unit, because the replace function creates a new unit and removes the old one.

2. ReplaceUnit function has a large overhead and should be avoided if possible, here is the "simple" replace function:
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 don't need to be able to read perfectly jass to see that here are done many operations for a seemingly simple function.
 
Last edited:
Instead of morphing here, why has nobody suggested dummy units? They work far better and don't require such.... work. If you don't want the hero icons to show then use a dummy player such as neutral extra or passive or etc. . .

Just tint the main hero to 100% transparency and don't let it attack or use abilities, while the dummy unit is the visible one doing all the work until its over.

Sure you might make unit leaks so instead of making it over and over, make like 50 dummy units to pick from at the start of the map so you only have 50 leaks instead of a chance for over that.
 
I forget where and who said it however this guy that made an anti-leak script posted how much each hero and unit and special effect leak.


I don't know If those are exact however they add up even if they look tiny. Yeah we can't clean every leak because we lack the access required to the code that is causing the issues I think. We can only reduce it as low as possible usually for objects.

Edit: That isn't a link CakeMaster.


Edit2: Found it.
http://www.hiveworkshop.com/forums/2424284-post4.html
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
I put Factory for a footprint ability on my hero, spawning a unit every 0.5 seconds and lasting 3s each. Game lasts 20 minutes or so, no lag?

Even if I create a map with pure GUI with no custom scripts and not remove any leaks it will still won't lag, especially in 20 mins.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
In WC3 there is no way to change a unit's model without changing its type. Chaos can do this permanently but any sort of attribute bonus breaks it causing gaining or loss in attributes with every application. Morphs are often not desirable as they can have effects such as immunity, timers, cast delay and probably also change the units type. This is a major short coming of WC3 as you are basically forced to use morphs.

In SC2 this is one of the easiest things you can do. In fact you have 4+ ways to do it!
1. Get unit actor to destroy on event and another unit actor to create on the same event.
2. Use event to perform model swap of actor. Some actor properties may remain which may or may not be desirable for the new model.
3. Get another actor to have both events and destroy the attached unit actor and attach a new unit actor. It may also be able to swap their model. Useful to avoid coupling a unit actor change to a unit actor.
4. Use triggers to directly destroy and create a unit actor or perform a model swap using the actor natives.
All of these methods do not alter unit type or stats in any way. They will not even interrupt the unit in any deterministic way (although they may look weird depending when it occurs).

Sad SC2 has so many easy ways to solve this problem yet WC3 cannot.
 
Sadly WC3 has one extremely easy way to solve this problem and your in the WC3 section blurting out love for SC2 however more onto topic. In WC3 there is a way to change a unit's model without changing its type, it is called exploiting dummy units. So yeah.... I am almost completely sure its easier to do here as well considering stuff. Only the people lacking knowledge are forced to do things.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
In WC3 there is a way to change a unit's model without changing its type, it is called exploiting dummy units.
This could potentially mess up targeting. It is also very inefficient. Animations are also unlikely to be fully in sync with the genuine unit animations. What happens if the unit is loaded on a transporter? What happens if the unit is hidden? What happens if the unit is subject to an explode death? What happens if a trigger changes the unit's fly height? What happens if a change in tint colour is required?

The reason no one has suggested it is because it simply will not work well and is pointlessly complicated.

I am almost completely sure its easier to do here as well considering stuff.
In SC2 I made a Thor change to an Ultralisk with every attack. It took me 2 data modifications, approximately 30 seconds (most of the time spent finding the right data elements). Good luck doing this in WC3 in less time seeing how WC3 does not even let you do this.
 
This could potentially mess up targeting. It is also very inefficient. Animations are also unlikely to be fully in sync with the genuine unit animations. What happens if the unit is loaded on a transporter? What happens if the unit is hidden? What happens if the unit is subject to an explode death? What happens if a trigger changes the unit's fly height? What happens if a change in tint colour is required?

The reason no one has suggested it is because it simply will not work well and is pointlessly complicated.


In SC2 I made a Thor change to an Ultralisk with every attack. It took me 2 data modifications, approximately 30 seconds (most of the time spent finding the right data elements). Good luck doing this in WC3 in less time seeing how WC3 does not even let you do this.

It wouldn't mess up targeting,animations,bla bla bla if you know what your doing unlike you because you haven't tried this as well you have moved onto SC2 mostly only retaining your scripting knowledge from WC3 I am sure.

"Most of the time spent finding the right data elements" is exactly the problem. WC3 does not directly support it true.

Question answered, if you want to chat more onto this please move It into VM's.
 
Status
Not open for further replies.
Top