Changing Terrain in specific ways.

LiveSsenkrad

Member
Reaction score
3
I have this map in mind where the player builds his pathing for the creeps him/herself, but I want it to work like this:
  • A player builds a point where the terrain starts changing.
  • The player builds another one that must be either vertical or horizontal to the point built. (Scripting help will also be required there)
  • Then the terrain between the two points change to a unbuildable terrain
This then continues on 'till the player reaches the end with his maze. (There will be a limit to the length, which I'll also need help with).

This is only an idea, but I'd really like to go through with this.. Any suggestions ect would be appreciated =)
 

Moridin

Snow Leopard
Reaction score
144
I have a way this could work. Though the second step of this would be the most complicated to trigger.

Essentially, in the beginning, give the player a unit called "The builder" or somesuch. Give "the builder" (now on referred to as tb) 3 abilities. Start point, End point, Create path. The first two abilities are target point abilities that do nothing. The third ability is a no target ability that does nothing.

So essentially you trigger it such that, when tb uses Start point, you save the point he targets in a variable (let's call this Point_Start). This variable is of type point (in GUI) or location (in JASS).

This is what is slightly complex. Once he has a start point, the end point should be vertical or horizontal according to your rules. So what you can do it, save the point he targets with End point ability, and then check to see if it's closer to the horizontal line or vertical line. Whichever one is closer you equalize the coordinates to that line and then save the point.

Graphically:

He targets start point (labeled S)

Code:
X  X  X  X  X  X  X
X  X  X  X  X  X  X
X  X  X  X  X  X  X
X  X  X  X  X  X  X
X  X  X  X  X  X  X
X  [COLOR="Red"]S[/COLOR]  X  X  X  X  X
X  X  X  X  X  X  X

Then when he targets end point, you have the two lines of Start point which are:

Code:
X  |  X  X  X  X  X
X  |  X  X  X  X  X
X  |  X  X  X  X  X
X  |  X  X  X  X  X
X  |  X  X  X  X  X
-- [COLOR="Red"]S[/COLOR]  -  --  --  -  --
X  |  X  X  X  X  X

So you check if it's closer to which line, and equalise the corresponding X or Y coordinate to match that line (cause no one will ever be able to get an exact horizontal line or vertical line by themselves)

So once you get your End point:

Code:
X  X  X  X  X  X  X
X  [COLOR="Cyan"]E[/COLOR]  X  X  X  X  X
X  X  X  X  X  X  X
X  X  X  X  X  X  X
X  X  X  X  X  X  X
X  [COLOR="Red"]S[/COLOR]  X  X  X  X  X
X  X  X  X  X  X  X

You use ability "Create path" which is just a simple triggered for loop that keeps changing the terrain between point Start and point End to a different, unbuildable terrain.

Code:
X  X  X  X  X  X  X
X  [COLOR="DeepSkyBlue"]P[/COLOR]  X  X  X  X  X
X  [COLOR="DeepSkyBlue"]P[/COLOR]  X  X  X  X  X
X  [COLOR="DeepSkyBlue"]P[/COLOR]  X  X  X  X  X
X  [COLOR="DeepSkyBlue"]P[/COLOR]  X  X  X  X  X
X  [COLOR="DeepSkyBlue"]P[/COLOR]  X  X  X  X  X
X  X  X  X  X  X  X

And then the process repeats.
 

LiveSsenkrad

Member
Reaction score
3
You grasp the concept perfectly =) Although I would rather use 2 abilities, and let the changing of terrain be automatic for when the second building is built.

But I never thought of using the X, Y values, but now it seems a bit clearer, I will quickly start working on it and come back with any issues.

Edit 1: Okay I've started with it, but it's not easy because the X, Y values needs a big margin, for instance 40 units, and I can't find loop coding anywhere, any help would be appreciated.

Edit 2: Found loop coding, but the below coding is still an issue, help will be appreciated. =)

Just basic coding so far, nothing really intense, but I'm looking in this direction.

Trigger:
  • Start point
    • Events
      • Unit - A unit Begins channeling an ability
    • Conditions
      • (Ability being cast) Equal to Create point (Neutral Hostile)
    • Actions
      • Set Point[1] = (Target point of ability being cast)
      • Unit - Create 1 XY (Level 1) for Player 1 (Red) at (Target point of ability being cast) facing Default building facing degrees
      • Set X[1] = (X of Point[1])
      • Set Y[1] = (Y of Point[1])
      • Wait 10.00 seconds
      • Unit Group - Pick every unit in Checker and do (Actions)
        • Loop - Actions
          • Unit - Remove (Picked unit) from the game


Trigger:
  • Second point
    • Events
      • Unit - A unit Begins channeling an ability
    • Conditions
      • (Ability being cast) Equal to Create Second point (Neutral Hostile 1)
    • Actions
      • Set X[2] = (X of (Target point of ability being cast))
      • Set Y[2] = (Y of (Target point of ability being cast))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • X[1] Equal to X[2]
              • Y[1] Equal to Y[2]
        • Then - Actions
          • Unit - Create 1 Point for Player 1 (Red) at (Target point of ability being cast) facing Default building facing degrees
          • Set Point[2] = (Target point of ability being cast)
        • Else - Actions
 

Moridin

Snow Leopard
Reaction score
144
Alright, I'm not sure how new you are at GUI code but here's a few things you need to know:

1) Instead of the Event:

Unit - A unit Begins channelling an ability

use:

Unit - A unit Starts the effect of an ability

2) To use loops, look under the action: For loop integer A, integer B, etc. These are basic for loops.

3) Be careful when using waits. Many values like (Target unit of ability being cast) and (last created unit), etc get cleared after a wait of a certain length. That means that you will most probably have to use variables for everything if you use waits in your trigger.

Note that it isn't impossible using waits, or even bad in any way. It just makes some things not work the way they should, so if you're not aware of what those things are then you should be careful using them.

As for your triggers: (If you don't understand them, ask and I shall explain)

Trigger:
  • Start Point
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Start Point -> I'm using my own ability here
    • Actions
      • Set Point[1] = (Target point of ability being cast)
      • Set X[1] = (X of Point[1])
      • Set Y[1] = (Y of Point[1])
      • Set Start_Point_Set = True -> Boolean Variable


Trigger:
  • End Point
    • Events
      • Unit - A unit starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to End point
    • Actions
      • If (All conditions are true) then do (then actions) else do (else actions)
        • If - Conditions
          • Start_Point_Set = True
        • then - Actions
          • Set X[2] = (X of (Target point of ability being cast))
          • Set Y[2] = (Y of (Target unit of ability being cast))
          • Set Difference[1] = Abs(X[2] - X[1])
          • Set Difference[2] = Abs(Y[2] - Y[1])
          • If (All conditions are true) then do (then actions) else do (else actions)
            • If - Conditions
              • Difference[1] Less than or Equal to Difference[2]
            • Then - Actions
              • Set X[2] = X[1]
              • Set Point[2] = Point(X[2], Y[2])
            • Else - Actions
              • Set Y[2] = Y[1]
              • Set Point[2] = Point(X[2], Y[2])
        • else - Actions
          • Game - Display ("You haven't placed the Start Point yet!") to <whichever player>


Trigger:
  • Pathing
    • Events
      • Unit - A unit starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Create Path
    • Actions
      • If (All conditions are true) then do (then actions) else do (else actions)
        • If - Conditions
          • Difference[1] Less than or Equal to Difference[2]
        • Then - Actions
          • For each (Integer A) from Y[1] to Y[2] do Actions
          • Environment - Change terrain type at (Point(X[1], (Integer A)) to <Some unbuildable terrain type> using variation -1 in an area of size 1 and shape Circle
        • Else - Actions
          • For each (Integer A) from X[1] to X[2] do Actions
          • Environment - Change terrain type at (Point((Integer A), Y[1]) to <Some unbuildable terrain type> using variation -1 in an area of size 1 and shape Circle
      • Set Start_Point_Set = False


Note: Freehand.
 

mapguy

New Member
Reaction score
46
just a note.

you should not use waits, only timers.
because waits will count even if the game is paused, lagging, or if it is in a different speed.
 

LiveSsenkrad

Member
Reaction score
3
I'll check what you've done just now, the wait was just for a quick testing purpose to create some dummy units showing the X/Y places, but I did not know it affected abilities =)

Will edit this post as soon as I tried your suggestions =)

Edit 1: Okay I've got it right Moridin, even though I don't know what the f**k is going on there. But that is a problem to the next step, I need to have the position of the second point saved as the first point, so that it stays connected, I am going to try tinker there myself, but it'll involve removing the 'start point' ability because now I'm continuing on from the previous point. Will report soon =P
 

Moridin

Snow Leopard
Reaction score
144
Right. I'll explain what I've done then.

The Start point trigger is pretty straightforward. He casts an ability targeting a point. As long as the ability is "Start point" it saves the target point as well as the X and Y co-ords of that target point in X[1] and Y[1].

The End point trigger might be a bit confusing. So here I first check if the start point has been placed using the boolean variable I saved earlier. If it hasn't been placed, I can't equalise the second point to the horizontal / vertical line of the start point, so I need it placed first.

Once I've checked that Yes, it has been placed, I save the X and Y co-ords of this new point in X[2] and Y[2]. Then I check the differences, which is where you might be a bit confused. To better explain I'll give an example:

Code:
X | X X X X X X
X [COLOR="Red"]S[/COLOR] X X X X X X
X | X X X X X X
X | X X X X X X
X | X X X X X X
X | [COLOR="Magenta"]C[/COLOR] X X X X X
X | X X X X X X
X | X X X X X X

^ This is an 8x8 matrix which I will assume as the entire map. Point S is the Start Point. Point C is the "Target of End point". Point C is NOT the end point yet, because we don't know if it's horizontal / vertical to the start point. So the coordinates (assuming 0,0 is the bottom left corner) of these points are:

S = (2, 7)
C = (3, 3)

Now, just from looking at the matrix, we ourselves know that point C is closer to the Vertical line of point S. So it SHOULD be here: (Point E)

Code:
X X X X X X X X
X [COLOR="Red"]S[/COLOR] X X X X X X
X X X X X X X X
X X X X X X X X
X X X X X X X X
X [COLOR="Blue"]E[/COLOR] [COLOR="Magenta"]C[/COLOR] X X X X X
X X X X X X X X
X X X X X X X X

But we need to know how to get to that point. This is where the differences come in. Difference[1] is the difference between X co-ords of Points S and C. Difference[2] is the difference between the Y co-ords of S and C. So:

Difference[1] = 3 - 2 = 1
Difference[2] = 3 - 7 = 4

We take absolute values because distance is a scalar quantity. It has no direction. There's no such thing as negative distance.

So now we know that yes, Point C is close to the Vertical "Y" axis of point S. So we equalise the X coords while keeping the Y coords intact. Making X[2] = X[1] gives us the point (X[2], Y[2]) = (2, 3). Now we see that yes, this point is E, the correct end point.

It works the same way for the other horizontal axis.

So now for the third trigger it cycles between all the points on that line created by points S and E and changes the terrain.

Hope that helped.
 

LiveSsenkrad

Member
Reaction score
3
That clears things up a little bit, but it's still a bit buggy, I'm thinking of creating temporary terrain like:
Code:
X X X | X X X X
X X X | X X X X
X X X | X X X X
X X X | X X X X
- - - S - - - -
X X X | X X X X
X X X | X X X X
X X X | X X X X
Because players will not always get it close enough, then I'm thinking of conditioning the second point to a specific terrain, the one which will be temporary.
 

Moridin

Snow Leopard
Reaction score
144
It doesn't have to be close at all. It can anywhere and the system will automatically adjust it to one of the lines.

If you want to make a continuous track, you will need to alter the code somewhat. If you can't get how to, ask again and I'll see what I can do.

Edit: Oh and it would also be a good idea to create units with flashy models on both points so the player knows where the points are.
 

LiveSsenkrad

Member
Reaction score
3
Yeah there are some bugs though, but I can sort it out.

I've used the 'Select Hero' arrows just for now, but I just have tweak it a bit first and then I'll start on making it look good.

Edit 1: It doesn't seem to work if I put the second point anywhere, it only works if it's roughly in line with the X/Y axes, which I'm using a temporary terrain to guide the player

Edit 2: The 'terrain guide' doesn't seem to be working properly, it's somewhat off the point like:
Code:
X X X | X X X X
X X X | X X X X
X X X | X X X X
X X X | X X X X
- - - + - - - -
X X P | X X X X
X X X | X X X X
X X X | X X X X

It's just a rough version of the code, but it should work? The if statement is to stop the terrain, but I haven't gotten there yet.
Trigger:
  • Start point
    • Events
      • Unit - A unit Begins channeling an ability
    • Conditions
      • (Ability being cast) Equal to Create Start point (Neutral Hostile)
    • Actions
      • Set Point[1] = (Target point of ability being cast)
      • Unit - Create 1 XY (Level 1) for Player 1 (Red) at (Target point of ability being cast) facing Default building facing degrees
      • Set X[1] = (X of Point[1])
      • Set Y[1] = (Y of Point[1])
      • Set Startpoint = True
      • For each (Integer A) from 1 to 200, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Terrain type at (Point[1] offset by (X[1], (Real(((Integer A) x 15)))))) Equal to Sunken Ruins - Large Bricks
            • Then - Actions
            • Else - Actions
              • Environment - Change terrain type at (Point[1] offset by (X[1], ((Real((Integer A))) x 15.00))) to Sunken Ruins - Dark Grass using variation -1 in an area of size 1 and shape Circle
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Terrain type at (Point[1] offset by (X[1], (Real(((Integer A) x -15)))))) Equal to Sunken Ruins - Large Bricks
            • Then - Actions
            • Else - Actions
              • Environment - Change terrain type at (Point[1] offset by (X[1], ((Real((Integer A))) x -15.00))) to Sunken Ruins - Dark Grass using variation -1 in an area of size 1 and shape Circle
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Terrain type at (Point[1] offset by (((Real((Integer A))) x 15.00), Y[1]))) Equal to Sunken Ruins - Large Bricks
            • Then - Actions
            • Else - Actions
              • Environment - Change terrain type at (Point[1] offset by (((Real((Integer A))) x 15.00), Y[1])) to Sunken Ruins - Dark Grass using variation -1 in an area of size 1 and shape Circle
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Terrain type at (Point[1] offset by (((Real((Integer A))) x -15.00), Y[1]))) Equal to Sunken Ruins - Large Bricks
            • Then - Actions
            • Else - Actions
              • Environment - Change terrain type at (Point[1] offset by (((Real((Integer A))) x -15.00), Y[1])) to Sunken Ruins - Dark Grass using variation -1 in an area of size 1 and shape Circle
 
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