[Trigger] Change Unit Model by GUI

Status
Not open for further replies.

deepstrasz

Map Reviewer
Level 75
Joined
Jun 4, 2009
Messages
20,215
Now (at least in 1.35) we have "Skins" though, so you can use that action but it's a bit tricky.
I tried converting unit types to strings and then integers since Skins are integers but it doesn't work. The integer value becomes 0.
So, the best way for now is creating and removing (not before changing the skin!)/hiding units and setting them as unit variables.
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Trigger - Run Set Unit Type Skins <gen> (checking conditions)
  • Set Unit Type Skins
    • Events
    • Conditions
    • Actions
      • Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
      • Unit - Hide (Last created unit)
      • Set VariableSet PseudoFootmanUnit = (Last created unit)
      • Unit - Create 1 Knight for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
      • Unit - Hide (Last created unit)
      • Set VariableSet PseudoKnightUnit = (Last created unit)
      • Unit - Create 1 Dragonhawk Rider for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
      • Unit - Hide (Last created unit)
      • Set VariableSet PseudoDragonhawkUnit = (Last created unit)
  • Set Desired Unit Skin
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Unit - Set Unit Skin of Peasant 0001 <gen> to (Skin ID of PseudoFootmanUnit)
      • Game - Display to (All players) the text: (String((Skin ID of Peasant 0001 <gen>)))
      • Unit - Remove PseudoFootmanUnit from the game (OPTIONAL)
      • Wait 1.00 seconds
      • Unit - Set Unit Skin of Peasant 0001 <gen> to (Skin ID of PseudoKnightUnit)
      • Game - Display to (All players) the text: (String((Skin ID of Peasant 0001 <gen>)))
      • Unit - Remove PseudoKnightUnit from the game (OPTIONAL)
      • Wait 1.00 seconds
      • Unit - Set Unit Skin of Peasant 0001 <gen> to (Skin ID of PseudoDragonhawkUnit)
      • Game - Display to (All players) the text: (String((Skin ID of Peasant 0001 <gen>)))
      • Unit - Remove PseudoDragonhawkUnit from the game (OPTIONAL)
      • Wait 1.00 seconds
      • Trigger - Run (This trigger) (checking conditions)
I have not tested with custom models/skins. I presume they might work since the Skin changes according to the model set in the object editor.
As you noticed, the Footman's model was changed to a spider, the Knight's to a kobold and the Dragonhawk's to a red dragon. The game text appearing as numbers are the Skins (integers) converted to text.

The advantages of this means is that you don't have to make object editor adjustments to custom units (projectile, attack range etc.) like with morph abilities and there is no pause between changing models/skins like with morph abilities.

EDIT: since creating units is point dependent, you should clear the leaks. Set a point variable and then remove the location with the specific custom script command. Or, you can make a dummy building that trains units instead of creating units via trigger but then you have to add/remove unit types for the building since a building can only contain so many units.
 

Attachments

  • UnitSkinChange.w3m
    18.1 KB · Views: 14
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
I'd argue that the best way is to just rely on the working Custom Script:
  • Set Variable SkinUnit = Your unit that you want to change
  • Custom script: call BlzSetUnitSkin(udg_SkinUnit, 'Hamg')
I know Custom Script can scare people off but you can always Convert your trigger to custom text to see what the Skin function looks like in code form if you forget.

Then go into the Object Editor, press Control + D to switch to Rawcode mode, and you'll see all of the rawcodes for your Units. Hamg = Human Archmage.
 

deepstrasz

Map Reviewer
Level 75
Joined
Jun 4, 2009
Messages
20,215
Alright, so, I wanted to make it the Uncle way but for some reason I get syntax errors. I enabled all the stuff under JassHelper, even tried each one solo. What am I doing wrong?

  • Set Unit Variable
    • Events
    • Conditions
    • Actions
      • Set VariableSet SkinUnit = Peasant 0001 <gen>
  • Set Desired Unit Skin
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Custom script: Custom script: call BlzSetUnitSkin(udg_SkinUnit, 'hfoo')
      • Game - Display to (All players) the text: (String((Skin ID of SkinUnit)))
      • Wait 1.00 seconds
      • Custom script: Custom script: call BlzSetUnitSkin(udg_SkinUnit, 'hkni')
      • Game - Display to (All players) the text: (String((Skin ID of SkinUnit)))
      • Wait 1.00 seconds
      • Custom script: Custom script: call BlzSetUnitSkin(udg_SkinUnit, 'hdhw')
      • Game - Display to (All players) the text: (String((Skin ID of SkinUnit)))
      • Wait 1.00 seconds
      • Custom script: Custom script: call BlzSetUnitSkin(udg_SkinUnit, 'H000:Hpal')
      • Game - Display to (All players) the text: (String((Skin ID of SkinUnit)))
      • Wait 1.00 seconds
      • Trigger - Run (This trigger) (checking conditions)
 

deepstrasz

Map Reviewer
Level 75
Joined
Jun 4, 2009
Messages
20,215
Man... I'm so stupid. I copied "custom script" as text inside the custom script action.
Thanks @Planetary I realized it when I read your custom script actions.

One thing to note. When you make a custom unit, the new code will be [new code]+:and the original copied (base unit) code. So for instance the Paladin is Hpal but if you make a custom unit of it you will get something like H000:Hpal. When you use the custom script, you don't write all that but only H000.
 

Attachments

  • UnitSkinChange.w3m
    17.8 KB · Views: 12

deepstrasz

Map Reviewer
Level 75
Joined
Jun 4, 2009
Messages
20,215
When using BlzSetUnitSkin() the units shadow is initially removed. At least in classic. The shadow is returned after a unit is killed and revived or after being morphed back and forth from another unit/model (for example being hexed) which reduces its usefulness. I havnt found a non-intrusive way to restore the shadow.
If it has anything to do with the shadow size, maybe these could help:
1676499294395.png
Or maybe this does the trick:
1676499350761.png
 

deepstrasz

Map Reviewer
Level 75
Joined
Jun 4, 2009
Messages
20,215
FYI: You can make a unit-type GUI-variable and use it instead of the unit-raw-codes if you'd like. Makes it slightly more GUI
Tried converting the unit types to strings and then to integers. I did not find a way to convert unit types to integers directly since skins are integers.
An example please.
 
Level 24
Joined
Feb 27, 2019
Messages
833
If it has anything to do with the shadow size, maybe these could help:
Or maybe this does the trick:
I tried these but not too surprisingly when it comes to some of these new functions they did nothing.

For anyone thats interested, heres a small update. I managed to find a sufficient way to restore the shadows of units that have changed skin. It affects orders as a pseudo non-interruptable instant ability would, meaning it doesnt interrupt orders but it interrupts channeled abilities and attack animations and its slower because it requires a timer started at 0.01 instead of 0.00 which causes a slight stutter. I doubt its possible to use this technique for spell immune units or units with spell shield.
  • Restore Shadow 1
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Custom script: call BlzSetUnitSkin(gg_unit_hfoo_0001, 'hkni')
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Footman 0001 <gen> is in Shadow_Group.) Equal to False
        • Then - Actions
          • Custom script: call BlzPauseUnitEx(gg_unit_hfoo_0001, true)
          • Unit Group - Add Footman 0001 <gen> to Shadow_Group
        • Else - Actions
      • Unit - Order Dummy 0004 <gen> to Orc Shadow Hunter - Hex Footman 0001 <gen>
      • Countdown Timer - Start Shadow_Timer as a One-shot timer that will expire in 0.01 seconds
  • Restore Shadow 2
    • Events
      • Time - Shadow_Timer expires
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Shadow_Group and do (Actions)
        • Loop - Actions
          • Unit - Remove Hex buff from (Picked unit)
          • Custom script: call BlzPauseUnitEx(GetEnumUnit(), false)
          • Unit Group - Remove (Picked unit) from Shadow_Group.
 
Status
Not open for further replies.
Top