• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Changing global unit ID of preplaced units?

Status
Not open for further replies.
Level 14
Joined
Apr 20, 2009
Messages
1,543
I want to know if it is possible to change the global unit ID's of preplaced units.

For example:

I want to create a loop in jass that goes through preplaced unit 1-4
however the unit ID's look somewhat like this:

Preplaced Unit 0001 <gen> (gg_unit_RAWC_0001)
Preplaced Unit 0003 <gen> (gg_unit_RAWC_0003)
Preplaced Unit 0004 <gen> (gg_unit_RAWC_0004)
Preplaced Unit 0012 <gen> (gg_unit_RAWC_0012)

How can I eithor create a loop that doesn't have unnessecary itterations or (preferrably) change the unit ID's of these units to count from 1-4 instead?
(I don't want to recreate them because I got quite a lot of them ๏_๏)
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
You can open the map with an MPQ-editor and open the file "war3map.j".
There should be a globals block with these values:
JASS:
unit                    gg_unit_RAWC_0000          = null
unit                    gg_unit_RAWC_0003          = null
unit                    gg_unit_RAWC_0004          = null
unit                    gg_unit_RAWC_0012          = null
Change those to your preferred values.

Then there should be a function called "CreateUnitsForPlayerX" (where X is the player number).
- If you never use those units in GUI, then it should just say "set u = CreateUnit(...)" for all your units.
- If you do used them in GUI, it should say "set gg_unit_RAWC_XXXX = CreateUnit(...)".
Change either the "u" or the "gg_unit_RAWC_XXXX" to the values you used above.

Every other reference to those units should be changed as well.

Edit: I forgot to mention that you need to save the newly created war3map.j somewhere and then replace it with the one in the MPQ.
Endedit

Note that if you use this method, the values will reset each time you open the map in the world editor. Meaning the values you chose previously will be unknown.
The map will work as long as you don't save/change anything though :D

If that's the only thing needed to finish your map, you're done.
Otherwise: better wait and finish the rest first :|
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
You can open the map with an MPQ-editor and open the file "war3map.j".
There should be a globals block with these values:
JASS:
unit                    gg_unit_RAWC_0000          = null
unit                    gg_unit_RAWC_0003          = null
unit                    gg_unit_RAWC_0004          = null
unit                    gg_unit_RAWC_0012          = null
Change those to your preferred values.

Then there should be a function called "CreateUnitsForPlayerX" (where X is the player number).
- If you never use those units in GUI, then it should just say "set u = CreateUnit(...)" for all your units.
- If you do used them in GUI, it should say "set gg_unit_RAWC_XXXX = CreateUnit(...)".
Change either the "u" or the "gg_unit_RAWC_XXXX" to the values you used above.

Every other reference to those units should be changed as well.

Edit: I forgot to mention that you need to save the newly created war3map.j somewhere and then replace it with the one in the MPQ.
Endedit

Note that if you use this method, the values will reset each time you open the map in the world editor. Meaning the values you chose previously will be unknown.
The map will work as long as you don't save/change anything though :D

If that's the only thing needed to finish your map, you're done.
Otherwise: better wait and finish the rest first :|

I see, however I still don't know if it's a good idea to do this then. This might get quite anoying when you want to update your map in this case..
Thanks a lot for your solution though! It's extremely appreciated! +rep

Lender said:
What are your intentions?
A friend of mine is using bribe's unit indexer and created about 100 preplaced units which aren't indexed in a correct way. (they are indexed but not from 1 to 100)
He also made a GUI trigger which seems to work incredibly slow and uses 100 ifs to check if the triggering unit equals a preplaced unit (by hand).

I was thinking of recreating the trigger in vJass with a loop that goes through all the preplaced units. But for some reason the units aren't indexed in a correct way.

Ideally something like this:

JASS:
library IncreaseTalent initializer Init
    globals
        integer tempInteger = 0
    endglobals

    private function checkIfCanSpend takes nothing returns boolean
        local unit triggeringUnit = GetTriggerUnit()
        local integer i
        loop
            exitwhen i > 100
                if (triggeringUnit == gg_unit_rawc_ + i) then //need to figure out a better way of keeping 4 digits at i
                    set tempInteger = i
                    return true
                endif
    endfunction

    private function Increase takes nothing returns nothing
        
    endfunction

    private function Init takes nothing returns nothing
        local integer i
        local trigger t = CreateTrigger()
        loop
            exitwhen i > bj_MAX_PLAYERS
                call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
            set i = i + 1
        endloop
        call TriggerAddCondition(t, Condition(function checkIfCanSpend))
        call TriggerAddAction(t, function Increase )
    endfunction
endlibrary
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Okay I found my own solution: remove every single preplaced unit in the editor and recreate them so that the ID's will follow up :p

It's gonna be a lot of work but at least it's for the greater good :)
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Actually Lender, that could've been a really good solution. I just see it now and realised it would even be easier, but I'm already done recreating the units xD.
Thanks though, I'll remember this for the future.

Now all I have to do is make sure I keep 4 digits and then use text macro's in order to refference them right?
 
Status
Not open for further replies.
Top