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

Buying stats through chat trigger

Status
Not open for further replies.
Level 1
Joined
Nov 5, 2020
Messages
4
Hi guys. Brand new to WC3 editor, and currently trying to familiarise myself with triggers.

Working on an already existing version of Hero Line Wars, and attempting to make some changes.

Im trying to add a chat trigger, that gives the players hero x amount of strenght.
So -str max would grant the playerhero strenght based on current gold / 100 (So 100 gold per 1 strenght)

Im unsure how exactly i select those action. If you look at the screenshot, I did so the strenght added is based on the math above, but I can't select the "PlayerHero" Anywhere? Also im unsure how the gold left should be added and calculated as a trigger.

Cheers!
 

Attachments

  • strmax.JPG
    strmax.JPG
    28 KB · Views: 29

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Hi guys. Brand new to WC3 editor, and currently trying to familiarise myself with triggers.

Working on an already existing version of Hero Line Wars, and attempting to make some changes.

Im trying to add a chat trigger, that gives the players hero x amount of strenght.
So -str max would grant the playerhero strenght based on current gold / 100 (So 100 gold per 1 strenght)

Im unsure how exactly i select those action. If you look at the screenshot, I did so the strenght added is based on the math above, but I can't select the "PlayerHero" Anywhere? Also im unsure how the gold left should be added and calculated as a trigger.

Cheers!
So (Targeted unit) is what's called an Event Response. Most Events have their own Event Responses associated with them. Here are some examples of Unit Event Responses:

Event: A unit dies
Event Response: Dying unit

Event: A unit gains a level
Event Response: Leveling hero

Event: A unit is attacked
Event Responses: Attacked unit, Attacking unit

Note: Every Unit Event (Events that have the word "unit" in their name) can also use (Triggering unit) as an Event Response. This Event Response is always set to the Unit that is referred to in the Event (Dying unit, Leveling hero, Attacked unit, etc).


So when you're referencing (Targeted unit) the game has no reference to this unit because the Event "Player types a chat message" does not use that Event Response. Targeted unit is actually reserved for the Event "A unit acquires a target". Not only that, but what you're using is a PLAYER Event and not a Unit Event. This means that it's Event Responses will be related to Players and not Units. See my attached picture "example" for further clarification.


With all of that in mind, here's how you can create your desired triggers:
So first we need to keep track of each Player's Hero. We can do this by using a Unit variable with an Array enabled (it's a checkbox that you can turn on when creating the Variable). Variable Arrays allow you to use 1 Variable to store multiple things by giving each Variable it's own unique Index --> [the Index is an Integer that goes inside these brackets].

In this case we're going to use our Hero variable to store the Player's Hero after it's purchased from a Tavern. If you don't purchase your Heroes through a Tavern-like structure then then you will need to adjust the trigger accordingly.

Now each Player in Warcraft 3 has a Player Number, Player 1's number is 1, P2's is 2, P3's is 3, etc... We can use this Player Number as the Index [] in our Hero variable. The result: Hero[1] = Player 1's hero, Hero[2] = Player 2's hero, Hero[3] = Player 3's hero, etc...
  • Setup Heroes
    • Events
      • Unit - A unit Sells a unit
    • Conditions
      • ((Sold unit) is A Hero) Equal to True
    • Actions
      • Set Variable Hero[(Player number of (Owner of (Sold unit)))] = (Sold unit)
Now that we're keeping track of each Player's Hero, we can reference them whenever and wherever. In the case of our Str Max trigger, we can reference the Hero that belongs to the Player that the typed chat message like so:
  • Str Max
    • Events
      • Player - Player 1 (Red) types a chat message containing -str max as An exact match
      • Player - Player 2 (Blue) types a chat message containing -str max as An exact match
      • Player - Player 3 (Teal) types a chat message containing -str max as An exact match
      • Player - Player 4 (Purple) types a chat message containing -str max as An exact match
    • Conditions
    • Actions
      • Set Variable PN = (Player number of (Triggering player))
      • Set Variable Before = (Strength of Hero[PN] (Include bonuses))
      • Hero - Modify Strength of Hero[PN]: Add (((Triggering player) Current gold) / 100).
      • Set Variable After = (Strength of Hero[PN] (Include bonuses))
      • Set Variable GoldMultiplier = (After - Before)
      • Player - Add (-100 x GoldMultiplier) to (Triggering player).Current gold
You'll see that I added some extra variables (Before/After/GoldMultiplier), these help guarantee that the Player only spends 100 Gold for each Point of Strength gained.

Using your original setup, if the Player had 160 gold for example: 160/100 = 1.6, which will be rounded down to 1. The Hero will only gain 1 Strength, but the Player will lose 159 gold (160 - 159 = 1).

Variables:
Hero = Unit (Array)
PN = Integer
Before = Integer
After = Integer
GoldMultiplier = Integer


I also attached a map with a demonstration of these triggers in action. You can copy the Trigger Folder from my map and paste it into your map to save you some work.

IMPORTANT! Before copying anything over, go into the World Editor and under File/Preferences/General you want to enable the checkbox "Automatically create unknown variables when pasting trigger data". This will make your life easier when importing triggers into your map.

While you're there you should also enable "Allow negative real values". This enables you to use Shift-click in the Object Editor when clicking on a field, which will then allow you to type in negative values. This is what's used to create things like a -Armor aura, which is just Devotion Aura that has been given a negative Armor Bonus instead of positive Armor Bonus, as well as having it's Targets Allowed changed to target enemies instead of allies.
 

Attachments

  • example.png
    example.png
    307.6 KB · Views: 30
  • Str Gold example.w3m
    17.6 KB · Views: 26
Last edited:
Level 1
Joined
Nov 5, 2020
Messages
4
While you're there you should also enable "Allow negative real values". This enables you to use Shift-click in the Object Editor when clicking on a field, which will then allow you to type in negative values. This is what's used to create things like a -Armor aura, which is just Devotion Aura that has been given a negative Armor Bonus instead of positive Armor Bonus, as well as having it's Targets Allowed changed to target enemies instead of allies.

Thank you so very much, for that elaborate answer. I appreicate you taking the time, to help a stranger on the internet!
I feel like I understand the logic behind it all.

I'm attempting to modify the trigger, so that it works to my map. The hero selection is based on a unit entering a specific region. I've attatched the example as Blade1
Now I have to modify the setup trigger that you provided. I've changed the Event to "Unit enters Custom Gen" where the region is called Custom.
However In the action part, I'm unsure how to select the Hero.

Should the variable part instead be part of the actual trigger of the hero selection, or? I've also attatched the map I'm working on, if that helps you understand.
 

Attachments

  • blade1.JPG
    blade1.JPG
    30.2 KB · Views: 19
  • setup.JPG
    setup.JPG
    21.7 KB · Views: 29
  • Hero Line Warz FWL 0.5.w3x
    236.2 KB · Views: 17

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
In the Blademaster trigger you would add this Action immediately after you create the Blademaster:
  • Set Variable Hero[Player number of (Owner of Entering unit)] = Last created unit
And remember, the beauty of this setup is that you don't need to specify the player. It's a Generic Unit Event, meaning the Event runs when any Unit enters the Region regardless of it's Owner. From there we can get the desired Player by referencing the Owner of the Entering Unit.

See how the Blademaster is created for (Owner of (Entering unit)) and not a specific Player. We will do the same thing with our Hero[] variable.

Ideally, you'd use this style of triggering whenever possible. The goal is to have 1 Trigger/1 Variable that can be used by EVERY single player without you needing to use Conditions like "Owner of Entering unit Equal to Player 1 (Red)".

That being said, there will still be times when you want to use Conditions to filter out unwanted Players/Units, like for instance you probably want a Condition to prevent Units that AREN'T your "Hero Selector" from Entering the Region:
  • Events:
  • Unit - A unit enters custom <gen>
  • Conditions:
  • (Unit-type of (Entering unit)) Equal to Hero Selector
By Hero Selector I mean the unit that the player moves into the Region. Often times it's a Wisp or "Soul" or something.
 
Last edited:
Status
Not open for further replies.
Top