Count characters in player name and reduce length if exceeding #

Danis[h]

New Member
Reaction score
19
Okay, so I've made a multiboard in which each player's name has to fit.. So obviously to becomes a problem with column width if the player has a very lengthy name.

So what I would like to do is to phrase the name. Or rather count up each character in the string (if possible) and then cut it off at a given number of characters..

example.. character limit for player names is set to 8
Player 5 is named "SomethingStupid" then I would like for my trigger to check his name, see that it is 15 characters long and then change it to display as
"Somethin..."

Result being that his name has been cut down in length to 8 characters with a tripple dot appended to it.


Nevermind.. the solution was very very simple..
Trigger:
  • Name Policing
    • Events
      • Map initialization
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 6, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Length of (Name of (Player((Integer A))))) Greater than 8
            • Then - Actions
              • Set NameLabel[(Integer A)] = ((Substring((Name of (Player((Integer A)))), 1, 8)) + ...)
            • Else - Actions
              • Set NameLabel[(Integer A)] = (Name of (Player((Integer A))))
 

Xorifelse

I'd love to elaborate about discussions...........
Reaction score
87
Trigger:
  • Untitled Trigger 001
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set LB_MaxLength = 8
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set TempInt = (Length of (Name of (Player((Integer A)))))
          • Set LB_Names[(Integer A)] = (Name of (Player((Integer A))))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TempInt Greater than LB_MaxLength
            • Then - Actions
              • Set LB_Names[(Integer A)] = ((Substring(LB_Names[(Integer A)], 1, LB_MaxLength)) + ...)
            • Else - Actions


This should do it, but it does not set the player names. You need a few variables but I guess you are experienced enough to know how to make them.

Edit:
Your setup works better, but I was trying to add something to the system what you didn't requested. Meaning..
For example, 8 is the maximum + 3 making it 11. If a length is 11 the name will stay intact. If it isn't it is adjusted and cut down to 8.
Just posted the code anyways.
 

Danis[h]

New Member
Reaction score
19
Trigger:
  • Untitled Trigger 001
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set LB_MaxLength = 8
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set TempInt = (Length of (Name of (Player((Integer A)))))
          • Set LB_Names[(Integer A)] = (Name of (Player((Integer A))))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TempInt Greater than LB_MaxLength
            • Then - Actions
              • Set LB_Names[(Integer A)] = ((Substring(LB_Names[(Integer A)], 1, LB_MaxLength)) + ...)
            • Else - Actions


This should do it, but it does not set the player names. You need a few variables but I guess you are experienced enough to know how to make them.

Edit:
Your setup works better, but I was trying to add something to the system what you didn't requested. Meaning..
For example, 8 is the maximum + 3 making it 11. If a length is 11 the name will stay intact. If it isn't it is adjusted and cut down to 8.
Just posted the code anyways.

Thanks for taking time to do this for me, and you're right about the 11 characters total thing. Although aesthetically I think having two people with trippe-dots by the end of their names and then one which goes to 11 without any dots will looks odd, since his letters will extend further than the rest have been allowed to.
 

Xorifelse

I'd love to elaborate about discussions...........
Reaction score
87
Thanks for taking time to do this for me, and you're right about the 11 characters total thing. Although aesthetically I think having two people with trippe-dots by the end of their names and then one which goes to 11 without any dots will looks odd, since his letters will extend further than the rest have been allowed to.
There is a system in vJass for this issue, with it you can determine the width of an entire string, instead of counting characters.

Hold on and give me a few minutes to find it, perhaps you have the ability to make a GUI version out of it, but I suggest just custom calls for it anyways.

Edit:
http://www.wc3c.net/showthread.php?t=97876&highlight=string+width
 

Danis[h]

New Member
Reaction score
19
There is a system in vJass for this issue, with it you can determine the width of an entire string, instead of counting characters.

Hold on and give me a few minutes to find it, perhaps you have the ability to make a GUI version out of it, but I suggest just custom calls for it anyways.

I am familiar enough with JASS to read and understand a system (for the most part) Although being lazy it's often easier to just use GUI. Since you don't have to type stuff.

Also, I'm making a Tower Defense. So GUI is adequate.
 

millz-

New Member
Reaction score
25
Thanks for taking time to do this for me, and you're right about the 11 characters total thing. Although aesthetically I think having two people with trippe-dots by the end of their names and then one which goes to 11 without any dots will looks odd, since his letters will extend further than the rest have been allowed to.

just change your condition to length > 11 but keep the substring 1-8, this way you would ignore people with nick 11 characters or less
(just in case you havent done this, lol)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top