Undertale Yellow script viewer

← back to main script listing

gml_GlobalScript_scr_walk_npc_solid

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

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