• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Need help with my give gold trigger

Level 3
Joined
Mar 18, 2023
Messages
28
Hello. I made a really simple give gold command similar to troll & elves and it doesn't work for me. I don't mess around with the string stuff too much and still new to how string functions work. I attached a screenshot if someone can look at it for me and tell me what went wrong, I'll greatly appreciate it. I'm guessing it had something to do with the way I set my GGAmount[1] variable or the Entered chat string condition. Thank you ahead of time!
 

Attachments

  • 1.png
    1.png
    28.6 KB · Views: 18

Remixer

Map Reviewer
Level 31
Joined
Feb 19, 2011
Messages
1,957
In future you'll want to copy your trigger as text (right-click the trigger file-icon above the list of events and actions and copy it as text) and paste said text using the
lZaPDTr[1].png
Trigger embedding function on Hive. This way it's easier for people to refer to your trigger's individual lines.

On the first line of actions, you'd want the line to be:
  • Set VariableSet YOUR_INTEGER = (Integer((Substring((Entered chat string), 6, (Length of (Entered chat string))))))
Difference: Length of... function.
Then in the IF conditions are a little wrong. Firstly, if you check for this:
  • (Entered chat string) Equal to -gg2
It will only pass when the message was exactly that "-gg2" which obviously doesn't work for your purpose. So you'd want to check if the player message contained the "-gg2" instead. Essentially you could do this with:
  • Set VariableSet YOUR_STRING = (Substring((Entered chat string), 4, 4))
This should return the number of the "-ggX". Note that it would not work if the player numbers go into two digits.

Generally you would want this trigger to work for any player. More efficient way would be to loop through the possible player numbers and match the player with the entered number and save that player in a variable.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,546
Here's an example of what Remixer suggested, which can handle any number of players:
  • Actions
    • Set Variable TARGET = (Integer((Substring((Entered chat string), 4, 4)))
    • If TARGET Less than 10 Then Set Variable OFFSET = 6 Else Set Variable OFFSET = 7
    • Set Variable GOLD = (Integer((Substring((Entered chat string), OFFSET, (Length of (Entered chat string))))))
    • If ((Triggering player) current gold) Less than GOLD Then Set Variable GOLD = ((Triggering player) current gold) Else do nothing
    • If (GOLD Less than or Equal to 0) Then Skip remaining actions Else do nothing
    • Player - Add (GOLD * -1) to (Triggering player) current gold
    • Player - Add GOLD to (Player(TARGET)) current gold
So this checks what you typed at index 4 of your chat message and uses that as the Player Number of your gold target:
-ggX

Then it checks what you typed at either index 6 or 7 depending on whether the Player Number from before was single or double digit:
-ggX Y

This expects a space between X and Y. With these values stored we can give the proper amount of gold to the correct target. It also handles what happens if you typed a gold value above your current gold or if you went below 0. Also, note how you don't need to Set the Player's gold, simply Add a positive or negative amount.

So if Player 1 types -gg5 1000 then Player 5 will receive 1000 gold from Player 1 OR up to Player's 1 current Gold.
 
Last edited:
Level 3
Joined
Mar 18, 2023
Messages
28
I'll delete mine and remake it to this version instead since it's a lot more efficient. Thank you Remixer and Uncle!
 
Level 6
Joined
Mar 27, 2019
Messages
51
I'll delete mine and remake it to this version instead since it's a lot more efficient. Thank you Remixer and Uncle!
Here is a pretty decent version of what you want to do.

  • InitGiveResource
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- 1 Represents Player Red | 12 Represents Player Brown --------
      • -------- - --------
      • -------- Increase it to 13-24 to support more Players --------
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Trigger - Add to GiveGold <gen> the event (Player - (Player((Integer A))) types a chat message containing -gg as A substring)
          • Trigger - Add to GiveLumber <gen> the event (Player - (Player((Integer A))) types a chat message containing -gl as A substring)

  • GiveGold
    • Events
    • Conditions
    • Actions
      • -------- - --------
      • Set VariableSet Temp_Integer = (Integer((Substring((Entered chat string), 4, 5))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Integer Less than 10
        • Then - Actions
          • Set VariableSet Offset = 6
        • Else - Actions
          • Set VariableSet Offset = 7
      • -------- - --------
      • Set VariableSet Temp_Player = (Player(Temp_Integer))
      • -------- - --------
      • Set VariableSet Temp_Integer = (Integer((Substring((Entered chat string), Offset, (Length of (Entered chat string))))))
      • -------- - --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering player) Current gold) Greater than or equal to Temp_Integer
          • (Triggering player) Not equal to Temp_Player
          • (Temp_Player slot status) Equal to Is playing
          • Temp_Integer Greater than 0
        • Then - Actions
          • Player - Add (0 - Temp_Integer) to (Triggering player).Current gold
          • Player - Add Temp_Integer to Temp_Player.Current gold
          • Set VariableSet Temp_Force = (Player group(Temp_Player))
          • Game - Display to Temp_Force for 1.00 seconds the text: ((Name of (Triggering player)) + ( has given you |cffffd700 + ((String(Temp_Integer)) + Gold|r!)))
          • Custom script: call DestroyForce(udg_Temp_Force)
          • Set VariableSet Temp_Force = (Player group((Triggering player)))
          • Game - Display to Temp_Force for 1.00 seconds the text: (You have sent |cffffd700 + ((String(Temp_Integer)) + ( Gold|r to + ((Name of Temp_Player) + !))))
          • Custom script: call DestroyForce(udg_Temp_Force)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Temp_Player slot status) Not equal to Is playing
            • Then - Actions
              • Set VariableSet Temp_Force = (Player group((Triggering player)))
              • Game - Display to Temp_Force for 1.00 seconds the text: |cffff6464You can't...
              • Custom script: call DestroyForce(udg_Temp_Force)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Triggering player) Equal to Temp_Player
                • Then - Actions
                  • Set VariableSet Temp_Force = (Player group((Triggering player)))
                  • Game - Display to Temp_Force for 1.00 seconds the text: |cffff6464You can't...
                  • Custom script: call DestroyForce(udg_Temp_Force)
                • Else - Actions
                  • Set VariableSet Temp_Force = (Player group((Triggering player)))
                  • Game - Display to Temp_Force for 1.00 seconds the text: |cffff6464Not enoug...
                  • Custom script: call DestroyForce(udg_Temp_Force)

  • GiveLumber
    • Events
    • Conditions
    • Actions
      • -------- - --------
      • Set VariableSet Temp_Integer = (Integer((Substring((Entered chat string), 4, 5))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Integer Less than 10
        • Then - Actions
          • Set VariableSet Offset = 6
        • Else - Actions
          • Set VariableSet Offset = 7
      • -------- - --------
      • Set VariableSet Temp_Player = (Player(Temp_Integer))
      • -------- - --------
      • Set VariableSet Temp_Integer = (Integer((Substring((Entered chat string), Offset, (Length of (Entered chat string))))))
      • -------- - --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering player) Current lumber) Greater than or equal to Temp_Integer
          • (Triggering player) Not equal to Temp_Player
          • (Temp_Player slot status) Equal to Is playing
          • Temp_Integer Greater than 0
        • Then - Actions
          • Player - Add (0 - Temp_Integer) to (Triggering player).Current lumber
          • Player - Add Temp_Integer to Temp_Player.Current lumber
          • Set VariableSet Temp_Force = (Player group(Temp_Player))
          • Game - Display to Temp_Force for 1.00 seconds the text: ((Name of (Triggering player)) + ( has given you |cff329632 + ((String(Temp_Integer)) + Lumber|r!)))
          • Custom script: call DestroyForce(udg_Temp_Force)
          • Set VariableSet Temp_Force = (Player group((Triggering player)))
          • Game - Display to Temp_Force for 1.00 seconds the text: (You have sent |cff329632 + ((String(Temp_Integer)) + ( Lumber|r to + ((Name of Temp_Player) + !))))
          • Custom script: call DestroyForce(udg_Temp_Force)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Temp_Player slot status) Not equal to Is playing
            • Then - Actions
              • Set VariableSet Temp_Force = (Player group((Triggering player)))
              • Game - Display to Temp_Force for 1.00 seconds the text: |cffff6464You can't...
              • Custom script: call DestroyForce(udg_Temp_Force)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Triggering player) Equal to Temp_Player
                • Then - Actions
                  • Set VariableSet Temp_Force = (Player group((Triggering player)))
                  • Game - Display to Temp_Force for 1.00 seconds the text: |cffff6464You can't...
                  • Custom script: call DestroyForce(udg_Temp_Force)
                • Else - Actions
                  • Set VariableSet Temp_Force = (Player group((Triggering player)))
                  • Game - Display to Temp_Force for 1.00 seconds the text: |cffff6464Not enoug...
                  • Custom script: call DestroyForce(udg_Temp_Force)

You can also download my GiveGoldExample Map to get a better view, also ready to be copy-pasted into your Map when you adjust the variables/copy them over.
 

Attachments

  • GiveGoldExample.w3m
    21.4 KB · Views: 2
Level 3
Joined
Mar 18, 2023
Messages
28
Here is a pretty decent version of what you want to do.

  • InitGiveResource
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- 1 Represents Player Red | 12 Represents Player Brown --------
      • -------- - --------
      • -------- Increase it to 13-24 to support more Players --------
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Trigger - Add to GiveGold <gen> the event (Player - (Player((Integer A))) types a chat message containing -gg as A substring)
          • Trigger - Add to GiveLumber <gen> the event (Player - (Player((Integer A))) types a chat message containing -gl as A substring)

  • GiveGold
    • Events
    • Conditions
    • Actions
      • -------- - --------
      • Set VariableSet Temp_Integer = (Integer((Substring((Entered chat string), 4, 5))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Integer Less than 10
        • Then - Actions
          • Set VariableSet Offset = 6
        • Else - Actions
          • Set VariableSet Offset = 7
      • -------- - --------
      • Set VariableSet Temp_Player = (Player(Temp_Integer))
      • -------- - --------
      • Set VariableSet Temp_Integer = (Integer((Substring((Entered chat string), Offset, (Length of (Entered chat string))))))
      • -------- - --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering player) Current gold) Greater than or equal to Temp_Integer
          • (Triggering player) Not equal to Temp_Player
          • (Temp_Player slot status) Equal to Is playing
          • Temp_Integer Greater than 0
        • Then - Actions
          • Player - Add (0 - Temp_Integer) to (Triggering player).Current gold
          • Player - Add Temp_Integer to Temp_Player.Current gold
          • Set VariableSet Temp_Force = (Player group(Temp_Player))
          • Game - Display to Temp_Force for 1.00 seconds the text: ((Name of (Triggering player)) + ( has given you |cffffd700 + ((String(Temp_Integer)) + Gold|r!)))
          • Custom script: call DestroyForce(udg_Temp_Force)
          • Set VariableSet Temp_Force = (Player group((Triggering player)))
          • Game - Display to Temp_Force for 1.00 seconds the text: (You have sent |cffffd700 + ((String(Temp_Integer)) + ( Gold|r to + ((Name of Temp_Player) + !))))
          • Custom script: call DestroyForce(udg_Temp_Force)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Temp_Player slot status) Not equal to Is playing
            • Then - Actions
              • Set VariableSet Temp_Force = (Player group((Triggering player)))
              • Game - Display to Temp_Force for 1.00 seconds the text: |cffff6464You can't...
              • Custom script: call DestroyForce(udg_Temp_Force)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Triggering player) Equal to Temp_Player
                • Then - Actions
                  • Set VariableSet Temp_Force = (Player group((Triggering player)))
                  • Game - Display to Temp_Force for 1.00 seconds the text: |cffff6464You can't...
                  • Custom script: call DestroyForce(udg_Temp_Force)
                • Else - Actions
                  • Set VariableSet Temp_Force = (Player group((Triggering player)))
                  • Game - Display to Temp_Force for 1.00 seconds the text: |cffff6464Not enoug...
                  • Custom script: call DestroyForce(udg_Temp_Force)

  • GiveLumber
    • Events
    • Conditions
    • Actions
      • -------- - --------
      • Set VariableSet Temp_Integer = (Integer((Substring((Entered chat string), 4, 5))))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Temp_Integer Less than 10
        • Then - Actions
          • Set VariableSet Offset = 6
        • Else - Actions
          • Set VariableSet Offset = 7
      • -------- - --------
      • Set VariableSet Temp_Player = (Player(Temp_Integer))
      • -------- - --------
      • Set VariableSet Temp_Integer = (Integer((Substring((Entered chat string), Offset, (Length of (Entered chat string))))))
      • -------- - --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering player) Current lumber) Greater than or equal to Temp_Integer
          • (Triggering player) Not equal to Temp_Player
          • (Temp_Player slot status) Equal to Is playing
          • Temp_Integer Greater than 0
        • Then - Actions
          • Player - Add (0 - Temp_Integer) to (Triggering player).Current lumber
          • Player - Add Temp_Integer to Temp_Player.Current lumber
          • Set VariableSet Temp_Force = (Player group(Temp_Player))
          • Game - Display to Temp_Force for 1.00 seconds the text: ((Name of (Triggering player)) + ( has given you |cff329632 + ((String(Temp_Integer)) + Lumber|r!)))
          • Custom script: call DestroyForce(udg_Temp_Force)
          • Set VariableSet Temp_Force = (Player group((Triggering player)))
          • Game - Display to Temp_Force for 1.00 seconds the text: (You have sent |cff329632 + ((String(Temp_Integer)) + ( Lumber|r to + ((Name of Temp_Player) + !))))
          • Custom script: call DestroyForce(udg_Temp_Force)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Temp_Player slot status) Not equal to Is playing
            • Then - Actions
              • Set VariableSet Temp_Force = (Player group((Triggering player)))
              • Game - Display to Temp_Force for 1.00 seconds the text: |cffff6464You can't...
              • Custom script: call DestroyForce(udg_Temp_Force)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Triggering player) Equal to Temp_Player
                • Then - Actions
                  • Set VariableSet Temp_Force = (Player group((Triggering player)))
                  • Game - Display to Temp_Force for 1.00 seconds the text: |cffff6464You can't...
                  • Custom script: call DestroyForce(udg_Temp_Force)
                • Else - Actions
                  • Set VariableSet Temp_Force = (Player group((Triggering player)))
                  • Game - Display to Temp_Force for 1.00 seconds the text: |cffff6464Not enoug...
                  • Custom script: call DestroyForce(udg_Temp_Force)

You can also download my GiveGoldExample Map to get a better view, also ready to be copy-pasted into your Map when you adjust the variables/copy them over.
Oh why thank you! I already manually did it myself, but this will definitely help someone else in the future if they're searching for it too. Greatly appreciate the time and effort you put in to making this and posting it! :)
 
Top