1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[GUI] Simple Name Prefixes

Discussion in 'The Lab' started by aple, Mar 14, 2018.

  1. aple

    aple

    Joined:
    May 20, 2009
    Messages:
    807
    Resources:
    2
    Maps:
    1
    Tutorials:
    1
    Resources:
    2
    Very simple GUI triggers that makes use of the new functions to set unit names so you can have prefixes in the Object Editor. Just something that I thought would be nice to do and figured I'd share it in case it would save anyone some time making it themselves.

    Notes:
    1. All units have to have the same length for their prefixes.

    2. Use "Prefix_Identifier" to set a certain substring to check for. If a unit has this in their name at the very beginning, then they are considered to have a Prefix. If not, they are ignored entirely. This makes units without a prefix not have their names "Cropped"

    The length of this Prefix_Identifier is also considered for the length of the string, so adjust SubStart accordingly.

    3. You can adjust how long the prefixes can be by setting the "Prefix_SubStart" variable.

    I'm not really sure how else I can go about recognizing a given part of a string so that it can cut out those parts instead of having a fixed length for all prefixes.

    Suggestions and ideas to improve it are welcome. :D

    Hopefully something like this won't be needed for long and we'll get real editor prefixes akin to SC2, though.

    Here is an example of how I am setting prefixes right now with use of this:

    [​IMG]

    EDIT:

    Pretty easy to set up something new to make it so units without Prefixes are ignored. Map updated.

    EDIT 2: Here's the triggers.

    • Init Vars
      • Events
      • Conditions
      • Actions
        • Set PrefixInt[99] = 0
        • Set RemovedPrefix[99] = Peasant
        • Set Prefix_SubStart = 0
        • Set Prefix_Identifier = P!
    • Init
      • Events
        • Map initialization
      • Conditions
      • Actions
        • Unit Group - Pick every unit in (Units in (Entire map)) and do (Actions)
          • Loop - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Substring((Name of (Picked unit)), 1, (Length of Prefix_Identifier))) Equal to Prefix_Identifier
              • Then - Actions
                • Unit - Set Name of (Picked unit) to (Substring((Name of (Picked unit)), (Prefix_SubStart + (Length of Prefix_Identifier)), (Length of (Name of (Picked unit)))))
                • Unit - Set Name of (Picked unit) to (Substring((Name of (Picked unit)), (Prefix_SubStart + (Length of Prefix_Identifier)), (Length of (Name of (Picked unit)))))
                • Set PrefixInt[0] = (PrefixInt[0] + 1)
                • Set RemovedPrefix[PrefixInt[0]] = (Unit-type of (Picked unit))
              • Else - Actions
        • For each (Integer PrefixInt[10]) from 1 to PrefixInt[0], do (Actions)
          • Loop - Actions
            • Unit Group - Pick every unit in (Units of type RemovedPrefix[PrefixInt[10]]) and do (Actions)
              • Loop - Actions
                • Unit - Set Name of (Picked unit) to (Name of (Picked unit))
    • On Unit Create
      • Events
        • Unit - A unit enters (Entire map)
      • Conditions
      • Actions
        • For each (Integer PrefixInt[1]) from 1 to PrefixInt[0], do (Actions)
          • Loop - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Unit-type of (Triggering unit)) Equal to RemovedPrefix[PrefixInt[1]]
              • Then - Actions
                • Set PrefixInt[2] = 1
              • Else - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • PrefixInt[2] Equal to 0
          • Then - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Substring((Name of (Triggering unit)), 1, (Length of Prefix_Identifier))) Equal to Prefix_Identifier
              • Then - Actions
                • Unit - Set Name of (Triggering unit) to (Substring((Name of (Triggering unit)), (Prefix_SubStart + (Length of Prefix_Identifier)), (Length of (Name of (Triggering unit)))))
                • Unit - Set Name of (Triggering unit) to (Substring((Name of (Triggering unit)), (Prefix_SubStart + (Length of Prefix_Identifier)), (Length of (Name of (Triggering unit)))))
                • Set PrefixInt[0] = (PrefixInt[0] + 1)
                • Set RemovedPrefix[PrefixInt[0]] = (Unit-type of (Triggering unit))
              • Else - Actions
          • Else - Actions
            • Set PrefixInt[2] = 0

    Note: The top one of those "Set Name of Unit" actions is "Set Name" and the other is "Set Name (All)"

    You do need both of them because "Set Name (All)" doesn't appear to set the name of the Triggering Unit, just all units that will spawn in beyond the time it is set of the same unit-type.

    EDIT 3: Fixed bug where only one of each unit-type being preplaced on the map would be renamed.
     

    Attached Files:

    Last edited: Mar 15, 2018