1 | -- Create the trigger |
---|
2 | trigger = ScriptTrigger() |
---|
3 | trigger:setName("guardtrigger") |
---|
4 | trigger:setScript("guard.lua") |
---|
5 | trigger:setFunction("tick") |
---|
6 | trigger:setActiveOnCreation(true) |
---|
7 | |
---|
8 | -- Get objects from orxonox |
---|
9 | thisscript:addObject("GenericNPC","guard") |
---|
10 | thisscript:addObject("FPSPlayer", "Player") |
---|
11 | |
---|
12 | -- Global Variables |
---|
13 | walkingRouteOne = true -- True if thestranger is walking route one |
---|
14 | exitPositionReached = false |
---|
15 | playerInLock = false |
---|
16 | hangarReached = false |
---|
17 | guardStopped = false |
---|
18 | gotoSpaceship = false |
---|
19 | |
---|
20 | height = 34 |
---|
21 | |
---|
22 | -- Returns the distance between (x1,x2,x3) and (y1,y2,y3) |
---|
23 | function dist( x1,x2,x3, y1,y2,y3 ) |
---|
24 | return math.sqrt( (x1-y1)^2 + (x2-y2)^2 + (x3-y3)^2 ) |
---|
25 | end |
---|
26 | |
---|
27 | |
---|
28 | function observePlayer() |
---|
29 | |
---|
30 | guardX = guard:getAbsCoorX() |
---|
31 | guardY = guard:getAbsCoorY() |
---|
32 | guardZ = guard:getAbsCoorZ() |
---|
33 | |
---|
34 | playerX = Player:getAbsCoorX() |
---|
35 | playerY = Player:getAbsCoorY() |
---|
36 | playerZ = Player:getAbsCoorZ() |
---|
37 | |
---|
38 | |
---|
39 | distance = dist( guardX,guardY,guardZ,playerX, playerY, playerZ) |
---|
40 | |
---|
41 | if distance > 250 and hangarRouteProgrammed and not guardStopped and not gotoSpaceship then |
---|
42 | guard:stop() |
---|
43 | guardStopped = true |
---|
44 | end |
---|
45 | |
---|
46 | if distance < 250 and hangarRouteProgrammed and guardStopped and not gotoSpaceship then |
---|
47 | guard:resume() |
---|
48 | guardStopped = false |
---|
49 | end |
---|
50 | |
---|
51 | if dist( playerX,playerY,playerZ,167.361526,29,483.163818 ) < 150 then |
---|
52 | playerInLock = true |
---|
53 | end |
---|
54 | |
---|
55 | if dist( guardX,guardY,guardZ,772.325012, height, -1500.850708) < 200 then |
---|
56 | gotoSpaceship = true |
---|
57 | end |
---|
58 | |
---|
59 | |
---|
60 | end |
---|
61 | |
---|
62 | routeOneProgrammed = false |
---|
63 | function walkRouteOne(timestep) |
---|
64 | if not routeOneProgrammed then |
---|
65 | guard:walkTo( 266.396362, height, 241.398544) |
---|
66 | guard:walkTo( 254.577255, height, 241.159897) |
---|
67 | guard:walkTo( 221.120651, height, 240.484360) |
---|
68 | guard:walkTo( 187.732651, height, 239.810196) |
---|
69 | guard:walkTo( 165.661865, height, 239.364563) |
---|
70 | guard:walkTo( 148.642044, height, 239.020889) |
---|
71 | guard:walkTo( 128.012802, height, 238.604340) |
---|
72 | guard:walkTo( 65.664688, height, 237.345383) |
---|
73 | guard:walkTo( 30.099592, height, 236.627243) |
---|
74 | guard:walkTo( -14.031926, height, 236.483414) |
---|
75 | guard:walkTo( -52.224205, height, 241.776978) |
---|
76 | guard:walkTo( -83.528168, height, 245.757629) |
---|
77 | guard:walkTo( -98.730980, height, 247.394043) |
---|
78 | guard:walkTo( -111.666504, height, 246.585648) |
---|
79 | guard:walkTo( -111.666504, height, 246.585648) |
---|
80 | guard:walkTo( -114.805542, height, 246.144440) |
---|
81 | guard:walkTo( -119.267967, height, 245.360168) |
---|
82 | guard:walkTo( -138.284515, height, 239.281021) |
---|
83 | guard:walkTo( -146.166840, height, 234.512054) |
---|
84 | guard:walkTo( -157.210480, height, 222.620941) |
---|
85 | guard:walkTo( -158.519867, height, 219.674301) |
---|
86 | guard:walkTo( -158.519867, height, 219.674301) |
---|
87 | guard:walkTo( -158.478958, height, 213.490570) |
---|
88 | guard:walkTo( -158.478958, height, 213.490570) |
---|
89 | guard:walkTo( -155.965332, height, 210.303101) |
---|
90 | guard:walkTo( -150.804489, height, 203.959869) |
---|
91 | guard:walkTo( -148.853012, height, 201.561295) |
---|
92 | guard:walkTo( -145.451157, height, 197.554382) |
---|
93 | guard:walkTo( -143.694107, height, 196.373535) |
---|
94 | guard:walkTo( -139.281479, height, 193.407990) |
---|
95 | guard:walkTo( -137.526047, height, 192.228226) |
---|
96 | guard:walkTo( -103.046753, height, 182.510071) |
---|
97 | guard:runTo( -14.992087, height, 181.910767) |
---|
98 | guard:runTo( 46.347664, height, 181.493317) |
---|
99 | guard:runTo( 86.343376, height, 181.221130) |
---|
100 | guard:runTo( 124.465179, height, 194.251617) |
---|
101 | guard:runTo( 136.548996, height, 219.682953) |
---|
102 | guard:runTo( 145.162140, height, 244.268982) |
---|
103 | guard:runTo( 149.328720, height, 256.993256) |
---|
104 | guard:runTo( 162.649582, height, 268.181732) |
---|
105 | |
---|
106 | routeOneProgrammed = true |
---|
107 | end |
---|
108 | |
---|
109 | if guard:finalGoalReached() then |
---|
110 | return false |
---|
111 | end |
---|
112 | |
---|
113 | return true |
---|
114 | end |
---|
115 | |
---|
116 | |
---|
117 | exitRouteProgrammed = false |
---|
118 | function goToExitPosition(timestep) |
---|
119 | |
---|
120 | if not exitRouteProgrammed then |
---|
121 | --guard:runTo( 162.096558, height, 274.944366) |
---|
122 | --guard:runTo( 161.519516, height, 286.673370) |
---|
123 | --guard:runTo( 161.098618, height, 295.228699) |
---|
124 | --guard:runTo( 160.568466, height, 306.004486) |
---|
125 | guard:runTo( 160.151169, height, 314.486572) |
---|
126 | guard:runTo( 159.416641, height, 324.925232) |
---|
127 | guard:walkTo( 158.700073, height, 335.108154) |
---|
128 | guard:walkTo( 157.943298, height, 345.862610) |
---|
129 | guard:walkTo( 157.418381, height, 356.131256) |
---|
130 | guard:walkTo( 156.908035, height, 366.115417) |
---|
131 | guard:walkTo( 156.940308, height, 377.467712) |
---|
132 | guard:walkTo( 156.965408, height, 386.287933) |
---|
133 | guard:walkTo( 156.924698, height, 394.296417) |
---|
134 | guard:walkTo( 156.816116, height, 401.564911) |
---|
135 | guard:walkTo( 156.147583, height, 446.314850) |
---|
136 | guard:walkTo( 155.145660, height, 515.473877) |
---|
137 | guard:walkTo( 148.450058, height, 524.572571) |
---|
138 | guard:walkTo( 135.599609, height, 533.407166) |
---|
139 | guard:walkTo( 119.772217, height, 539.609192) |
---|
140 | guard:walkTo( 108.926720, height, 537.174927) |
---|
141 | guard:walkTo( 100.885788, height, 524.737793) |
---|
142 | guard:walkTo( 99.870834, height, 512.540100) |
---|
143 | guard:walkTo( 108.219215, height, 502.064178) |
---|
144 | |
---|
145 | exitRouteProgrammed = true |
---|
146 | end |
---|
147 | |
---|
148 | if guard:finalGoalReached() and playerInLock then |
---|
149 | return true |
---|
150 | end |
---|
151 | |
---|
152 | return false |
---|
153 | end |
---|
154 | |
---|
155 | |
---|
156 | hangarRouteProgrammed = false |
---|
157 | function goToHangar(timestep) |
---|
158 | |
---|
159 | if not hangarRouteProgrammed and playerInLock then |
---|
160 | |
---|
161 | guard:walkTo( 133.354797, height, 504.669128) |
---|
162 | guard:walkTo( 147.490158, height, 507.034393) |
---|
163 | guard:walkTo( 157.640610, height, 508.901001) |
---|
164 | guard:walkTo( 168.830688, height, 510.958710) |
---|
165 | guard:walkTo( 185.020630, height, 512.736206) |
---|
166 | guard:walkTo( 201.232452, height, 513.413818) |
---|
167 | guard:walkTo( 265.666138, height, 513.736023) |
---|
168 | guard:walkTo( 362.377960, height, 515.575806) |
---|
169 | guard:walkTo( 426.176392, height, 515.666748) |
---|
170 | guard:walkTo( 500.031677, height, 515.197266) |
---|
171 | guard:walkTo( 551.294250, height, 514.430237) |
---|
172 | guard:walkTo( 604.974731, height, 515.106323) |
---|
173 | guard:walkTo( 651.117920, height, 516.026550) |
---|
174 | guard:walkTo( 664.581909, height, 516.295227) |
---|
175 | guard:walkTo( 683.122803, height, 516.665100) |
---|
176 | guard:walkTo( 694.547485, height, 516.892944) |
---|
177 | guard:walkTo( 704.408569, height, 517.089539) |
---|
178 | guard:walkTo( 714.413208, height, 517.289185) |
---|
179 | guard:walkTo( 739.045288, height, 515.581970) |
---|
180 | guard:walkTo( 763.904541, height, 497.281738) |
---|
181 | guard:walkTo( 767.672791, height, 481.974457) |
---|
182 | guard:walkTo( 769.436951, height, 468.704559) |
---|
183 | guard:walkTo( 770.490967, height, 453.283386) |
---|
184 | guard:walkTo( 771.185303, height, 435.960114) |
---|
185 | guard:walkTo( 771.952820, height, 379.502045) |
---|
186 | guard:walkTo( 771.938293, height, 310.049042) |
---|
187 | guard:walkTo( 772.514526, height, 231.579498) |
---|
188 | guard:walkTo( 773.601074, height, 135.177933) |
---|
189 | guard:walkTo( 773.790771, height, 50.675163) |
---|
190 | guard:walkTo( 773.316162, height, -36.961666) |
---|
191 | guard:walkTo( 772.885986, height, -116.407944) |
---|
192 | guard:walkTo( 772.841309, height, -124.651726) |
---|
193 | guard:walkTo( 772.491333, height, -137.742279) |
---|
194 | guard:walkTo( 770.644775, height, -153.245926) |
---|
195 | guard:walkTo( 768.774414, height, -163.767120) |
---|
196 | guard:walkTo( 766.336426, height, -174.224228) |
---|
197 | guard:walkTo( 762.794128, height, -187.312271) |
---|
198 | guard:walkTo( 733.548279, height, -274.004791) |
---|
199 | guard:walkTo( 713.113647, height, -329.657959) |
---|
200 | guard:walkTo( 694.801819, height, -379.530243) |
---|
201 | guard:walkTo( 681.276062, height, -422.047028) |
---|
202 | guard:walkTo( 672.579102, height, -458.540985) |
---|
203 | guard:walkTo( 670.843384, height, -465.824615) |
---|
204 | guard:walkTo( 669.948364, height, -480.910645) |
---|
205 | guard:walkTo( 669.361511, height, -493.648529) |
---|
206 | guard:walkTo( 669.686829, height, -501.598572) |
---|
207 | guard:walkTo( 674.055664, height, -582.077637) |
---|
208 | guard:walkTo( 676.046387, height, -630.403809) |
---|
209 | guard:walkTo( 677.839050, height, -674.209534) |
---|
210 | guard:walkTo( 680.754944, height, -765.965515) |
---|
211 | guard:walkTo( 681.034180, height, -803.351135) |
---|
212 | guard:walkTo( 680.088806, height, -844.069031) |
---|
213 | guard:walkTo( 677.801514, height, -899.952148) |
---|
214 | guard:walkTo( 675.205627, height, -950.496460) |
---|
215 | guard:walkTo( 672.847778, height, -996.413574) |
---|
216 | guard:walkTo( 676.204041, height, -1043.556274) |
---|
217 | guard:walkTo( 691.304382, height, -1088.596558) |
---|
218 | guard:walkTo( 705.101318, height, -1128.320312) |
---|
219 | guard:walkTo( 720.476013, height, -1164.364380) |
---|
220 | guard:walkTo( 729.216797, height, -1183.948364) |
---|
221 | guard:walkTo( 740.145203, height, -1212.598267) |
---|
222 | guard:walkTo( 746.547363, height, -1238.340576) |
---|
223 | guard:walkTo( 756.866211, height, -1280.605347) |
---|
224 | guard:walkTo( 763.380554, height, -1314.622314) |
---|
225 | guard:walkTo( 768.731506, height, -1347.977539) |
---|
226 | guard:walkTo( 772.446655, height, -1381.641479) |
---|
227 | guard:walkTo( 772.721069, height, -1421.184937) |
---|
228 | guard:walkTo( 772.414734, height, -1457.349121) |
---|
229 | guard:walkTo( 772.803284, height, -1489.560913) |
---|
230 | |
---|
231 | guard:walkTo( 772.325012, height, -1500.850708) |
---|
232 | guard:walkTo( 772.325012, height, -1500.850708) |
---|
233 | guard:walkTo( 772.487854, height, -1508.028809) |
---|
234 | guard:walkTo( 774.761047, height, -1519.442139) |
---|
235 | guard:walkTo( 778.809204, height, -1525.292847) |
---|
236 | guard:walkTo( 783.482666, height, -1530.000610) |
---|
237 | guard:walkTo( 790.163269, height, -1536.350708) |
---|
238 | guard:walkTo( 797.713745, height, -1542.968018) |
---|
239 | guard:walkTo( 804.024475, height, -1548.390503) |
---|
240 | guard:walkTo( 810.316406, height, -1553.796875) |
---|
241 | guard:walkTo( 819.849731, height, -1561.323242) |
---|
242 | guard:walkTo( 826.676819, height, -1566.627197) |
---|
243 | guard:walkTo( 833.950928, height, -1572.278442) |
---|
244 | guard:walkTo( 840.587036, height, -1577.434082) |
---|
245 | guard:walkTo( 847.261230, height, -1582.458252) |
---|
246 | guard:walkTo( 852.104797, height, -1586.104370) |
---|
247 | guard:walkTo( 857.504944, height, -1590.169556) |
---|
248 | guard:walkTo( 861.696411, height, -1593.324829) |
---|
249 | guard:walkTo( 867.690613, height, -1597.837036) |
---|
250 | guard:walkTo( 874.808105, height, -1604.437378) |
---|
251 | guard:walkTo( 878.302429, height, -1608.333252) |
---|
252 | guard:walkTo( 884.001892, height, -1614.366211) |
---|
253 | guard:walkTo( 890.699646, height, -1621.398315) |
---|
254 | guard:walkTo( 895.391052, height, -1626.179688) |
---|
255 | guard:walkTo( 902.171509, height, -1633.090332) |
---|
256 | guard:walkTo( 906.807495, height, -1637.957764) |
---|
257 | guard:walkTo( 910.438599, height, -1641.770142) |
---|
258 | guard:walkTo( 915.626160, height, -1647.216797) |
---|
259 | guard:walkTo( 921.844727, height, -1653.745972) |
---|
260 | guard:walkTo( 928.565125, height, -1660.801636) |
---|
261 | guard:walkTo( 933.742004, height, -1666.236694) |
---|
262 | guard:walkTo( 938.956543, height, -1671.711182) |
---|
263 | guard:walkTo( 942.160706, height, -1675.745972) |
---|
264 | guard:walkTo( 947.547302, height, -1681.952881) |
---|
265 | guard:walkTo( 951.732483, height, -1687.077759) |
---|
266 | guard:walkTo( 957.284851, height, -1693.876709) |
---|
267 | guard:walkTo( 962.786438, height, -1700.614990) |
---|
268 | guard:walkTo( 966.177246, height, -1705.151245) |
---|
269 | guard:walkTo( 970.221619, height, -1710.886230) |
---|
270 | guard:walkTo( 974.503113, height, -1717.243896) |
---|
271 | guard:walkTo( 977.332153, height, -1722.064087) |
---|
272 | guard:walkTo( 981.496887, height, -1729.391357) |
---|
273 | guard:walkTo( 986.814148, height, -1738.394165) |
---|
274 | guard:walkTo( 991.428650, height, -1745.393799) |
---|
275 | guard:walkTo( 998.958069, height, -1755.184326) |
---|
276 | guard:walkTo( 1003.995300, height, -1761.734131) |
---|
277 | guard:walkTo( 1009.006226, height, -1768.234375) |
---|
278 | guard:walkTo( 1013.550842, height, -1773.405029) |
---|
279 | guard:walkTo( 1019.371277, height, -1778.674072) |
---|
280 | guard:walkTo( 1024.703491, height, -1782.708618) |
---|
281 | guard:walkTo( 1030.605469, height, -1787.173950) |
---|
282 | guard:walkTo( 1036.072876, height, -1790.982056) |
---|
283 | guard:walkTo( 1043.746094, height, -1795.485474) |
---|
284 | guard:walkTo( 1050.884644, height, -1799.663574) |
---|
285 | hangarRouteProgrammed = true |
---|
286 | end |
---|
287 | |
---|
288 | if guard:finalGoalReached() and not guardStopped then |
---|
289 | return true |
---|
290 | end |
---|
291 | |
---|
292 | return false |
---|
293 | end |
---|
294 | |
---|
295 | |
---|
296 | |
---|
297 | function tick(timestep) |
---|
298 | --io.write("Guard called \n") |
---|
299 | observePlayer() |
---|
300 | |
---|
301 | |
---|
302 | if walkingRouteOne then |
---|
303 | walkingRouteOne = walkRouteOne(timestep) |
---|
304 | end |
---|
305 | |
---|
306 | if not walkingRouteOne and not exitPositionReached then |
---|
307 | exitPositionReached = goToExitPosition(timestep) |
---|
308 | end |
---|
309 | |
---|
310 | if not hangarReached and exitPositionReached then |
---|
311 | hangarReached = goToHangar(timestep) |
---|
312 | end |
---|
313 | |
---|
314 | return hangarReached |
---|
315 | end |
---|
316 | |
---|