• 🏆 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!

[General] Text when using -str/agi/int max chat command

Status
Not open for further replies.
Level 1
Joined
Jan 28, 2015
Messages
7
Have been trying to make a game text or a floating text saying : Your hero has gained X strength. Can`t get it to show how many strength points the hero gets.
thanks in advance.
  • 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
    • Player - Player 5 (Yellow) types a chat message containing -str max as An exact match
    • Player - Player 6 (Orange) types a chat message containing -str max as An exact match
    • Player - Player 7 (Green) types a chat message containing -str max as An exact match
    • Player - Player 8 (Pink) types a chat message containing -str max as An exact match
    • Player - Player 9 (Gray) types a chat message containing -str max as An exact match
    • Player - Player 10 (Light Blue) types a chat message containing -str max as An exact match
    • Player - Player 11 (Dark Green) types a chat message containing -str max as An exact match
    • Player - Player 12 (Brown) types a chat message containing -str max as An exact match
  • Conditions
    • ((Triggering player) Current gold) Greater than or equal to 150
  • ActionsActions
    • Unit Group - Pick every unit in (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True)) and do (Actions)
      • Loop - Actions
        • Hero - Modify Strength of (Picked unit): Add ((Player 1 (Red) Current gold) / 150)
        • Player - Set (Triggering player) Current gold to (((Triggering player) Current gold) mod 150)
        • Game - Display to Player Group - Player 1 (Red) for 30.00 seconds the text: (Your Hero Gained + ((Substring(<Empty String>, (((Owner of (Triggering unit)) Current gold) / 150), 1)) + Strength))
 
Level 25
Joined
May 11, 2007
Messages
4,651
Set tempInteger = Triggering player Current Gold / 150

if (tempInteger > 0)
{
Modify Strength of Picked unit: Add tempReal
Game - Display to PlayerGroup(TriggeringPlayer) the text: Your hero has gained + substring(tempReal)
}

Sort of like that and it should work.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
The method of LordDz is good.
However to make sure that you know the difference (when a value could have a max) you should set a tempvariable to the amount of strength the unit has, then modify the strength, then calculate the difference between before and after.

In this case it wouldnt make any difference but when something has a maximum, life health, mana or anything else with a cap, this is the best way.
 
Substring of an emty string doesn't make sense. You must take the entered chat string as reference:

((Substring(<Empty String>, ....
->
((Substring(EnteredChatString, ....

You would anyway print the wrong number, because you already devided your gold in the action before.

Don't use "Player 1" in any of your operations, as you want it to have MPI. (multiple player instanability)
You may use TriggeringPlayer instead.

"Display <Text> to PlayerGroupOf(TriggeringPlayer)" will create a new PlayerGroup each call. (http://www.hiveworkshop.com/forums/triggers-scripts-269/things-leak-35124/)

Responses used more often like "TriggeringPlayer" might be stored into temp variables to increase performance. (and probably readability^^)

@LordDz, you (probably accidently) use a real for addting stats and to display the number, which should be an integer.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Something like this:
  • set max attribute
    • Events
      • Player - Player 1 (Red) types a chat message containing - as A substring
      • Player - Player 2 (Blue) types a chat message containing - as A substring
      • Player - Player 3 (Teal) types a chat message containing - as A substring
      • Player - Player 4 (Purple) types a chat message containing - as A substring
      • Player - Player 5 (Yellow) types a chat message containing - as A substring
      • Player - Player 6 (Orange) types a chat message containing - as A substring
      • Player - Player 7 (Green) types a chat message containing - as A substring
      • Player - Player 8 (Pink) types a chat message containing - as A substring
      • Player - Player 9 (Gray) types a chat message containing - as A substring
      • Player - Player 10 (Light Blue) types a chat message containing - as A substring
      • Player - Player 11 (Dark Green) types a chat message containing - as A substring
      • Player - Player 12 (Brown) types a chat message containing - as A substring
    • Conditions
    • Actions
      • Set TempPlayer = (Triggering player)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Entered chat string) Equal to -str max
        • Then - Actions
          • Set TempUnitGroup = (Units in (Entire map))
          • Unit Group - Pick every unit in TempUnitGroup and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) is A Hero) Equal to True
                  • (Owner of (Picked unit)) Equal to TempPlayer
                • Then - Actions
                  • Set TempInteger = (Strength of (Picked unit) (Include bonuses))
                  • Hero - Modify Strength of (Picked unit): Add ((TempPlayer Current gold) / 150)
                  • Player - Set TempPlayer Current gold to ((TempPlayer Current gold) mod 150)
                  • Set TempInteger = ((Strength of (Picked unit) (Include bonuses)) - TempInteger)
                  • Game - Display to (Player group(TempPlayer)) for 30.00 seconds the text: ((Proper name of (Picked unit)) + ( gained + ((String(TempInteger)) + points of Strength.)))
                • Else - Actions
          • Custom script: call DestroyGroup(udg_TempUnitGroup)
          • Skip remaining actions
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Entered chat string) Equal to -agi max
        • Then - Actions
          • Set TempUnitGroup = (Units in (Entire map))
          • Unit Group - Pick every unit in TempUnitGroup and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) is A Hero) Equal to True
                  • (Owner of (Picked unit)) Equal to TempPlayer
                • Then - Actions
                  • Set TempInteger = (Agility of (Picked unit) (Include bonuses))
                  • Hero - Modify Agility of (Picked unit): Add ((TempPlayer Current gold) / 150)
                  • Player - Set TempPlayer Current gold to ((TempPlayer Current gold) mod 150)
                  • Set TempInteger = ((Agility of (Picked unit) (Include bonuses)) - TempInteger)
                  • Game - Display to (Player group(TempPlayer)) for 30.00 seconds the text: ((Proper name of (Picked unit)) + ( gained + ((String(TempInteger)) + points of Agility.)))
                • Else - Actions
          • Custom script: call DestroyGroup(udg_TempUnitGroup)
          • Skip remaining actions
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Entered chat string) Equal to -int max
        • Then - Actions
          • Set TempUnitGroup = (Units in (Entire map))
          • Unit Group - Pick every unit in TempUnitGroup and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) is A Hero) Equal to True
                  • (Owner of (Picked unit)) Equal to TempPlayer
                • Then - Actions
                  • Set TempInteger = (Intelligence of (Picked unit) (Include bonuses))
                  • Hero - Modify Intelligence of (Picked unit): Add ((TempPlayer Current gold) / 150)
                  • Player - Set TempPlayer Current gold to ((TempPlayer Current gold) mod 150)
                  • Set TempInteger = ((Intelligence of (Picked unit) (Include bonuses)) - TempInteger)
                  • Game - Display to (Player group(TempPlayer)) for 30.00 seconds the text: ((Proper name of (Picked unit)) + ( gained + ((String(TempInteger)) + points of Intelligence.)))
                • Else - Actions
          • Custom script: call DestroyGroup(udg_TempUnitGroup)
          • Skip remaining actions
        • Else - Actions
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
I mean that the GUI function for Player Groups is this:
call ForForce( GetPlayersAll(), function Trig_Untitled_Trigger_001_Func001A )
and the GUI function for Unit Groups is this:
JASS:
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    call ForGroup(whichGroup, callback)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(whichGroup)
    endif

So Blizzard didn't care about bj_wantDestroyForce.
 
Level 1
Joined
Jan 28, 2015
Messages
7
Thanks for all the help so far.
This might be a stupid question but is there a way to copy the trigger right out of the browser or do i have to type it in manualy.
 
Level 1
Joined
Jan 28, 2015
Messages
7
It didn`t accept Custom script: call DestroyGroup(udg_TempUnitGroup)
Says expected a name on error
what to do ?
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
You need to add a global variable.
TempUnitGroup (of type "Unit Group")
the "udg_" refers to regular globals.

Also just under the "Set TempPlayer = (Triggering Player)"
You need to set a player group: "Set TempPlayerGroup = Convert (TempPlayer) to player group"
and use that one on the "Display text to player group"
Just below the "Custom Script: call DestroyGroup(udg_TempUnitGroup)"
you need this: "Custom Script: call DestroyForce(udg_TempPlayerGroup)"
 
Level 1
Joined
Jan 28, 2015
Messages
7
It sems like the error was because i named the variable tempUnitGroup And not TempUnitGroup as the custom script was looking for
 
Level 1
Joined
Jan 28, 2015
Messages
7
But now it says expected `endif` For line:
Custom Script: call DestroyForce(udg_tempPlayerGroup)
 
Level 1
Joined
Jan 28, 2015
Messages
7
No need got just solved the problem had copied: `Custom Script: call DestroyForce(udg_tempPlayerGroup)`
it all works like a charm now

Thank you to all of you who helped me much appreciated
 
Status
Not open for further replies.
Top