• 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.

[Solved] String Trigger

Status
Not open for further replies.
Level 6
Joined
Apr 1, 2009
Messages
201
What I'm trying to do is to display information about a stored string. For example in my trigger I have an item named "WoodenSword". Under the item wooden sword are its stats. So when a player types "dis" as a substring adding "WoodenSword" at the end to make "diswoodensword" it displays the amount of damage and armor that item has. I was hoping it was possible to use integer A, instead of the if its equal to this exact line under the conditions because there would be a very long list of them. I know there are probally a lot of things wrong with the trigger and I am sorry for that. I attempted to do it on my own and are confused about it. I built off an old trigger I had gotten some help on.

  • Storage
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Items[1] = WoodenSword
      • Set DamageAmount[1] = 1
      • Set ArmorAmount[1] = 0
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Trigger - Add to DIS <gen> the event (Player - (Player((Integer A))) types a chat message containing dis as A substring)
  • DIS
    • Events
    • Conditions
    • Actions
      • Set CommandString = (Substring((Entered chat string), 12, (Length of (Entered chat string))))
      • For each (Integer A) from 1 to 2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CommandString Equal to Items[(Integer A)]
            • Then - Actions
              • Game - Display to (Player group((Triggering player))) the text: (ArmorAmount[(Integer A)] + DamageAmount[(Integer A)])
            • Else - Actions
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
  • Set CommandString = (Substring((Entered chat string), 12, (Length of (Entered chat string))))
Shouldn't this be

  • Set CommandString = (Substring((Entered chat string), 4, (Length of (Entered chat string))))
First 3 letters is "dis", from fourth letter to last letter: name of item.

Edit:I can delete my post and you can figure :O
 
^Plus: trigger leaks player force. In both triggers you should replace (Integer A) with custom integer, in case it's global parameter and can bug your trigger ocasionaly, if used ofen in many differend triggers. You don't have to iterate loop two times since you have only one array index avaible ;)

Fixed:
  • DIS
    • Events
    • Conditions
    • Actions
      • Set CommandString = (Substring((Entered chat string), 3, (Length of (Entered chat string))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CommandString Equal to Items[1]
        • Then - Actions
          • Set force = (PlayerGroup((Triggering player)))
          • Game - Display to force the text: (ArmorAmount[1] + DamageAmount[1])
          • Custom script: call DestroyForce(udg_force)
Where 'force' is player group variable.
 
Level 6
Joined
Apr 1, 2009
Messages
201
I changed the set command string to 4 as you both had mentioned and as Pharaoh_ also mentioned the group triggering player leaks, so I tried spinnaker's idea and changed integer A to a custom variable. And nothing happens at all when I type "disWoodenSword". I still have no clue what I'm doing wrong, hoping someone could help. Here's what I have now: (Also on a sidenote not sure if I mentioned that all the set variables are strings)
Edit:Added Test Map
  • Storage
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Items[1] = WoodenSword
      • Set DamageAmount[1] = 1
      • Set ArmorAmount[1] = 0
      • For each (Integer PlayersInteger) from 1 to 12, do (Actions)
        • Loop - Actions
          • Trigger - Add to DIS <gen> the event (Player - (Player(PlayersInteger)) types a chat message containing dis as A substring)
  • DIS
    • Events
    • Conditions
    • Actions
      • Set CommandString = (Substring((Entered chat string), 4, (Length of (Entered chat string))))
      • For each (Integer ItemsInteger) from 1 to 2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CommandString Equal to Items[1]
            • Then - Actions
              • Set Force = (Player group((Triggering player)))
              • Game - Display to Force the text: (ArmorAmount[1] + DamageAmount[1])
              • Custom script: call DestroyForce(udg_Force)
            • Else - Actions
 
Last edited:
There's no reason to make use of a loop and have a static number as an array slot comparison (because you will end up using what you wanted to avoid: if/then/else huge block); try ItemsInteger.

Set Array maximum size of the String variables to 1, there's no need to set it up to 8192.

The display message uses concatenate strings; if you want to get the sum of the variables, you need a real (or integer) conversion first and the use of Arithmetic function.
 
Level 6
Joined
Apr 1, 2009
Messages
201
I'm not that talented with making triggers, But I've been reading up on some tutorials in the meantime. But I don't understand the first and last suggestion. I changed the arrays to 1 but I don't understand what you meant by the other two :/.
 
Level 6
Joined
Apr 1, 2009
Messages
201
Finally figured it out and I wanted it to display the amount of armor and damage an item had. So far the trigger works fine here it is:

  • Storage
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Items[1] = WoodenSword
      • Set DamageAmount[1] = 1
      • Set ArmorAmount[1] = 0
      • For each (Integer PlayersInteger) from 1 to 12, do (Actions)
        • Loop - Actions
          • Trigger - Add to DIS <gen> the event (Player - (Player(PlayersInteger)) types a chat message containing dis as A substring)
  • DIS
    • Events
    • Conditions
    • Actions
      • Set CommandString = (Substring((Entered chat string), 4, (Length of (Entered chat string))))
      • For each (Integer ItemsInteger) from 1 to 2, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CommandString Equal to Items[ItemsInteger]
            • Then - Actions
              • Set Force = (Player group((Triggering player)))
              • Game - Display to Force the text: (Damage: + (String((Integer(DamageAmount[ItemsInteger])))))
              • Game - Display to Force the text: (Armor: + (String((Integer(ArmorAmount[ItemsInteger])))))
              • Custom script: call DestroyForce(udg_Force)
            • Else - Actions
 
Last edited:
Status
Not open for further replies.
Top