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

Saving/Deleting Preplaced Units to improve Editor performance

Status
Not open for further replies.

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
This is a rather simple and possibly unnecessary idea but I figured it might be of use to someone.

I've created a small system that allows GUI users to save all of their preplaced units in the World Editor, and by that I mean save each unit's player-owner, unit-type id, x position, y position, and facing angle, inside of a text file so that the user can safely delete these preplaced units from their map and instead create them via triggers in-game. I've also added a Unit Group variable which can be used to add specific units to an ignore group which tells the system not to save them-useful for units that you don't want to delete.

You would really only want to do this once you're done placing units in your map, although it could come in handy during the development process if your loading times are a pain. I've seen a lot of maps that have 1000's of preplaced units and I imagine this could help.

The pros:
  • Improved World Editor performance.
  • Improved load times.
The cons:
  • Any other preset data like Dropped Items, % Life, % Mana, Level, Abilities, etc. won't be saved. I suppose some of these things could be added in the future if people actually wanted it.
  • Triggers that reference preplaced units won't work anymore BUT you could use the ignore unit group to get around this.
  • You'll want to have backup versions of your map with all of the units still preplaced. Don't misunderstand how this works, it can't paste the units back into the editor after saving/closing the map.
Here's the code (efficiency doesn't really matter in this case):
vJASS:
function StorePreplacedUnitsCallback takes nothing returns nothing
    local unit u = GetEnumUnit()
    local integer unitid = GetUnitTypeId(u)
    local integer id = GetPlayerId(GetOwningPlayer(u))
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local real face = GetUnitFacing(u)
    if IsUnitInGroup(u, udg_SPU_Ignore) == false then
        call Preload("call CreateUnit(Player(" + I2S(id) + "), " + I2S(unitid) + ", " + R2S(x) + ", " + R2S(y) + ", " + R2S(face) + ")")
    endif
    set u = null
endfunction

function StorePreplacedUnits takes nothing returns nothing
    local group g = GetUnitsInRectAll(GetEntireMapRect())
    call PreloadGenClear()
    call PreloadGenStart()
    call ForGroup(g, function StorePreplacedUnitsCallback)
    call PreloadGenEnd("StorePreplacedUnits.txt")
    call DestroyGroup(g)
    call DestroyGroup(udg_SPU_Ignore)
    set g = null
endfunction

HOW TO USE:
Step 1: Open your map and copy and paste the above Jass code into a new script. Then call the StorePreplacedUnits() function in one of your triggers. This function will save all of your preplaced units once it runs.

Step 2: Launch your map and allow the function to run and then quit the game. The units will have been saved in a .txt file located at: C:\Users\Profile\Documents\Warcraft III\CustomMapData. Then open this newly created StorePreplacedUnits.txt file and copy it's entire contents.

Step 3: Run the Preplaced Units Formatter.app and follow the instructions. You may have to hit Enter twice despite what the instructions say.
This app formats the save file into a usable Jass function.

Step 4: Copy the now properly formatted code and paste it into a new script. You now have access to a function that will create all of your preplaced units.

Step 5: Now you can delete any preplaced units from your map and instead create them in-game by calling the CreatePreplacedUnits() function.

---

So this is my first time "making an app" and I have no idea if you can use the attached Preplaced Units Formatter app without extra file(s) or the correct .Net framework installed. It was created as a C# Console App in Visual Studio and published using .Net Core 3.1.
 

Attachments

  • Preplaced Units Formatter.7z
    65.1 KB · Views: 13
  • Store Preplaced Units.w3m
    27.3 KB · Views: 9
Last edited:

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
This is a good concept. My recommendation would rather be to do this:

1. Save war3map as a folder.
2. Open war3map.j from that folder
3. Copy contents of function "CreateAllUnits"
4. Paste it into a function within a new custom script trigger and call that function when desired.

This won't fix the gg_unit stuff and you'll still have to prune any of those out of the pasted code (replaced by something like "local unit u"), but it will allow the items dropped/level/abilities/HP/mana to be preserved.

Edit: Actually, I think the unit/item creation portion is stored somewhere above the CreateAllUnits function, so those will need to be copied as well.

This method will also work for destructables and items.
 
Level 18
Joined
Jan 1, 2018
Messages
728

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
Status
Not open for further replies.
Top