1. Find your way through the deepest dungeon in the 18th Mini Mapping Contest Poll.
    Dismiss Notice
  2. A brave new world lies beyond the seven seas. Join the 34th Modeling Contest today!
    Dismiss Notice
  3. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
Hive 3 Remoosed BETA - NOW LIVE. Go check it out at BETA Hive Workshop! Post your feedback in this new forum BETA Feedback.
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Custom doodad variations

Discussion in 'General Mapping Tutorials' started by WaterKnight, Nov 15, 2011.

  1. WaterKnight

    WaterKnight

    Joined:
    Aug 18, 2009
    Messages:
    4,035
    Resources:
    5
    Maps:
    1
    Tutorials:
    4
    Resources:
    5

    Introduction


    This is a short tutorial that should allow to apply own variation sets to doodads. The here displayed method requires the nowadays widely spread Jass NewGen Pack.

    Exposition


    Variation sets in object editor are defined by having the field Art - Variations (dvar) set to >1. Additional coloration fields will spawn but you can only state one model. If you take a look at other doodads with variations, you will recognize that a click on Art - Model (dfil) does not display anything in the preview window. That's because there really is no model placed on this path but when searching for single variations, it attachs number suffixes. Assumed that the specified path is Folder\FileName, then the first variation is on Folder\FileName0, second on Folder\FileName1, third one on Folder\FileName2 and so forth.

    Now, what is the problem? If you imported your models to Plant0.mdx, Plant1.mdx and Plant2.mdx, according to above logic, you would enter Plant as model in doodad editor. The editor disapproves of this though! Everytime you want to edit that field, it adds .mdl to the end since the editor likes to have this format. As a consequence, it won't find the variations anymore, it probably searches for Plant.mdl0 or similar, which does not work either.

    Solution


    Since the editor does not permit it, the following method will adjust the attribute of the doodad otherwise. JNGP possesses an external tool named ObjectMerger. It has the ability to unite different object editor data, if you want to transfer stuff from one map to another for example without overwriting the existing objects there. Additionally, you can create objects directly via input lines or modify them. The used language is lua. Do not fear. I will show the needed mini script here and explain what to do. The in JNGP integrated vJass language (trigger editor) is able to call external tools like the ObjectMerger automatically. So we go to the trigger editor (F4), create a new page (CTRL+T) and convert it to jass format (>>Edit >Convert to custom text). You may delete the already present content of the lower window. Instead, we write:

    Code (vJASS):
    //! textmacro SetDoodadModel takes id, path
        //! externalblock extension=lua ObjectMerger $FILENAME$
            //! i setobjecttype("doodads")

            //! i modifyobject("$id$")

            //! i makechange(current, "dfil", "$path$")
        //! endexternalblock
    //! endtextmacro

    //! runtextmacro SetDoodadModel("D000", "Plant")


    What to do now? I should first mention that the script does not need to be run more than once actually. But maybe you want to change it later on or you would like to add more variation sets, so I would leave it. That is why I have wrapped it in a textmacro. The script gets run when the map is being saved and you won't see the changes in editor until you reload the map. Afterwards, you can comment out the runtextmacro line (simply add one more / in front) to avoid lengthened saving times.

    As you should see, the textmacro parameters are between quotation marks. At the place where Plant is currently written, the model path needs to be - like I said above without .mdl/.mdx and without variation number. Folders are specified by double backslash (\\).

    The first parameter D000 represents the id of the doodad. You can inspect it by changing to raw data display in object editor (CTRL+D), search for your desired doodad in the left list then and select the first four letters (pay attention to case sensitivity!). For custom objects it's something like D000:OOal; the colon is only a delimiter and the four letters after that indicate the original object yours was based on, not important. So only take the first four letters, D000 in that case.

    Addition for destructables


    Destructables may also have variations. The script for them is a bit altered though:

    Code (vJASS):
    //! textmacro SetDestructableModel takes id, path
        //! externalblock extension=lua ObjectMerger $FILENAME$
            //! i setobjecttype("destructables")

            //! i modifyobject("$id$")

            //! i makechange(current, "bfil", "$path$")
        //! endexternalblock
    //! endtextmacro

    //! runtextmacro SetDestructableModel("B000", "Plant")


    Concluding word


    That's all. I divagated a bit to ensure that every novice gets it right since the variation stuff does not have anything more in common with the remains and you do not need more in that direction. Those are basics however one will stumple upon sooner or later.

    An example map is attached. Open the map in JNGP, activate the runtextmacro line inside the single page in trigger editor (remove one of the slashes), save, reload the map and comment the line out again in this order.
     

    Attached Files:

  2. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,430
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Tested. Works perfectly.

    Great job, very useful tutorial. ~Approved.

    EDIT: I'm moving this to General Mapping Tutorials, let me know if you think it belongs elsewhere.
     
  3. Mechanical Man

    Mechanical Man

    Joined:
    Jan 18, 2005
    Messages:
    5,384
    Resources:
    39
    Models:
    30
    Icons:
    3
    Packs:
    1
    Maps:
    4
    Tutorials:
    1
    Resources:
    39
    It's confusing as most programming languages including JASS use // a comments, but here it seems to actually activate the commands
     
  4. Flux

    Flux

    Joined:
    Feb 6, 2014
    Messages:
    2,333
    Resources:
    28
    Maps:
    1
    Spells:
    19
    Tutorials:
    2
    JASS:
    6
    Resources:
    28
    I think the reason for the //! is so that if JNGP is not present, the compiler will simply ignore it (since it thinks it's a comment).
     
  5. Doomcore

    Doomcore

    Joined:
    Sep 7, 2017
    Messages:
    207
    Resources:
    0
    Resources:
    0
    I did this but it corrupted my map and all it gives is just a crash. How could it be?
     
    Last edited: Oct 14, 2017
  6. SA Dashie

    SA Dashie

    Joined:
    Apr 3, 2010
    Messages:
    1,463
    Resources:
    6
    Skins:
    2
    Maps:
    2
    Spells:
    1
    Template:
    1
    Resources:
    6
    Thank you for the tutorial. I love these little things that editing more enjoyable.