Undertale Yellow script viewer

← back to main script listing

gml_GlobalScript_scr_walk_ai

(view raw script w/o annotations or w/e)
1
function scr_walk_ai
scr_walk_ai

function scr_walk_ai(argument0, argument1, argument2, argument3, argument4) //gml_Script_scr_walk_ai { dalv_walk_speed = argument3 condition_1 = false if (no_loop_destination_dalv == false) { var destination_x = abs(x - argument0) var destination_y = abs(y - argument1) var axis_override = argument4 if (axis_override == "x" || axis_override == "y") dalv_walk_axis = axis_override else { var result = sign(destination_x - destination_y) switch result { case 1: dalv_walk_axis = "x" break case -1: dalv_walk_axis = "y" break default: dalv_walk_axis = "y" } } dalv_walk_speed_x = (sign(argument0 - x)) * dalv_walk_speed dalv_walk_speed_y = (sign(argument1 - y)) * dalv_walk_speed no_loop_destination_dalv = true } if (x == argument0 && y == argument1) { npc_walking = false path_speed = 0 image_speed = 0 image_index = 0 return; } switch dalv_walk_axis { case "x": x_previous = x x += dalv_walk_speed_x if (abs(argument0 - x) < dalv_walk_speed && place_free(argument0, y) && (!(place_meeting(argument0, y, argument2)))) x = argument0 if (place_free(x, y) && (!(place_meeting(x, y, argument2))) && x_previous != argument0) { npc_walking = true image_speed = 0.2 if (dalv_walk_speed_x == (-dalv_walk_speed)) direction = 180 else if (dalv_walk_speed_x == dalv_walk_speed) direction = 0 } if ((!(place_free(x, y))) || place_meeting(x, y, argument2) || x_previous == argument0) { x = x_previous dalv_walk_axis = "y" return; } dalv_walk_speed_y = (sign(argument1 - y)) * dalv_walk_speed i = x + dalv_walk_speed_x j = y if (abs(argument0 - i) < dalv_walk_speed) i = argument0 while (j != argument1) { j += dalv_walk_speed_y if (abs(argument1 - j) < dalv_walk_speed) j = argument1 if ((!(place_free(i, j))) || place_meeting(i, j, argument2)) { condition_1 = true break } else continue } if (condition_1 == true) { while (i != argument0) { i += dalv_walk_speed_x j = y if (abs(argument0 - i) < dalv_walk_speed) i = argument0 while (j != argument1) { j += dalv_walk_speed_y if (abs(argument1 - j) < dalv_walk_speed) j = argument1 if (i == argument0 && j == argument1) return; else if ((!(place_free(i, j))) || place_meeting(i, j, argument2)) break else { if (j == argument1) return; continue ...
(argument0, argument1, argument2, argument3, argument4) //gml_Script_scr_walk_ai
2
{
3
    dalv_walk_speed = argument3
4
    condition_1 = false
5
    if (no_loop_destination_dalv == false)
6
    {
7
        var destination_x = abs(x - argument0)
8
        var destination_y = abs(y - argument1)
9
        var axis_override = argument4
10
        if (axis_override == "x" || axis_override == "y")
11
            dalv_walk_axis = axis_override
12
        else
13
        {
14
            var result = sign(destination_x - destination_y)
15
            switch result
16
            {
17
                case 1:
18
                    dalv_walk_axis = "x"
19
                    break
20
                case -1:
21
                    dalv_walk_axis = "y"
22
                    break
23
                default:
24
                    dalv_walk_axis = "y"
25
            }
26
27
        }
28
        dalv_walk_speed_x = (sign(argument0 - x)) * dalv_walk_speed
29
        dalv_walk_speed_y = (sign(argument1 - y)) * dalv_walk_speed
30
        no_loop_destination_dalv = true
31
    }
32
    if (x == argument0 && y == argument1)
33
    {
34
        npc_walking = false
35
        path_speed = 0
36
        image_speed = 0
37
        image_index = 0
38
        return;
39
    }
40
    switch dalv_walk_axis
41
    {
42
        case "x":
43
            x_previous = x
44
            x += dalv_walk_speed_x
45
            if (abs(argument0 - x) < dalv_walk_speed && place_free(argument0, y) && (!(place_meeting(argument0, y, argument2))))
46
                x = argument0
47
            if (place_free(x, y) && (!(place_meeting(x, y, argument2))) && x_previous != argument0)
48
            {
49
                npc_walking = true
50
                image_speed = 0.2
51
                if (dalv_walk_speed_x == (-dalv_walk_speed))
52
                    direction = 180
53
                else if (dalv_walk_speed_x == dalv_walk_speed)
54
                    direction = 0
55
            }
56
            if ((!(place_free(x, y))) || place_meeting(x, y, argument2) || x_previous == argument0)
57
            {
58
                x = x_previous
59
                dalv_walk_axis = "y"
60
                return;
61
            }
62
            dalv_walk_speed_y = (sign(argument1 - y)) * dalv_walk_speed
63
            i = x + dalv_walk_speed_x
64
            j = y
65
            if (abs(argument0 - i) < dalv_walk_speed)
66
                i = argument0
67
            while (j != argument1)
68
            {
69
                j += dalv_walk_speed_y
70
                if (abs(argument1 - j) < dalv_walk_speed)
71
                    j = argument1
72
                if ((!(place_free(i, j))) || place_meeting(i, j, argument2))
73
                {
74
                    condition_1 = true
75
                    break
76
                }
77
                else
78
                    continue
79
            }
80
            if (condition_1 == true)
81
            {
82
                while (i != argument0)
83
                {
84
                    i += dalv_walk_speed_x
85
                    j = y
86
                    if (abs(argument0 - i) < dalv_walk_speed)
87
                        i = argument0
88
                    while (j != argument1)
89
                    {
90
                        j += dalv_walk_speed_y
91
                        if (abs(argument1 - j) < dalv_walk_speed)
92
                            j = argument1
93
                        if (i == argument0 && j == argument1)
94
                            return;
95
                        else if ((!(place_free(i, j))) || place_meeting(i, j, argument2))
96
                            break
97
                        else
98
                        {
99
                            if (j == argument1)
100
                                return;
101
                            continue
102
                        }
103
                    }
104
                }
105
                dalv_walk_axis = "y"
106
                return;
107
            }
108
            break
109
        case "y":
110
            y_previous = y
111
            y += dalv_walk_speed_y
112
            if (abs(argument1 - y) < dalv_walk_speed && place_free(x, argument1) && (!(place_meeting(x, argument1, argument2))))
113
                y = argument1
114
            if (place_free(x, y) && (!(place_meeting(x, y, argument2))) && y_previous != argument1)
115
            {
116
                npc_walking = true
117
                image_speed = 0.2
118
                if (dalv_walk_speed_y == (-dalv_walk_speed))
119
                    direction = 90
120
                else if (dalv_walk_speed_y == dalv_walk_speed)
121
                    direction = 270
122
            }
123
            if ((!(place_free(x, y))) || place_meeting(x, y, argument2) || y_previous == argument1)
124
            {
125
                y = y_previous
126
                dalv_walk_axis = "x"
127
                return;
128
            }
129
            dalv_walk_speed_x = (sign(argument0 - x)) * dalv_walk_speed
130
            i = x
131
            j = y + dalv_walk_speed_y
132
            if (abs(argument1 - j) < dalv_walk_speed)
133
                j = argument1
134
            while (i != argument0)
135
            {
136
                i += dalv_walk_speed_x
137
                if (abs(argument0 - i) < dalv_walk_speed)
138
                    i = argument0
139
                if ((!(place_free(i, j))) || place_meeting(i, j, argument2))
140
                {
141
                    condition_1 = true
142
                    break
143
                }
144
                else
145
                    continue
146
            }
147
            if (condition_1 == true)
148
            {
149
                while (j != argument1)
150
                {
151
                    i = x
152
                    j += dalv_walk_speed_y
153
                    if (abs(argument1 - j) < dalv_walk_speed)
154
                        j = argument1
155
                    while (i != argument0)
156
                    {
157
                        i += dalv_walk_speed_x
158
                        if (abs(argument0 - i) < dalv_walk_speed)
159
                            i = argument0
160
                        if (i == argument0 && j == argument1)
161
                            return;
162
                        else if ((!(place_free(i, j))) || place_meeting(i, j, argument2))
163
                            break
164
                        else
165
                        {
166
                            if (i == argument0)
167
                                return;
168
                            continue
169
                        }
170
                    }
171
                }
172
                dalv_walk_axis = "x"
173
                return;
174
            }
175
            break
176
    }
177
178
    if (x == argument0 && y == argument1)
179
    {
180
        npc_walking = false
181
        path_speed = 0
182
        image_speed = 0
183
        image_index = 0
184
    }
185
}