• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

How to set level as "number"

Status
Not open for further replies.
Level 29
Joined
Sep 26, 2009
Messages
2,595
I think this question has already been asked on this forum many times, so searching the forums may have given you some insights.
Anyway, you can work with something like this:
  • Set Level
    • Events
      • Player - Player 1 (Red) types a chat message containing -lvl as A substring
    • Conditions
      • (Length of (Entered chat string)) Greater than 6
      • (Length of (Entered chat string)) Less than or equal to 7
      • (Substring((Entered chat string), 1, 5)) Equal to -lvl
    • Actions
      • Set VariableSet Level = (Integer((Substring((Entered chat string), 6, (Length of (Entered chat string))))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Level Equal to 0
        • Then - Actions
          • Game - Display to (Player group((Triggering player))) the text: Invalid value for c...
          • Skip remaining actions
        • Else - Actions
      • Set VariableSet Level = (Min((Max(1, Level)), 10))
      • Hero - Set Your_Hero Hero-level to Level, Show level-up graphics
  • You check that the text player entered contains '-lvl ' (including the empty space behind)
  • But that means the trigger would fire for example when player writes into chat something like 'abcdef -lvl xxx yyy'. Hence the conditions
  • The conditions check that
    • the string length is 6 or 7 characters (5 length for '-lvl ' + 1 or 2 characters representing the number)
    • check that the start of string is '-lvl '
  • The actions convert the 6 and 7 character into integer number
  • The if/then/else checks that the conversion was successful (e.g. this avoid issues if player entered string '-lvl AB')
  • The min/max functions are used to clamp the level number between 1 and 10 (i.e. if you enter '-lvl 99', it will not give level 99 but level 10. Same for entering '-lvl -5' which will give level 1)
You can add the same event into this trigger for the remaining player, but you will need to determine on your own which hero you should give the level to.
For example if in your map a player can only have a single hero, you can store those heroes in an array, where the array index corresponds to player's number.
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
You can simplify the trigger to this:
  • Set Level
    • Events
      • Player - Player 1 (Red) types a chat message containing -lvl as A substring
    • Conditions
    • Actions
      • Set VariableSet NewLevel = (Integer((Substring((Entered chat string), 5, (Length of (Entered chat string))))))
      • Hero - Set Your_Hero Hero-level to NewLevel, Show level-up graphics
Nichilus added some nice features to avoid potential issues, but those aren't necessarily required for it to work.

The idea is simple, the player types "-lvl 5" for example. The (Entered chat string) is set to "-lvl 5". We then use the Substring() function to find the 5th -> Last character in that chat string, which means everything after the word "-lvl". We then convert those last few characters into an Integer (NewLevel) and Set our Hero level to NewLevel. If the user didn't type any Integers after -lvl then it will fail to work.
 
Last edited:
Status
Not open for further replies.
Top