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

Zoom command

Status
Not open for further replies.
Level 12
Joined
Dec 11, 2014
Messages
662
I want to add a zoom command to my map.
When a player types -zoom 0 the camera will be zoomed in to the ground (more than warcraft allows with scroll on the mouse) and the max would be -zoom 1000 where you pretty much won't be able to see the map how far you would be. Also, any number in between would also work.This command can be seen in Legion TD. How to make it?
 
Level 4
Joined
Dec 31, 2014
Messages
68
You'll have to experient with values but..
  • Events
    • Player - Player 1 (Red) types a chat message containing -Zoom1 as An exact match
  • Conditions
  • Actions
    • Camera - Set (Triggering player)'s camera Field of view to 1500.00 over 0.00 seconds
For both Zooms make a trigger but change the 1500 value.

If your map is Multiplayer you'd have to make seperate triggers for all players that will be playing.
 
You can add more events to one trigger. Only one trigger is needed, as you can refer to the correct player with using "TriggeringPlayer" response.

It can be done with static commands as shown above.
It can be done in a more dynamic way if you work with "Types <-zoom >" as substring. Then you need to convert the latter subtring into a real and do further operations.
 
Level 7
Joined
May 11, 2010
Messages
278
I made an example for you.


  • Setup
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • For each (Integer TempInt) from 1 to 12, do (Actions)
        • Loop - Actions
          • Trigger - Add to Zoom <gen> the event (Player - (Player(TempInt)) types a chat message containing -zoom as A substring)
  • Zoom
    • Events
    • Conditions
    • Actions
      • Set TempReal = (Real((Substring((Entered chat string), 7, (Length of (Entered chat string))))))
      • Camera - Set (Triggering player)'s camera Field of view to TempReal over 0.00 seconds
In the setup trigger, it adds all players to the other trigger so they can trigger it by writing "-zoom"
The Zoom trigger runs when a player writes -zoom and checks what they've written after zoom, and sets the camera bounds to that number.
For example, writing "-zoom 50" would set the camera field of view to 50.

Test map attached
 

Attachments

  • Set Zoom.w3x
    15.4 KB · Views: 328
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
I would recommend adding conditions to check if the entered chat string is a valid zoom command. This includes checking if it is prefixed with the appropriate "-zoom " (case insensitive, space included) string and that it has exactly 1 argument which is a valid integer.

This is to stop it firing accidently when people are instructing the command to other players.

For example, Shoto's implementation shown above (did not check map) would incorrectly fire if someone typed the below message.
DrSuperGood said:
NARUTO257 type -zoom 750 for a better zoom level so you can see more of what happens
With the above the player would have had their zoom level set as if they typed "-zoom 257" even though they clearly did not type the command. If the string conversion has poor robustness it could result in a value of 0 zoom, which would inconvenience the player. This would correctly fail the prefix check I described above as "NARUTO" is not case insensitive equal to "-zoom ".
 
Level 14
Joined
Dec 29, 2009
Messages
931
  • Zoom
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Substring((Entered chat string), 1, 5)) Equal to -zoom
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Substring((Entered chat string), 6, (Length of (Entered chat string)))) Not equal to <Empty String>
            • Then - Actions
              • Set tempReal = (Real((Substring((Entered chat string), 7, (Length of (Entered chat string))))))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • tempReal Less than 500.00
                • Then - Actions
                  • Camera - Set (Triggering player)'s camera Distance to target to 500.00 over 1.00 seconds
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • tempReal Greater than 3000.00
                    • Then - Actions
                      • Camera - Set (Triggering player)'s camera Distance to target to 3000.00 over 1.00 seconds
                    • Else - Actions
                      • Camera - Set (Triggering player)'s camera Distance to target to tempReal over 1.00 seconds
            • Else - Actions
              • Camera - Reset camera for (Triggering player) to standard game-view over 1.00 seconds
        • Else - Actions
Try this, I believe this should work.
It will also reset the camera to the default zoom if you type "-zoom" without entering any additional information.
 
Level 12
Joined
Dec 11, 2014
Messages
662
Thanks fladdermasken.
After some time (long time) I tested the trigger and it works perfectly except one thing.
When a player types "-zoom " (There is a space after zoom) the camera goes to the minimum (500).
I tried putting another condition where it's
  • (Substring((Entered chat string), 6, (Length of (Entered chat string)))) Not equal to " "
(So just 1 space) instead of <Empty String>, and it works. But now if you type "-zoom " (2 spaces) it acts like before where it sets the camera to the minimum.

Any ways to avoid this?
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
You should use a String library.
One that supports splitting words, then you can do:

JASS:
call String_SplitWords(GetEnteredChatString())
if String_StartsWith(word[0], "/") then
    if word[0] == "/zoom" and S2I(word[1]) > 0 then
        call SetCameraDistanceStuffICantRememberTheName(S2I(word[1]))
    endif
endif

Both String_SplitWords() and String_StartsWith() would be functions from the string library.
(I am aware that SplitWords would be Trim on regex to replace multispaces with single spaces and a Split that would split the string with " " as argument of the split, but that is of no concern at this moment, I assume String libraries will work differently depending on who made it.)

In GUI, there is not much you can do... you will still require custom scripts that run the String libraries functions.
 
Level 12
Joined
Dec 11, 2014
Messages
662
If someone types "-zoom" the camera is set to the default game camera, but when they type "-zoom " (with a space) the camera goes to the minimum value (500).

It's nothing important really, just wanted to know if there was a way to make it always behave the same way, regardless of how many spaces.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
You can do a substring check.
Technically, check if the substring of 1 to 5 of the entered chat string is equal to "-zoom" or "/zoom"
Then it wont care what you wrote after it.
If you also want the feature to have it zoom to a parameter that you can fill in, then you have to reset the camera if the integer of the substring of the remainder of the string is equal to 0.

EDIT:
Just took a look at the actual script and:
After "Set tempReal = (Real((Substring((Entered chat string), 7, (Length of (Entered chat string))))))"
You have to do a check if the tempReal is equal to 0.
If so, it is not a proper number (probably) and you then should also return it to the standard game camera.
 
Level 12
Joined
Dec 11, 2014
Messages
662
You can do a substring check.
Technically, check if the substring of 1 to 5 of the entered chat string is equal to "-zoom" or "/zoom"
Then it wont care what you wrote after it.

Isn't that already in the trigger?

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Substring((Entered chat string), 1, 5)) Equal to -zoom
    • Then - Actions
If you also want the feature to have it zoom to a parameter that you can fill in, then you have to reset the camera if the integer of the substring of the remainder of the string is equal to 0.

If it's equal to zero (-zoom 0) then this part of the trigger puts it to 500

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • tempReal Less than 500.00
    • Then - Actions
      • Camera - Set (Triggering player)'s camera Distance to target to 500.00 over 1.00 seconds
But WE sees <Empty string> and a space (" ") differently

Just took a look at the actual script and:
After "Set tempReal = (Real((Substring((Entered chat string), 7, (Length of (Entered chat string))))))"
You have to do a check if the tempReal is equal to 0.
If so, it is not a proper number (probably) and you then should also return it to the standard game camera.

0 is a number that the player would put in(Which is a number less than 500), and then again the above trigger would put it to 500.

Edit: I might have a solution
Edit2: The solution isn't working because 1 space and 2 spaces are 2 different things. And it sees nothing as 0
 
Make a comparison if "Entered Chat String Equals "-zoom".
If it does then set the cam to default values.

If not, that does mean the string is longer then just "-zoom".
In this case you convert the rest of the string to an "real" and put it
as the cam value. If it is a valid value it will be set correct, but if it
is emptry spaces, or random characters, it will return 0, and so become 500 in your system.
 
Level 12
Joined
Dec 11, 2014
Messages
662
Make a comparison if "Entered Chat String Equals "-zoom".
If it does then set the cam to default values.

Doesn't that mean that whatever the player types in will make it go to the default value, since it isn't "-zoom"
Edit: I am looking for a way for when it returns 0 ,that it doesn't set it to 500. But 1 space and 2 spaces (etc) are treated differently
Edit2: Is there a way to see if it contains a thing within itself? Like check if: 6 to (leng of chatstring) has 2 or more spaces?
Yay 200th post
 
Level 12
Joined
Dec 11, 2014
Messages
662
I read it again. I understand now.
The problem is that if you type 0 and if you put a space it will behave the same, while it shouldn't.
Putting a 0 should put you to 500, and putting a space should put you to default cam. But it sees a space as a 0(When setting tempReal), so it always puts you to 500.

Best thing would be if there was a way to see if it contains a thing within itself? Like check if: 6 to (leng of chatstring) has 2 or more spaces, but it can't because it will see spaces the same as 0.
 
Well you can loop through the rest of the string and compare each character.
This way you can ensure that the substring contains only " " (spaces).
If this is the case you would also set the cam to default.

But this is imo too much work.
I would simply only set to default if the user writes exactly "-zoom" and
else I would convert the rest of the string and use it as cam value.
I would not care that it sets it to "500" in case the user writes "-zoom " with 8 spaces.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
But it sees a space as a 0(When setting tempReal), so it always puts you to 500.
First things first... you have to realize what you are attempting to do.
You have a string (a character sequence) that can contain letters from a to z, upper case letters of the same, special characters like a question mark, brackets, dots, commas, stars, plusses, dashes, etc, etc, etc... ow and numbers.

You try to convert a part of the string to a number.
"12345" is a proper number and gets converted to 12345
" 12345" is NOT a proper number so it will return the default or null value... for an integer/real, that is 0
So 0 is not the same as spaces, however, you will get the same results.
In substrings converted to integers/reals, 0 should in that case be an exception or you should do ascii checking... which can get really heavy in WC3.

But yes, there is no reason to write "/zoom " instead of "/zoom"... so dont make something for it to act the same. :D
 
Status
Not open for further replies.
Top