Tutorial Make Units Slide

Ryuu

I am back with Chocolate (:
Reaction score
64
Flare's GUI MUI method is used.

GUI
First off, define which event you need. Will it be when you cast a spell and you slide to the target point? In this tutorial I'll be using the 'starts the effect of an ability' event.

Trigger:
  • Events
    • Unit - A unit Starts the effect of an ability

The condition below checks if the unit casts the 'slide' spell.

Trigger:
  • Conditions
    • (Ability being cast) Equal to Slide

So now that you initialized the trigger, we got to start with the core part - the actions.

This is what your trigger should look like for the time being:

Trigger:
  • Slide Init
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Slide
    • Actions

First off, we need to set variables to use them for later. These variables are needed:

1. CustomValue (Integer Non-array Variable)
2. SlidePoint (Point Array Variable)
3. Slider (Unit Array Variable)
4. SlideOffset (Point Array Variable)
5. UnitGroup (Unit Group Non-array Variable)
6. TmpInteger (Integer Non-array Variable)
7. MovedRange (Real Array Variable)
8. TargetPoint (Point Array Variable)
9. StartPoint (Point Array Variable)​

Usually after we initialize variables, we set them in the trigger. However in this case, since we are doing a MUI sliding, we got initialize the MUI section first. The following action checks if the CustomValue variable reaches 100; if it does reach 100 or higher, it recycles the indices so that the spell actually becomes MUI.

Trigger:
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • CustomValue Less than 100
      • Then - Actions
        • Set CustomValue = (CustomValue + 1)
      • Else - Actions
        • Set CustomValue = 1


Then we set the variables. Notice in the following code that I use CustomValue as the index for our array variables. This fulfills the purpose of having a CustomValue variable, making our spell MUI.

Trigger:
  • Actions
    • Set Slider[CustomValue] = (Triggering unit)
    • Set StartPoint[CustomValue] = (Position of Slider[CustomValue])
    • Set SlidePoint[CustomValue] = (Position of Slider[CustomValue])
    • Set TargetPoint[CustomValue] = (Target point of ability being cast)

Now that we set our variables, we need to give one of our units the custom value CustomValue. This also fulfills the purpose of making our spell MUI. However do realise that you don't have to have a model-less dummy unit for our spell. All we need is a peasant. I rather you choose the frog.

Also, if you don't want our unit to be seen, you can specify a hidden region in our map or just give our unit no model.

Trigger:
  • Actions
    • Unit - Create 1 Frog (No model) for (Owner of Slider[CustomValue]) at SlidePoint[CustomValue] facing Default building facing degrees

Next we need to give him the custom value, and add him to our unit group.

Trigger:
  • Actions
    • Unit - Set the custom value of (Last created unit) to CustomValue
    • Unit Group - Add (Last created unit) to UnitGroup

The last action, simply removing leaks.

Trigger:
  • Custom script: call RemoveLocation(udg_SlidePoint[udg_CustomValue])

We're done for this initialization trigger.
This is what your trigger should look like:

Trigger:
  • Slide Init
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Slide
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CustomValue Less than 100
        • Then - Actions
          • Set CustomValue = (CustomValue + 1)
        • Else - Actions
          • Set CustomValue = 1
      • Set Slider[CustomValue] = (Triggering unit)
      • Set StartPoint[CustomValue] = (Position of Slider[CustomValue])
      • Set SlidePoint[CustomValue] = (Position of Slider[CustomValue])
      • Set TargetPoint[CustomValue] = (Target point of ability being cast)
      • Unit - Create 1 Frog for (Owner of Slider[CustomValue]) at SlidePoint[CustomValue] facing Default building facing degrees
      • Unit - Set the custom value of (Last created unit) to CustomValue
      • Unit Group - Add (Last created unit) to UnitGroup
      • Custom script: call RemoveLocation(udg_SlidePoint[udg_CustomValue])

Now that we're done with our initialization trigger, it's time we really go in to our core trigger. Create a new trigger, with the event:

Trigger:
  • Events
    • Time - Every 0.03 seconds of game time

You can change the above value to your liking. However don't go above 0.04, it will be quite unrealistic.

Next off we need to specify the conditions. The following condition checks if anyone even cast the 'Slide' spell. Because if this trigger is running unused for a long period, the game might get laggy.

Trigger:
  • Conditions
    • CustomValue Greater than 0

Now the actions. Before doing anything we need to use the ForGroup call.
Translated to GUI is this:

Trigger:
  • Actions
    • Unit Group - Pick every unit in UnitGroup and do (Actions)
      • Loop - Actions

The following action is probably useless but it can save you a lot of time. Instead of referring back to '(Custom value of (Picked unit))' for the entire trigger, you can just refer back to the TmpInteger variable.

Trigger:
  • Actions
    • Set TmpInteger = (Custom value of (Picked unit))

The following action checks if the slider is dead. Because we don't want sliding corpses.

Trigger:
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Slider[TmpInteger] is dead) Equal to True
      • Then - Actions
        • Unit - Remove (Picked unit) from the game
      • Else - Actions

Under 'Else - Actions', set the following variables. The following actions are 'setups' for the main action. The '15' in the second action is the speed of sliding. Basically it moves every 15 units per 0.03 second.

Trigger:
  • Actions
    • Set SlidePoint[TmpInteger] = (Position of Slider[TmpInteger])
    • Set SlideOffset[TmpInteger] = (SlidePoint[TmpInteger] offset by 15.00 towards (Angle from SlidePoint[TmpInteger] to TargetPoint[TmpInteger]) degrees)

The following actions check if the unit has reached its point. There are also leak removals because we are going to recycle the variables, hence we can't leave any of them lying around.

Trigger:
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • MovedRange[TmpInteger] Less than (Distance between StartPoint[TmpInteger] and TargetPoint[TmpInteger])
      • Then - Actions
        • Unit - Move Slider[TmpInteger] instantly to SlideOffset[TmpInteger]
        • Set MovedRange[TmpInteger] = (MovedRange[TmpInteger] + 15.00)
        • Custom script: call RemoveLocation(udg_SlidePoint[udg_TmpInteger])
        • Custom script: call RemoveLocation(udg_SlideOffset[udg_TmpInteger])
      • Else - Actions
        • Unit - Remove (Picked unit) from the game
        • Unit - Order Slider[TmpInteger] to Stop
        • Set Slider[TmpInteger] = No unit

Getting out of the If/Then/Else, we need to remove the leaks.

Trigger:
  • Actions
    • Custom script: call RemoveLocation(udg_SlidePoint[udg_TmpInteger])
    • Custom script: call RemoveLocation(udg_SlideOffset[udg_TmpInteger])
    • Custom script: call RemoveLocation(udg_StartPoint[udg_TmpInteger])
    • Custom script: call RemoveLocation(udg_TargetPoint[udg_TmpInteger])


That's it! You're done with your GUI sliding.
Your second trigger should look like this:

Trigger:
  • Slide
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
      • CustomValue Greater than 0
    • Actions
      • Unit Group - Pick every unit in UnitGroup and do (Actions)
        • Loop - Actions
          • Set TmpInteger = (Custom value of (Picked unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Slider[TmpInteger] is dead) Equal to True
            • Then - Actions
              • Unit - Remove (Picked unit) from the game
            • Else - Actions
              • Set SlidePoint[TmpInteger] = (Position of Slider[TmpInteger])
              • Set SlideOffset[TmpInteger] = (SlidePoint[TmpInteger] offset by 15.00 towards (Angle from SlidePoint[TmpInteger] to TargetPoint[TmpInteger]) degrees)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • MovedRange[TmpInteger] Less than (Distance between StartPoint[TmpInteger] and TargetPoint[TmpInteger])
                • Then - Actions
                  • Unit - Move Slider[TmpInteger] instantly to SlideOffset[TmpInteger]
                  • Set MovedRange[TmpInteger] = (MovedRange[TmpInteger] + 15.00)
                  • Custom script: call RemoveLocation(udg_SlidePoint[udg_TmpInteger])
                  • Custom script: call RemoveLocation(udg_SlideOffset[udg_TmpInteger])
                • Else - Actions
                  • Unit - Remove (Picked unit) from the game
                  • Unit - Order Slider[TmpInteger] to Stop
                  • Set Slider[TmpInteger] = No unit
              • Custom script: call RemoveLocation(udg_SlidePoint[udg_TmpInteger])
              • Custom script: call RemoveLocation(udg_SlideOffset[udg_TmpInteger])
              • Custom script: call RemoveLocation(udg_StartPoint[udg_TmpInteger])
              • Custom script: call RemoveLocation(udg_TargetPoint[udg_TmpInteger])

GUI sliding triggers
Code:
Slide Init
    Events
        Unit - A unit Starts the effect of an ability
    Conditions
        (Ability being cast) Equal to Slide 
    Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                CustomValue Less than 100
            Then - Actions
                Set CustomValue = (CustomValue + 1)
            Else - Actions
                Set CustomValue = 1
        Set Slider[CustomValue] = (Triggering unit)
        Set StartPoint[CustomValue] = (Position of Slider[CustomValue])
        Set SlidePoint[CustomValue] = (Position of Slider[CustomValue])
        Set TargetPoint[CustomValue] = (Target point of ability being cast)
        Unit - Create 1 Frog for (Owner of Slider[CustomValue]) at SlidePoint[CustomValue] facing Default building facing degrees
        Unit - Set the custom value of (Last created unit) to CustomValue
        Unit Group - Add (Last created unit) to UnitGroup
        Custom script:   call RemoveLocation( udg_SlidePoint[udg_CustomValue] )

Code:
Slide
    Events
        Time - Every 0.03 seconds of game time
    Conditions
        CustomValue Greater than 0
    Actions
        Unit Group - Pick every unit in UnitGroup and do (Actions)
            Loop - Actions
                Set TmpInteger = (Custom value of (Picked unit))
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        (Slider[TmpInteger] is dead) Equal to True
                    Then - Actions
                        Unit - Remove (Picked unit) from the game
                    Else - Actions
                        Set SlidePoint[TmpInteger] = (Position of Slider[TmpInteger])
                        Set SlideOffset[TmpInteger] = (SlidePoint[TmpInteger] offset by 15.00 towards (Angle from SlidePoint[TmpInteger] to TargetPoint[TmpInteger]) degrees)
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                MovedRange[TmpInteger] Less than (Distance between StartPoint[TmpInteger] and TargetPoint[TmpInteger])
                            Then - Actions
                                Unit - Move Slider[TmpInteger] instantly to SlideOffset[TmpInteger]
                                Set MovedRange[TmpInteger] = (MovedRange[TmpInteger] + 15.00)
                                Custom script:   call RemoveLocation(udg_SlidePoint[udg_TmpInteger])
                                Custom script:   call RemoveLocation(udg_SlideOffset[udg_TmpInteger])
                            Else - Actions
                                Unit - Remove (Picked unit) from the game
                                Unit - Order Slider[TmpInteger] to Stop
                                Set Slider[TmpInteger] = No unit
                        Custom script:   call RemoveLocation(udg_SlidePoint[udg_TmpInteger])
                        Custom script:   call RemoveLocation(udg_SlideOffset[udg_TmpInteger])
                        Custom script:   call RemoveLocation(udg_StartPoint[udg_TmpInteger])
                        Custom script:   call RemoveLocation(udg_TargetPoint[udg_TmpInteger])
 

UndeadDragon

Super Moderator
Reaction score
447
I have no guarantee the vJass one works.

Maybe you should check that before posting it :p

A lengthy tutorial you have made here. I am sure that the many people who ask questions about "How do I make a unit slide" will be able to find out using this tutorial.
 

Ryuu

I am back with Chocolate (:
Reaction score
64
I have no guarantee over that one because I haven't tested it myself. Or rather I had no chance to test it.
 

Flare

Stops copies me!
Reaction score
662
Code:
# Set StartPoint[CustomValue] = (Position of Slider[CustomValue])
# Set SlidePoint[CustomValue] = StartPoint[CustomValue]
What's the point in that? Also, when you do
Code:
Custom script: call RemoveLocation(udg_SlidePoint[udg_CustomValue])
You're also destroying StartPoint[CustomValue], since you're destroying the location that SlidePoint is pointing to, and that location is StartPoint
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
610
You should test anything before making a tutorial for ANYTHING!

fyi - that's a bad way of making a unit slide in vJASS refer to your JassHelper manual for more information :p
 

Ryuu

I am back with Chocolate (:
Reaction score
64
The vJass part was made to the extent of my knowledge. However I will either test it later or tomorrow so it shouldn't be so bad.

Flare
I didn't know that, thanks. Fixed.​
 

saw792

Is known to say things. That is all.
Reaction score
280
Wow umm... ok then.

Maybe you should just skip the vJASS part for now, since anybody who understands it doesn't need it, and people who don't shouldn't be learning that way (unoptimized, inefficient, BJ-filled, UnitUserData-hogging tripe). No offence intended towards you, of course, I just think it's better to stick with what you know well, your GUI system.

The first thing to do would be to check through all your GUI code and make sure it works properly, fix up a couple of things that have been mentioned already, and then work on the vJASS. Don't use the same method you would use in GUI for vJASS, since then there is absolutely no advantage in using vJASS at all. Sooda's method is not applicable at all for this situation. You want an attachment system and a timer callback to do the work for you and keep things MUI.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top