• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Entered chat string converts to random item.

Status
Not open for further replies.
Level 2
Joined
Mar 24, 2013
Messages
18
Name Input system help

Hi, this is my first time posting but I have been learning and looking at this site for a while but I have a problem with a feature I want to implement.

The system would have the player enter a 6 character string. Each letter and number has a value.

Lets say a player enters : "Syous"

I want to take each letter, in this case S, Y, O, U, S and then set them to all have their own value.

S Y O U S
3, 4, 4, 0, 3

Then I want to add them all up. So it would be 14.
Then I want to add the 1 and 4 which equals 5.

From here, i would reference a chart and give that player's hero an item from that chart.

  • Player Name Value 0
  • Events
  • Player - Player 1 (Red) types a chat message containing a as A substring
  • Player - Player 1 (Red) types a chat message containing f as A substring
  • Player - Player 1 (Red) types a chat message containing k as A substring
  • Player - Player 1 (Red) types a chat message containing p as A substring
  • Player - Player 1 (Red) types a chat message containing u as A substring
  • Player - Player 1 (Red) types a chat message containing z as A substring
  • Conditions
  • Actions
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
  • If - Conditions
  • (Length of(Entered chat string)) Less than or equal to 6
  • Then - Actions
  • Set PlayerNamesCalculate[1] = (PlayerNamesCalculate[1] + 0)
  • Set PlayerNameString[1] = (Entered chat string)
  • Game - Display to (All players) the text: (String(PlayerNamesCalculate[1]))
  • Set PlayerNameEntered[1] = True
  • Trigger - Run Name Validated <gen> (checking conditions)
  • Else - Actions
  • Set PlayerNamesCalculate[1] = 0
  • Trigger - Run Enter Name Again <gen> (checking conditions)
I have 9 more triggers like this but when I do run it, if I name a character "aaaaaa" it will only set PlayerNamesCalculate[1] once instead of 6 times.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
its a lot more efficient if u have the players type in numbers but u can do something like this.

make 2 arrays one array is a string array tht u store all letters into. ( a-z) the other array has which number they correspond to.

ex: stringA[0] = A, integerA[0] = 0

now to check just use substring of entered chat 0,1 for first letter 1,2 for second letter and so on. then check each substring to get the letter it corresponds to. add them to an integer variable and there u go.
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
its a lot more efficient if u have the players type in numbers but u can do something like this.

make 2 arrays one array is a string array tht u store all letters into. ( a-z) the other array has which number they correspond to.

ex: stringA[0] = A, integerA[0] = 0

now to check just use substring of entered chat 0,1 for first letter 1,2 for second letter and so on. then check each substring to get the letter it corresponds to. add them to an integer variable and there u go.

That should do it, you saved a lot of time for me deathismyfriend. Thanks.
 
Level 2
Joined
Mar 24, 2013
Messages
18
Thanks for all the info, so does this mean I can combine all my triggers into one super trigger and do every single check in one large if/then/else statement?

like:

  • Event
  • Player - Player 1 (Red) types a chat message containing 'any letter or number' as a substring (Basically any of the letters or numbers/symbols I want)
  • Conditions
  • Actions
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
  • If - Conditions
  • Or - Any (Conditions) are true
  • Conditions
  • (Substring((Entered chat string), 0, 1)) Equal to StringNameLetter[0]
  • (Substring((Entered chat string), 1, 2)) Equal to StringNameLetter[0]
  • (Substring((Entered chat string), 2, 3)) Equal to StringNameLetter[0]
  • (Substring((Entered chat string), 3, 4)) Equal to StringNameLetter[0]
  • (Substring((Entered chat string), 4, 5)) Equal to StringNameLetter[0]
  • (Substring((Entered chat string), 5, 6)) Equal to StringNameLetter[0]
  • Then - Actions
  • Set PlayerNameCalculate[1] = (PlayerNamesCalculate[1] + 0
  • Else
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
  • If - Conditions
  • Or - Any (Conditions) are true
  • Conditions
  • (Substring((Entered chat string), 0, 1)) Equal to StringNameLetter[1]
  • (Substring((Entered chat string), 1, 2)) Equal to StringNameLetter[1]
  • (Substring((Entered chat string), 2, 3)) Equal to StringNameLetter[1]
  • (Substring((Entered chat string), 3, 4)) Equal to StringNameLetter[1]
  • (Substring((Entered chat string), 4, 5)) Equal to StringNameLetter[1]
  • (Substring((Entered chat string), 5, 6)) Equal to StringNameLetter[1]
  • Then - Actions
  • Set PlayerNameCalculate[1] = (PlayerNamesCalculate[1] + 1
Then keep repeating until I get all the letters and numbers done?

or would a for loop for all the letters in the array and another for loop for all the numbers and symbols I am using make it take alot less triggering?
 
Last edited by a moderator:
Level 2
Joined
Mar 24, 2013
Messages
18
Hey, didn't mean to double post. I however am a bit confused about how to detect what letter was entered. Is the way I described above the only way to do it? Or is there an easier way to write the trigger out?
 
Last edited:
Level 2
Joined
Mar 24, 2013
Messages
18
so I am getting confused on how to get this to work. If someone could do a trigger explanation that would help me out a ton.

Thanks.
 
Level 2
Joined
Mar 24, 2013
Messages
18
currently I want to just make it max of 6. But right now the calculation does not work. I am not sure what I should do to get it to work.
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
currently I want to just make it max of 6. But right now the calculation does not work. I am not sure what I should do to get it to work.

Ok, I'll give you the idea.

Lets say for example you typed the name "CHAOS1"

First we get the string length, in this case 6, then we enter a loop that will exit when its integer reach 6 (the string length)

Now, inside the loop we are comparing letter by letter, like C H A O S 1, and check if this letter belong to the set of letters that we defined using the table in the name generator.

So the loop will check the letter "C" by the conditions that we define then the system will return the corresponding number which in this case is 2, we save that number on a variable then check the next letter and find the corresponding number then add it to the previous integer that we saved on the variable, the sum after that will be consisting of 2 digits I guess, so in order to sum those 2 digits we need to convert that integer into a string then save each character on a separate variable using the SubString function then convert the 2 strings into and integer and add them to each other to get the final number.

Lets say the number is 24, we will convert 24 into string then substring 24 into 2 and 4 then convert them into integer again and add them to be 2 + 4 = 6

P.S. This will be done faster and better if done in JASS.
 
Level 2
Joined
Mar 24, 2013
Messages
18
thanks for explaining it a bit more. I am not good at JASS yet. I have used it but for animation things. I will try it out again. I will post if I have any luck.
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
He could check against the s econd array and just have a variable tht is a temp tht adds it as he is going also do u use jass vjass or GUI. If u use jass or vjass I might be able to give u a hand on it. If u can't get it to work. I prefer vjass so if u use tht thts great. It wouldn't take me long to write tht up for u.

The thing is that I want him to make it by himself, writing a script by yourself won't help him to learn and should be left as the last solution, unless you want to write it yourself out of fun :wink:. I would write it myself especially that its been a while since I opened the editor and my skills (or what left of it) needs refreshing but my time is short due to my conscription.
 
Level 2
Joined
Mar 24, 2013
Messages
18
Well, I got it to work yesterday sorta. The only problem I have is that the scripts are ran multiple times because the player is entering 6 letters and my event is set to player enters a message containing 'letter/number' as a substring.
 
Last edited:
Level 16
Joined
Mar 3, 2006
Messages
1,564
Well, I got it to work yesterday sorta. The only problem I have is that the scripts are ran multiple times because the player is entering 6 letters and my event is set to player enters a message containing 'letter/number' as a substring.

Are you making the player enter the name (in-game) letter by letter or type the name as a whole word ?
 
Level 2
Joined
Mar 24, 2013
Messages
18
I am having the player type the name in as a whole word but the event is whenever the player enters any letter as a substring.

here is my scripts:
this is the enter name part, the actual event is every letter is entered as a substring but I didnt want to show it cause it is a waste of space

2rxg10z.jpg


this one is the calculation part:

2cgkaza.jpg


Hopefully those uploads worked.
 
Level 2
Joined
Mar 24, 2013
Messages
18
I have events but there are like 42 of them. They are all "Player - Player 1 (Red) types a chat message containing 'letter/number' as A substring"

I however tried "Player - Player 1 (Red) types a chat message containing <Empty String> as An exact Match" and that seemed to work.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Did you get it to work?

I was bored and triggered it while watching TV.


  • Prize Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set pht = (Last created hashtable)
      • -------- -------------------------------------------------- --------
      • // You can use a loop here to add events for all players
      • Trigger - Add to Prize Convert <gen> the event (Player - Player 1 (Red) types a chat message containing <Empty String> as A substring)
      • -------- -------------------------------------------------- --------
      • Set PrizeItems[0] = Claws of Attack +15
      • Set PrizeItems[1] = Crown of Kings +5
      • Set PrizeItems[2] = Kelen's Dagger of Escape
      • Set PrizeItems[3] = Mask of Death
      • Set PrizeItems[4] = Orb of Frost
      • Set PrizeItems[5] = Ring of Protection +5
      • Set PrizeItems[6] = Horn of Cenarius
      • Set PrizeItems[7] = Keg of Thunderwater
      • Set PrizeItems[8] = Key of Three Moons
      • Set PrizeItems[9] = Frostguard
      • -------- -------------------------------------------------- --------
      • Hashtable - Save 0 as (Integer(a)) of 0 in pht
      • Hashtable - Save 0 as (Integer(f)) of 0 in pht
      • Hashtable - Save 0 as (Integer(k)) of 0 in pht
      • Hashtable - Save 0 as (Integer(p)) of 0 in pht
      • Hashtable - Save 0 as (Integer(u)) of 0 in pht
      • Hashtable - Save 0 as (Integer(z)) of 0 in pht
      • -------- -------------------------------------------------- --------
      • Hashtable - Save 1 as (Integer(b)) of 0 in pht
      • Hashtable - Save 1 as (Integer(g)) of 0 in pht
      • Hashtable - Save 1 as (Integer(l)) of 0 in pht
      • Hashtable - Save 1 as (Integer(q)) of 0 in pht
      • Hashtable - Save 1 as (Integer(v)) of 0 in pht
      • -------- -------------------------------------------------- --------
      • Hashtable - Save 2 as (Integer(c)) of 0 in pht
      • Hashtable - Save 2 as (Integer(h)) of 0 in pht
      • Hashtable - Save 2 as (Integer(m)) of 0 in pht
      • Hashtable - Save 2 as (Integer(r)) of 0 in pht
      • Hashtable - Save 2 as (Integer(w)) of 0 in pht
      • -------- -------------------------------------------------- --------
      • Hashtable - Save 3 as (Integer(d)) of 0 in pht
      • Hashtable - Save 3 as (Integer(i)) of 0 in pht
      • Hashtable - Save 3 as (Integer(n)) of 0 in pht
      • Hashtable - Save 3 as (Integer(s)) of 0 in pht
      • Hashtable - Save 3 as (Integer(x)) of 0 in pht
      • -------- -------------------------------------------------- --------
      • Hashtable - Save 4 as (Integer(e)) of 0 in pht
      • Hashtable - Save 4 as (Integer(j)) of 0 in pht
      • Hashtable - Save 4 as (Integer(o)) of 0 in pht
      • Hashtable - Save 4 as (Integer(t)) of 0 in pht
      • Hashtable - Save 4 as (Integer(y)) of 0 in pht
      • -------- -------------------------------------------------- --------
      • Hashtable - Save 5 as (Integer(0)) of 0 in pht
      • Hashtable - Save 5 as (Integer(5)) of 0 in pht
      • Hashtable - Save 5 as (Integer(1)) of 0 in pht
      • Hashtable - Save 5 as (Integer(.)) of 0 in pht
      • -------- -------------------------------------------------- --------
      • Hashtable - Save 6 as (Integer(1)) of 0 in pht
      • Hashtable - Save 6 as (Integer(6)) of 0 in pht
      • Hashtable - Save 6 as (Integer(2)) of 0 in pht
      • Hashtable - Save 6 as (Integer(&)) of 0 in pht
      • -------- -------------------------------------------------- --------
      • Hashtable - Save 7 as (Integer(2)) of 0 in pht
      • Hashtable - Save 7 as (Integer(7)) of 0 in pht
      • Hashtable - Save 7 as (Integer(3)) of 0 in pht
      • -------- -------------------------------------------------- --------
      • Hashtable - Save 8 as (Integer(3)) of 0 in pht
      • Hashtable - Save 8 as (Integer(8)) of 0 in pht
      • Hashtable - Save 8 as (Integer(4)) of 0 in pht
      • Hashtable - Save 8 as (Integer(-)) of 0 in pht
      • -------- -------------------------------------------------- --------
      • Hashtable - Save 9 as (Integer(4)) of 0 in pht
      • Hashtable - Save 9 as (Integer(9)) of 0 in pht
      • Hashtable - Save 9 as (Integer(5)) of 0 in pht
      • Hashtable - Save 9 as (Integer(!)) of 0 in pht
      • Hashtable - Save 9 as (Integer(?)) of 0 in pht
  • Prize Convert
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 1 to (Length of (Entered chat string)), do (Actions)
        • Loop - Actions
          • Set int = (int + (Load (Integer((Substring((Entered chat string), (Integer A), (Integer A))))) of 0 from pht))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • int Greater than 9
        • Then - Actions
          • Set int = ((Integer((Substring((String(int)), 2, 2)))) + (Integer((Substring((String(int)), 1, 1)))))
        • Else - Actions
      • Hero - Create PrizeItems[int] and give it to Blood Mage 0001 <gen>


You can flush the child hashtable for key 0 and the destroy the parent hashtable and turn off the second trigger when all units have gotten their items.

Some of the init lines are disabled, those are the ones for roman numerals.
 

Attachments

  • PrizeName.w3x
    14.4 KB · Views: 39
Level 2
Joined
Mar 24, 2013
Messages
18
hey Maker,

I tried it and I entered a few test names and the calculation is off. Typing in capcom, should give the player the 2nd prize, instead the player gets the last prize.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
I believe you should use the String ID, as "Convert string to integer" will always be 0 when dealing with letters.

Basically, instead of:
  • Hashtable - Save 0 as (Integer(a)) of 0 in pht
It should be:
  • Hashtable - Save 0 as (Key a) of 0 in pht
("Key a" is the action "Hashtable - Get String ID").
When I did that, I got the crown of kings (which is the second reward).
 
Level 2
Joined
Mar 24, 2013
Messages
18
Thanks ap0calypse,

Quick question: Should I keep the numbers as convert string to integer or change all of them to String ID?
 
Level 2
Joined
Mar 24, 2013
Messages
18
Hey,

I made them all String ID but for some reason it always makes the item in PrizeItems[0]. Not sure what is wrong, I copied the Prize Convert trigger and it still only makes the first item in the list.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
It works just fine for me.

Oh, one little note: I do believe capital letters make a difference, so I also converted it to lower-case (forgot about that).
This is what the edited trigger looks like for me:
  • Prize Convert
    • Events
    • Conditions
    • Actions
      • Set int = 0
      • For each (Integer A) from 1 to (Length of (Entered chat string)), do (Actions)
        • Loop - Actions
          • Set int = (int + (Load (Key (Substring((String((Entered chat string)) as Lower case), (Integer A), (Integer A)))) of 0 from pht))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • int Greater than 9
        • Then - Actions
          • Set int = ((Integer((Substring((String(int)), 2, 2)))) + (Integer((Substring((String(int)), 1, 1)))))
        • Else - Actions
      • Hero - Create PrizeItems[int] and give it to Blood Mage 0001 <gen>
 
Level 2
Joined
Mar 24, 2013
Messages
18
You rock ap0colypse!

I forgot to change the set int to a key ID instead of convert string to int.

Thanks again to Maker, deathismyfriend, and Starquizer. Do I just add rep to each of you guys.
 
Status
Not open for further replies.
Top