• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[Trigger] Trade Resources with message text

Level 7
Joined
Sep 10, 2023
Messages
110
Hello I want to make a trigger for players 11 and 12, they are allied. I want when a player writes -give gold x amount it gives that resource from the player to the other one. I disabled resource trading but I need to make this work. Any help? I know I have to use string variables but im confused on how to use them.
 
That should be about it

  • Trade
    • Events
      • Player - Player 11 (Dark Green) types a chat message containing -give gold as A substring
    • Conditions
    • Actions
      • Set VariableSet GoldString = (Substring((Entered chat string), 11, 21))
      • Set VariableSet GoldInteger = (Integer(GoldString))
      • -------- --------------------------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Player 11 (Dark Green) Current gold) Greater than or equal to GoldInteger
        • Then - Actions
          • Player - Set Player 11 (Dark Green).Current gold to ((Player 11 (Dark Green) Current gold) - GoldInteger)
          • Player - Add (Integer(GoldString)) to Player 12 (Brown).Current gold
        • Else - Actions
So the string "-give gold " is 11 character long including the space, that's why you take a substring from 11 to whatever. I set 21 so that you can trade amounts up to 10 digits long but you may want to change that
You get an integer to a string by using this function

1777984964659.webp


And then an if/then/else to check that you can't give more than you currently have, you just have to duplicate the trigger for the other player
 
Chaosium is faster than me :D
Here's my take:
  • Give Gold
    • Events
      • Player - Player 11 (Dark Green) types a chat message containing -give gold as A substring
      • Player - Player 12 (Brown) types a chat message containing -give gold as A substring
    • Conditions
      • (Length of (Entered chat string)) Greater than 11
      • (Substring((Entered chat string), 1, 11)) Equal to -give gold
    • Actions
      • Set VariableSet amount = (Integer((Substring((Entered chat string), 12, 0))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Triggering player) Equal to Player 11 (Dark Green)
        • Then - Actions
          • Set VariableSet targetPlayer = Player 12 (Brown)
        • Else - Actions
          • Set VariableSet targetPlayer = Player 11 (Dark Green)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • amount Greater than 0
          • ((Triggering player) Current gold) Greater than or equal to amount
        • Then - Actions
          • Player - Add amount to targetPlayer.Current gold
          • Player - Add (-1 x amount) to (Triggering player).Current gold
          • Game - Display to (All allies of (Triggering player).) the text: ((Name of (Triggering player)) + ( added + ((String(amount)) + ( gold to + (Name of targetPlayer)))))
        • Else - Actions
I also check that the player does not input negative numbers, which would actually cause the player to take away gold from the other player
 
I also check that the player does not input negative numbers, which would actually cause the player to take away gold from the other player
Isn't it more appropriate to do this?
  • Set amount = (Integer((Substring((Entered chat string), 12, (Length of (Entered chat string))))))
 
Back
Top