Player types a chat message containing an integer

Phoenixrainn

New Member
Reaction score
2
Hey, I'm trying to create a script that allows you to type an integer in chat and it recognizes any integer.

Player - Player 1 (Red) types a chat message containing ((t + gold ) + ((Name of Player 2 (Blue)) + (String(0)))) as An exact match

What I need to say, is if a player types "t wool (any player color) (integer"

the "t" stands for "trade". Wool is going to be a custom resource just defined by a variable. The event will give any specified resource to another player.

I've looked throughout these forums and others, but I can't seem to find the answer, so I'm finally posting.

Thanks

EDIT

Would it be something like this??

Player - Player 1 (Red) types a chat message containing ((t + (Substring(gold , 7, 8))) + blue) as An exact match

So "t gold (integer) blue"
 

bOb666777

Stand against the ugly world domination face!
Reaction score
117
Would it be something like this??

Player - Player 1 (Red) types a chat message containing ((t + (Substring(gold , 7, 8))) + blue) as An exact match

So "t gold (integer) blue"

Not really
More of something like that:
Code:
Player - Player 1 (Red) types a chat message containing -t wool  as A substring

Set Wool[(Player Number of (Triggering Player))] = Wool[(Player Number of (Triggering Player))] - (Integer((Substring((Entered chat string), 12, (Lenght of (Entered Chat String))))))

Set Wool[Player(Integer((Substring((Entered chat string), 9, 11)))] = Wool[Player(Integer((Substring((Entered chat string), 9, 11)))] + (Integer((Substring((Entered chat string), 12, (Lenght of (Entered Chat String))))))
 

Phoenixrainn

New Member
Reaction score
2
I'm trying to figure out exactly what you did, but I can't seem to do it right.
I exchanged "wool" for Crop Income.

Code:
Player - Player 1 (Red) types a chat message containing -t wool as A substring
Set CropIncome[(Player number of (Triggering player))] = (CropIncome[(Player number of (Triggering player))] - (Integer((Substring((String((Integer((Entered chat string))))), 12, (Length of (Entered chat string)))))))
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Well, to make an efficient system, you should probably start out making it so that it can recognize any 'resource', any 'player color' and an 'integer'.

This makes it a bit of a complicated process... Basically, the strings are separated by spaces. The first string is "t", the second can be of varying length, since "lumber" is longer than "gold". The same is for different colors, and the integer (no one is going to put in '001' if they want to trade '1' gold).


Long story short...

Trigger:
  • Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set resources[1] = gold
      • Set resources[2] = wool
      • -------- repeat for all of your resources --------
      • Set playercolor[1] = red
      • Set playercolor[2] = blue
      • Set playercolor[3] = teal
      • -------- ........ --------
      • Set playercolor[11] = darkgreen
      • -------- repeat for all controllable players --------
      • For each (Integer A) from 1 to 3, do (Actions)
        • Loop - Actions
          • -------- Change 3 to the number of controllable players --------
          • Trigger - Add to Trade <gen> the event (Player - (Player((Integer A))) types a chat message containing t as A substring)


Trigger:
  • Trade
    • Events
    • Conditions
      • (Substring((Entered chat string), 1, 2)) Equal to t
    • Actions
      • Set tempplayer[1] = Neutral Passive
      • Set tempstring[1] = <Empty String>
      • Set tempstring[2] = <Empty String>
      • Set tempstring[3] = <Empty String>
      • Set tempint[1] = 0
      • Set tempint[2] = 0
      • Set tempint[3] = 0
      • Set tempint[4] = 0
      • -------- Now we must determine the length of the next string: --------
      • For each (Integer A) from 3 to 11, do (Actions)
        • Loop - Actions
          • -------- change the 11 to ( 2 + the length of the longeset resource string). For example, if 'gold' was the longest resource name, you should change 11 to 6. --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Substring((Entered chat string), (Integer A), (Integer A))) Equal to
            • Then - Actions
              • -------- If the word has ended, or if the string is equal to a space --------
              • Set tempstring[1] = (Substring((Entered chat string), 3, ((Integer A) - 1)))
              • Set tempint[1] = (1 + (Integer A))
            • Else - Actions
      • For each (Integer A) from 1 to 2, do (Actions)
        • Loop - Actions
          • -------- change "2" to the number of resources --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • tempstring[1] Equal to resources[(Integer A)]
            • Then - Actions
              • -------- if the entered string is *this* resource --------
              • Set tempint[2] = (Integer A)
              • -------- set a temporary integer to the index of which resource it is, for later use --------
            • Else - Actions
      • For each (Integer A) from tempint[1] to (tempint[1] + 8), do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Substring((Entered chat string), (Integer A), (Integer A))) Equal to
            • Then - Actions
              • -------- If the word has ended, or if the string is equal to a space --------
              • Set tempstring[2] = (Substring((Entered chat string), tempint[1], ((Integer A) - 1)))
              • Set tempint[3] = ((Integer A) + 1)
            • Else - Actions
      • For each (Integer A) from 1 to 11, do (Actions)
        • Loop - Actions
          • -------- change "11" to the number of players --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • tempstring[2] Equal to playercolor[(Integer A)]
            • Then - Actions
              • -------- if the entered player color is this player/color --------
              • Set tempplayer[1] = (Player((Integer A)))
              • -------- set a temporary variable to the player --------
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • tempstring[1] Equal to <Empty String>
        • Then - Actions
          • -------- invalid resource was entered --------
          • Skip remaining actions
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • tempstring[2] Equal to <Empty String>
              • tempplayer[1] Equal to Neutral Passive
        • Then - Actions
          • -------- invalid player was entered --------
          • Skip remaining actions
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • tempint[4] Equal to 0
        • Then - Actions
          • -------- invalid or zero amount was entered --------
          • Skip remaining actions
        • Else - Actions
      • Set tempint[4] = (Integer((Substring((Entered chat string), tempint[3], (Length of (Entered chat string))))))
      • -------- The Resource is tempstring[1], or resources[tempint[1]] --------
      • -------- The Player color is tempstring[2] or tempplayer[1] --------
      • -------- The amount is tempint[4] --------


At the end of the second trigger (after the comments), you can start using the listed data as the information collected from the string.

This has a little bit of testing done:

I typed in "t wool blue 4", and the output variables were:

tempstring[1]: "wool"
tempstring[2]: "blue" tempplayer[1]: Player 2 (Blue)
tempint[4]: 4

I also made it so that if a player typed in something incorrect, such as "litebloo", it would stop the function from running, so you don't end up with the incorrect player.

Good luck with your map!

EDIT: Uploaded the map with the (working) script, so you don't have to re-create it (it is rather large... :eek:)

EDIT2: I forgot to mention, that as a limitation of the script (I separated the strings by spaces), you must specify the colors of players with spaces in them (light blue, and dark green), without the spaces. When/if you set the playercolors[10] and playercolors[11], make sure to set them as "lightblue" and "darkgreen". When players type it in, they must type "t wool lightblue 4" rather than "t wool light blue 4".
 

HydraRancher

Truth begins in lies
Reaction score
197
darth, that kinda fail :p
Trigger:
  • (Substring((Entered chat string), 1, 2)) Equal to t

T is 1 character long :eek:
Trigger:
  • (Substring((Entered chat string), (Integer A), (Integer A))) Equal to

equal to what?
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
darth, that kinda fail :p
Trigger:
  • (Substring((Entered chat string), 1, 2)) Equal to t

T is 1 character long :eek:
Trigger:
  • (Substring((Entered chat string), (Integer A), (Integer A))) Equal to

equal to what?

That is "t "

and the second, is equal to " ". They're spaces. If you looked at the map I uploaded, you can see that they are included.

It's been tested, and it works. :p
 

Phoenixrainn

New Member
Reaction score
2
Code:
Init
    Events
        Map initialization
    Conditions
    Actions
        Set resources[1] = wheat
        Set resources[2] = straw
        -------- repeat for all of your resources --------
        Set playercolor[1] = red
        Set playercolor[2] = blue
        Set playercolor[3] = teal
        Set playercolor[4] = purple
        Set playercolor[5] = yellow
        Set playercolor[6] = orange
        Set playercolor[7] = green
        Set playercolor[8] = pink
        Set playercolor[9] = gray
        Set playercolor[10] = lightblue
        Set playercolor[11] = darkgreen
        Set playercolor[12] = brown
        For each (Integer A) from 1 to 12, do (Actions)
            Loop - Actions
                Trigger - Add to Trade <gen> the event (Player - (Player((Integer A))) types a chat message containing t  as A substring)

Code:
Trade
    Events
    Conditions
        (Substring((Entered chat string), 1, 2)) Equal to t 
    Actions
        Set tempplayer[1] = Neutral Passive
        Set tempstring[1] = <Empty String>
        Set tempstring[2] = <Empty String>
        Set tempstring[3] = <Empty String>
        Set tempint[1] = 0
        Set tempint[2] = 0
        Set tempint[3] = 0
        Set tempint[4] = 0
        -------- Now we must determine the length of the next string: --------
        For each (Integer A) from 3 to 13, do (Actions)
            Loop - Actions
                -------- change the 13 to ( 2 + the length of the longeset resource string).  For example, if 'gold' was the longest resource name, you should change 13 to 6. --------
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        (Substring((Entered chat string), (Integer A), (Integer A))) Equal to  
                    Then - Actions
                        -------- If the word has ended, or if the string is equal to a space --------
                        Set tempstring[1] = (Substring((Entered chat string), 3, ((Integer A) - 1)))
                        Set tempint[1] = (1 + (Integer A))
                    Else - Actions
        For each (Integer A) from 1 to 2, do (Actions)
            Loop - Actions
                -------- change "2" to the number of resources --------
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        tempstring[1] Equal to resources[(Integer A)]
                    Then - Actions
                        -------- if the entered string is *this* resource --------
                        Set tempint[2] = (Integer A)
                        -------- set a temporary integer to the index of which resource it is, for later use --------
                    Else - Actions
        For each (Integer A) from tempint[1] to (tempint[1] + 8), do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        (Substring((Entered chat string), (Integer A), (Integer A))) Equal to  
                    Then - Actions
                        -------- If the word has ended, or if the string is equal to a space --------
                        Set tempstring[2] = (Substring((Entered chat string), tempint[1], ((Integer A) - 1)))
                        Set tempint[3] = ((Integer A) + 1)
                    Else - Actions
        For each (Integer A) from 1 to 12, do (Actions)
            Loop - Actions
                -------- change "12" to the number of players --------
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        tempstring[2] Equal to playercolor[(Integer A)]
                    Then - Actions
                        -------- if the entered player color is this player/color --------
                        Set tempplayer[1] = (Player((Integer A)))
                        -------- set a temporary variable to the player --------
                    Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                tempstring[1] Equal to <Empty String>
            Then - Actions
                -------- invalid resource was entered --------
                Skip remaining actions
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                Or - Any (Conditions) are true
                    Conditions
                        tempstring[2] Equal to <Empty String>
                        tempplayer[1] Equal to Neutral Passive
            Then - Actions
                -------- invalid player was entered --------
                Skip remaining actions
            Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                tempint[4] Equal to 0
            Then - Actions
                -------- invalid or zero amount was entered --------
                Skip remaining actions
            Else - Actions
        Set tempint[4] = (Integer((Substring((Entered chat string), tempint[3], (Length of (Entered chat string))))))
        Game - Display to (All players) the text: YAY?? It works???
        -------- The Resource is tempstring[1], or resources[tempint[1]] --------
        -------- The Player color is tempstring[2] or tempplayer[1] --------
        -------- The amount is tempint[4] --------

Ok. So am working on it. Currently it doesn't work I don't think. But I think that HydraRancher had a good point about the "(Integer A), (Integer A)".
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Just copy and paste the trigger. If you do a substring from 1, 1 (using the GUI substring function), you get the very first letter. Take a look at the description of the function.

Also, you probably should just copy the trigger I posted in the map. It'd be a lot simpler!
 

Phoenixrainn

New Member
Reaction score
2
I did just copy the trigger. And then edited for the player number I have.

then within the game, I typed "t wheat blue 4" and nothing would happen. I wouldn't get my success message check.

EDIT

Should my variables all be array's of (1). Shouldn't my playercolor be an array of 12?
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Should my variables all be array's of (1). Shouldn't my playercolor be an array of 12?

This only matters for timers, timer windows, unit groups, player groups, and other things that must be created before they can be used.

Alright, I fixed it. It was a slight mistake I made in checking whether the amount was 0 before I set it. :p

I also left in the Custom Scripts which display the resource, player name, and amount, so you can get the 'success message' thing.
 

Phoenixrainn

New Member
Reaction score
2
It is working great. Thanks. What I am trying to do now is create the set variable.

Code:
-------- Remove Resources from Player --------
Set tempint[(Player number of (Triggering player))] = (tempint[(Player number of (Triggering player))] - tempint[4])

I don't think that is right though.

What I need to do is set the variable of the person typing - number given. And then give the selected resource and specificed value to the typed playercolor.

What I am ultimately trying to do is create a trade system.

So that I can give 10 wheat to a player, and he will give me 8 straw for instance. But there is going to have to be a way so that they will have to agree on the trade.

One idea is

"t wheat blue 10 straw 8"

so the first resource is give and the 2nd resource is take. And then blue would have to type the same values back in order to confirm. So ...

"t straw 8 red wheat 10"

or instead

"t red confirm"

I think that is a good way to do it, but I'm sure there are better ways.
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
It is working great. Thanks. What I am trying to do now is create the set variable.

Code:
-------- Remove Resources from Player --------
Set tempint[(Player number of (Triggering player))] = (tempint[(Player number of (Triggering player))] - tempint[4])

I don't think that is right though.

Those variables I gave you at the end are only to be used as values. Don't set the variables, because they contain information. Instead, create your own arrays of 'resources' and do something like this:

Code:
-------- Remove Resources from Player --------
Set straw[(Player number of (Triggering player))] = (straw[(Player number of (Triggering player))] - tempint[4])

What I need to do is set the variable of the person typing - number given. And then give the selected resource and specificed value to the typed playercolor.

What I am ultimately trying to do is create a trade system.

So that I can give 10 wheat to a player, and he will give me 8 straw for instance. But there is going to have to be a way so that they will have to agree on the trade.

One idea is

"t wheat blue 10 straw 8"

so the first resource is give and the 2nd resource is take. And then blue would have to type the same values back in order to confirm. So ...

"t straw 8 red wheat 10"

or instead

"t red confirm"

I think that is a good way to do it, but I'm sure there are better ways.

How about adding the variables to a *pot*, and then create a system that lets people agree or disagree on the trade. If they agree, add and subtract the amount of resources appropriately (remember to make sure each player has the minimum amount), and if they disagree, stop the 'trade'.
 

Phoenixrainn

New Member
Reaction score
2
good idea. But if I script

Code:
Set straw[(Player number of (Triggering player))] = (straw[(Player number of (Triggering player))] - tempint[4])

Won't that cause serious efficieny issues.

I currently have each of my resources set up as an integer array (12)
I need a way to refer to the written resource. I'm sure the answer is right in front of me, but it has been kind of a long day.

So instead of "Set Straw =" can't I do "Set (written resource) ="

Meaning, I would have to set up a separate trigger that says:

Set Straw (the resource) = Straw (the string)
so that if someone everytime types "straw" the game knows it is refferring specifically to straw. And not just any straw, but "Straw (Player number of (Triggering player))"
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
good idea. But if I script

Code:
Set straw[(Player number of (Triggering player))] = (straw[(Player number of (Triggering player))] - tempint[4])

Won't that cause serious efficieny issues.

You'd be surprised how much the game can handle. The operations limit is around 8,000 (before the game must 'wait' or give control up), and it is possible (in JASS) to create a periodic trigger running every 0.001 seconds (1,000 times per second).

I currently have each of my resources set up as an integer array (12)
I need a way to refer to the written resource. I'm sure the answer is right in front of me, but it has been kind of a long day.

So instead of "Set Straw =" can't I do "Set (written resource) ="

Meaning, I would have to set up a separate trigger that says:

Set Straw (the resource) = Straw (the string)
so that if someone everytime types "straw" the game knows it is refferring specifically to straw. And not just any straw, but "Straw (Player number of (Triggering player))"

There really isn't a way without 2D arrays (not supported in the GUI). Though you could take a look at a way of imitating them (we have a few tutorials).

An easy way would be to do an if-then-else.

Code:
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    If - Conditions
        tempstring[1] == "straw"
    Then - Actions
        Set straw[(Player number of (Triggering player))] = (straw[(Player number of (Triggering player))] - tempint
    Else - Actions
    -------- Repeat for all resources --------
 

Phoenixrainn

New Member
Reaction score
2
cool. getting closer.

Code:
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    If - Conditions
        And - All (Conditions) are true
            Conditions
                tempstring[1] Equal to straw
                Straw[(Player number of (Triggering player))] Greater than or equal to tempint[4]
    Then - Actions
        Game - Display to (All players) the text: (Straw:  + (String(Straw[(Player number of (Triggering player))])))
        Set Straw[(Player number of (Triggering player))] = (Straw[(Player number of (Triggering player))] - tempint[4])
        Game - Display to (All players) the text: (Straw:  + (String(Straw[(Player number of (Triggering player))])))
    Else - Actions
        Game - Display to (All players) the text: Not Enough Straw

Code:
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    If - Conditions
        And - All (Conditions) are true
            Conditions
                tempstring[1] Equal to wheat
                Wheat[(Player number of (Triggering player))] Greater than or equal to tempint[4]
    Then - Actions
        Game - Display to (All players) the text: (Wheat:  + (String(Wheat[(Player number of (Triggering player))])))
        Set Wheat[(Player number of (Triggering player))] = (Wheat[(Player number of (Triggering player))] - tempint[4])
        Game - Display to (All players) the text: (Wheat:  + (String(Wheat[(Player number of (Triggering player))])))
    Else - Actions
        Game - Display to (All players) the text: Not Enough Wheat

Now, obviously there is alot of issues with this. For one, if I give someone straw and there isn't enough. It is going to say.

"Not Enough Straw"
"Not Enough Wheat"

because it is just going down the list.

I've somewhat tried to fit all of the "if/then/else" conditions into 1.
Here is what I came up with.

Code:
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    If - Conditions
        And - All (Conditions) are true
            Conditions
                Or - Any (Conditions) are true
                    Conditions
                        tempstring[1] Equal to wheat
                        tempstring[1] Equal to straw
                Or - Any (Conditions) are true
                    Conditions
                        Wheat[(Player number of (Triggering player))] Greater than or equal to tempint[4]
                        Straw[(Player number of (Triggering player))] Greater than or equal to tempint[4]
    Then - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                tempstring[1] Equal to straw
            Then - Actions
                Set Straw[(Player number of (Triggering player))] = (Straw[(Player number of (Triggering player))] - tempint[4])
            Else - Actions
                Game - Display to (All players) the text: Not Enough Straw
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                tempstring[1] Equal to wheat
            Then - Actions
                Set Wheat[(Player number of (Triggering player))] = (Wheat[(Player number of (Triggering player))] - tempint[4])
            Else - Actions
                Game - Display to (All players) the text: Not Enough Wheat
    Else - Actions
        Game - Display to (All players) the text: Invalid Input

UPDATE

I've coded out some more.

Code:
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    If - Conditions
        And - All (Conditions) are true
            Conditions
                tempstring[1] Equal to wheat
                Wheat[(Player number of (Triggering player))] Greater than or equal to tempint[4]
    Then - Actions
        Set Wheat[(Player number of (Triggering player))] = (Wheat[(Player number of (Triggering player))] - tempint[4])
        -------- Red --------
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                tempstring[2] Equal to red
            Then - Actions
                Set Wheat[1] = (Wheat[1] + tempint[4])
                Game - Display to (All players) the text: (Red Wheat:  + (String(Wheat[1])))
                Game - Display to (All players) the text: (Blue Wheat:  + (String(Wheat[2])))
                Game - Display to (All players) the text: Trade Succesful
            Else - Actions
        -------- Blue --------
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                tempstring[2] Equal to blue
            Then - Actions
                Set Wheat[2] = (Wheat[2] + tempint[4])
                Game - Display to (All players) the text: (Red Wheat:  + (String(Wheat[1])))
                Game - Display to (All players) the text: (Blue Wheat:  + (String(Wheat[2])))
                Game - Display to (All players) the text: Trade Succesful
            Else - Actions
    Else - Actions
        Do nothing

This takes and gives from and to specified players. Which is good. But it the other player doesn't have to confirm, and it doesn't take anything in return. I think I should change the written text to

"g (player) (resource) (integer) t (resource) (integer)"

so "g" = give and "t" = take

so then maybe run another trigger after this trigger. And the specified player would have to type "confirm" or something before 10 seconds and before typing anything else.

So if the specified player (blue for instance if I'm red), types "hahaha" or "(not equal to ) confirm" then it would cancel the deal.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top