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

Trade resources via chat

Status
Not open for further replies.
I can't believe i don't know how to do this...I've been using world editor for like 4 years and i know most stuff about triggers. The problem is, i found myself in need for more complex chat commands triggers, which, apparently, i have never used before for some reason.
the thing i want to do is something like:
-give player2 gold 2000
that's how a chat command should look like
If anyone was be kind enough to help me, i would appreciate it :ogre_haosis:
 
Level 23
Joined
Oct 20, 2012
Messages
3,075
Here's a sample trigger.
  • Give Gold
    • Events
      • Player - Player 1 (Red) types a chat message containing -givegold as A substring
      • (Insert All Other events for other players here)
    • Conditions
    • Actions
      • Set PlayerIndex = (Integer((Substring((Entered chat string), 11, 12))))
      • Set Amount = (Integer((Substring((Entered chat string), 14, 17))))
      • Player - Add Amount to (Player(PlayerIndex)) Current gold
      • Player - Add (Amount x -1) to (Triggering player) Current gold

The chatstring needed is -givegold. So if the player types "-givegold 02 2000", it will give 2000 gold to the player 2.

The chat string MUST be in that format because of how I get the values from the chatstring. To get determine which player the triggering player wants to give resource to, I set the variable PlayerIndex to the integers from the 11th to the 12th character of the string. (spaces and the dash will be included in counting the characters)
  • Set PlayerIndex = (Integer((Substring((Entered chat string), 11, 12))))

Now to get the amount of resource the player wants to give, I just set the amount variable to the string founf between the 14th and the 17th character. (you can change the 17 to 18 to enable the player to give more than 9999)
  • Set Amount = (Integer((Substring((Entered chat string), 14, 17))))

The rest is kinda simple I guess.

This gives the gold to the desired player.
  • Player - Add Amount to (Player(PlayerIndex)) Current gold

And this one deducts it from your resource.
  • Player - Add (Amount x -1) to (Triggering player) Current gold
 
Status
Not open for further replies.
Top