[4202] | 1 | -- Create the trigger |
---|
| 2 | trigger = ScriptTrigger() |
---|
| 3 | trigger:setName("secondguardtrigger") |
---|
| 4 | trigger:setScript("secondguard.lua") |
---|
| 5 | trigger:setFunction("tick") |
---|
| 6 | trigger:setActiveOnCreation(true) |
---|
| 7 | |
---|
| 8 | |
---|
[4080] | 9 | -- Get objects from orxonox |
---|
| 10 | thisscript:addObject("GenericNPC", "secondguard") |
---|
| 11 | thisscript:addObject("GenericNPC", "guard") |
---|
| 12 | thisscript:addObject("FPSPlayer", "Player") |
---|
| 13 | thisscript:addObject("GenericNPC", "prisoner") |
---|
| 14 | |
---|
[3945] | 15 | -- Global Variables |
---|
| 16 | allOk = true |
---|
[3951] | 17 | cellReached = false |
---|
[3945] | 18 | guidePositionReached = false |
---|
| 19 | prisonerReachedLock = false |
---|
| 20 | hangarReached = false |
---|
[4080] | 21 | guardStopped = false |
---|
[4106] | 22 | letsgo = false |
---|
[3945] | 23 | |
---|
[4080] | 24 | height = 90 |
---|
[3946] | 25 | |
---|
| 26 | -- Returns the distance between (x1,x2,x3) and (y1,y2,y3) |
---|
| 27 | function dist( x1,x2,x3, y1,y2,y3 ) |
---|
| 28 | return math.sqrt( (x1-y1)^2 + (x2-y2)^2 + (x3-y3)^2 ) |
---|
| 29 | end |
---|
| 30 | |
---|
| 31 | |
---|
[3951] | 32 | function observeGuard() |
---|
| 33 | guardX = guard:getAbsCoorX() |
---|
| 34 | guardY = guard:getAbsCoorY() |
---|
| 35 | guardZ = guard:getAbsCoorZ() |
---|
| 36 | |
---|
[3965] | 37 | if dist( guardX,guardY,guardZ,35.48, 29, 191.28 ) < 30 then |
---|
[3945] | 38 | allOk = false |
---|
| 39 | end |
---|
| 40 | |
---|
[3951] | 41 | end |
---|
| 42 | |
---|
[4080] | 43 | function observePlayer() |
---|
| 44 | |
---|
| 45 | guardX = guard:getAbsCoorX() |
---|
| 46 | guardY = guard:getAbsCoorY() |
---|
| 47 | guardZ = guard:getAbsCoorZ() |
---|
| 48 | |
---|
| 49 | playerX = Player:getAbsCoorX() |
---|
| 50 | playerY = Player:getAbsCoorY() |
---|
| 51 | playerZ = Player:getAbsCoorZ() |
---|
| 52 | |
---|
| 53 | distance = dist( guardX,guardY,guardZ,playerX, playerY, playerZ) |
---|
| 54 | |
---|
| 55 | if distance > 250 and hangarProgrammed and not guardStopped then |
---|
| 56 | secondguard:stop() |
---|
| 57 | guardStopped = true |
---|
| 58 | end |
---|
| 59 | |
---|
| 60 | if distance < 250 and hangarProgrammed and guardStopped then |
---|
| 61 | secondguard:resume() |
---|
| 62 | guardStopped = false |
---|
| 63 | end |
---|
| 64 | |
---|
[4161] | 65 | if dist( playerX,playerY,playerZ,161.76,49,408.87 ) < 50 then |
---|
[4106] | 66 | letsgo = true |
---|
[4080] | 67 | end |
---|
| 68 | |
---|
[4106] | 69 | end |
---|
[4080] | 70 | |
---|
| 71 | |
---|
[4106] | 72 | |
---|
[3946] | 73 | function observePrisoner() |
---|
[3945] | 74 | |
---|
[3962] | 75 | prisonerX = prisoner:getAbsCoorX() |
---|
| 76 | prisonerY = prisoner:getAbsCoorY() |
---|
| 77 | prisonerZ = prisoner:getAbsCoorZ() |
---|
[3946] | 78 | |
---|
[3964] | 79 | if dist( prisonerX,prisonerY,prisonerZ,162.757919,49,363.489349 ) < 60 then |
---|
[3965] | 80 | --io.write("Prisonner reached lock \n") |
---|
| 81 | prisonerReachedLock = true |
---|
[3945] | 82 | end |
---|
| 83 | |
---|
[3951] | 84 | end |
---|
[3945] | 85 | |
---|
[3954] | 86 | cellProgrammed = false |
---|
[3951] | 87 | function goToCell(timestep) |
---|
| 88 | |
---|
[3954] | 89 | if not cellProgrammed then |
---|
[3964] | 90 | secondguard:walkTo( 442.173767, height, 176.429855) |
---|
| 91 | secondguard:walkTo( 442.173767, height, 176.429855) |
---|
| 92 | secondguard:walkTo( 436.727753, height, 188.191757) |
---|
| 93 | secondguard:walkTo( 432.311584, height, 198.882462) |
---|
| 94 | secondguard:walkTo( 426.079590, height, 213.968994) |
---|
| 95 | secondguard:walkTo( 420.553986, height, 226.714996) |
---|
| 96 | secondguard:walkTo( 412.681915, height, 235.053696) |
---|
| 97 | secondguard:walkTo( 398.758545, height, 241.846924) |
---|
| 98 | secondguard:walkTo( 384.690735, height, 242.851395) |
---|
| 99 | secondguard:walkTo( 348.930481, height, 242.394958) |
---|
| 100 | secondguard:walkTo( 336.467926, height, 241.985764) |
---|
| 101 | secondguard:walkTo( 324.042999, height, 241.577774) |
---|
| 102 | secondguard:walkTo( 303.851410, height, 240.914841) |
---|
| 103 | secondguard:walkTo( 293.013977, height, 240.559006) |
---|
| 104 | secondguard:walkTo( 276.207611, height, 240.007233) |
---|
| 105 | secondguard:walkTo( 261.475800, height, 239.523544) |
---|
| 106 | secondguard:walkTo( 239.185089, height, 238.791687) |
---|
| 107 | secondguard:walkTo( 226.655655, height, 238.491974) |
---|
| 108 | secondguard:walkTo( 211.996979, height, 238.851044) |
---|
| 109 | secondguard:walkTo( 192.956741, height, 239.859207) |
---|
| 110 | secondguard:walkTo( 178.496552, height, 241.852539) |
---|
| 111 | secondguard:walkTo( 160.421860, height, 244.009827) |
---|
| 112 | secondguard:walkTo( 145.371857, height, 244.946075) |
---|
| 113 | secondguard:walkTo( 129.918198, height, 245.307037) |
---|
| 114 | secondguard:walkTo( 113.065468, height, 245.108231) |
---|
| 115 | secondguard:walkTo( 99.159073, height, 244.695694) |
---|
| 116 | secondguard:walkTo( 82.069923, height, 244.188766) |
---|
| 117 | secondguard:walkTo( 65.880531, height, 243.708527) |
---|
| 118 | secondguard:walkTo( 48.133881, height, 243.182114) |
---|
| 119 | secondguard:walkTo( 34.706280, height, 242.783813) |
---|
| 120 | secondguard:walkTo( 20.682344, height, 242.367783) |
---|
| 121 | secondguard:walkTo( 5.419819, height, 241.915070) |
---|
| 122 | secondguard:walkTo( -10.556346, height, 241.058746) |
---|
| 123 | secondguard:walkTo( -24.159513, height, 240.127090) |
---|
| 124 | secondguard:walkTo( -33.819145, height, 239.995453) |
---|
| 125 | secondguard:walkTo( -45.414162, height, 240.373322) |
---|
| 126 | secondguard:walkTo( -60.228550, height, 240.856079) |
---|
| 127 | secondguard:walkTo( -73.269897, height, 241.260895) |
---|
| 128 | secondguard:walkTo( -86.128647, height, 240.457886) |
---|
| 129 | secondguard:walkTo( -100.443581, height, 236.485718) |
---|
| 130 | secondguard:walkTo( -112.346939, height, 233.967209) |
---|
| 131 | secondguard:walkTo( -127.331635, height, 227.615112) |
---|
| 132 | secondguard:walkTo( -135.153656, height, 215.476883) |
---|
| 133 | secondguard:walkTo( -131.529984, height, 202.931015) |
---|
| 134 | secondguard:walkTo( -122.671799, height, 193.644669) |
---|
| 135 | secondguard:walkTo( -113.823517, height, 183.986633) |
---|
| 136 | secondguard:walkTo( -104.089592, height, 170.659729) |
---|
[3954] | 137 | cellProgrammed = true |
---|
| 138 | end |
---|
| 139 | |
---|
| 140 | if secondguard:finalGoalReached() then |
---|
| 141 | return true |
---|
| 142 | end |
---|
| 143 | |
---|
[3945] | 144 | return false |
---|
| 145 | end |
---|
| 146 | |
---|
[3954] | 147 | guideProgrammed = false |
---|
[3945] | 148 | function goToGuidePosition(timestep) |
---|
| 149 | |
---|
[3954] | 150 | if not guideProgrammed then |
---|
[3964] | 151 | secondguard:walkTo( -100.266739, height, 171.345627) |
---|
| 152 | secondguard:walkTo( -91.152046, height, 171.639709) |
---|
| 153 | secondguard:walkTo( -85.456375, height, 171.823486) |
---|
| 154 | secondguard:walkTo( -74.048538, height, 172.191589) |
---|
| 155 | secondguard:walkTo( -53.574173, height, 172.852219) |
---|
| 156 | secondguard:walkTo( -43.275124, height, 173.184540) |
---|
| 157 | secondguard:walkTo( -35.155544, height, 173.446518) |
---|
| 158 | secondguard:walkTo( -31.645050, height, 173.559784) |
---|
| 159 | secondguard:walkTo( -23.426588, height, 173.824966) |
---|
| 160 | secondguard:walkTo( -10.576803, height, 174.239578) |
---|
| 161 | secondguard:walkTo( -2.389911, height, 174.503754) |
---|
| 162 | secondguard:walkTo( 6.950986, height, 174.805176) |
---|
| 163 | secondguard:walkTo( 16.313608, height, 175.161179) |
---|
| 164 | secondguard:walkTo( 23.271458, height, 175.547226) |
---|
| 165 | secondguard:walkTo( 31.248058, height, 176.199890) |
---|
| 166 | secondguard:walkTo( 43.694778, height, 177.753479) |
---|
| 167 | secondguard:walkTo( 50.441612, height, 178.595612) |
---|
| 168 | secondguard:walkTo( 71.374535, height, 181.208389) |
---|
| 169 | secondguard:walkTo( 82.251022, height, 181.855988) |
---|
| 170 | secondguard:walkTo( 91.975792, height, 182.434998) |
---|
| 171 | secondguard:walkTo( 101.695015, height, 183.013672) |
---|
| 172 | secondguard:walkTo( 110.377205, height, 183.530609) |
---|
| 173 | secondguard:walkTo( 122.299400, height, 184.240448) |
---|
| 174 | secondguard:walkTo( 129.848495, height, 184.689911) |
---|
| 175 | secondguard:walkTo( 141.687805, height, 185.394821) |
---|
| 176 | secondguard:walkTo( 150.166702, height, 186.776016) |
---|
| 177 | secondguard:walkTo( 155.342255, height, 189.285080) |
---|
| 178 | secondguard:walkTo( 162.508133, height, 192.849976) |
---|
| 179 | secondguard:walkTo( 171.747696, height, 197.075134) |
---|
| 180 | secondguard:walkTo( 177.846390, height, 199.864029) |
---|
| 181 | secondguard:walkTo( 182.707596, height, 204.381516) |
---|
| 182 | secondguard:walkTo( 182.707596, height, 204.381516) |
---|
| 183 | secondguard:walkTo( 187.317139, height, 211.966385) |
---|
| 184 | secondguard:walkTo( 193.191528, height, 221.632446) |
---|
| 185 | secondguard:walkTo( 197.856018, height, 229.307724) |
---|
| 186 | secondguard:walkTo( 198.350906, height, 232.634857) |
---|
| 187 | secondguard:walkTo( 198.427155, height, 243.656113) |
---|
[3954] | 188 | |
---|
| 189 | guideProgrammed = true |
---|
| 190 | end |
---|
| 191 | |
---|
| 192 | if secondguard:finalGoalReached() then |
---|
| 193 | return true |
---|
| 194 | end |
---|
| 195 | |
---|
[3945] | 196 | return false |
---|
| 197 | end |
---|
| 198 | |
---|
[3954] | 199 | hangarProgrammed = false |
---|
[3945] | 200 | function goToHangar(timestep) |
---|
| 201 | |
---|
[4106] | 202 | if not hangarProgrammed and prisonerReachedLock and letsgo then |
---|
[4080] | 203 | secondguard:walkTo( 198.984589, height, 243.144440) |
---|
| 204 | secondguard:walkTo( 188.270493, height, 242.143143) |
---|
| 205 | secondguard:walkTo( 185.177658, height, 241.854080) |
---|
| 206 | secondguard:walkTo( 166.990906, height, 249.598251) |
---|
| 207 | secondguard:walkTo( 160.702652, height, 251.610641) |
---|
| 208 | secondguard:walkTo( 157.542480, height, 260.691101) |
---|
| 209 | secondguard:walkTo( 158.720688, height, 285.526489) |
---|
| 210 | secondguard:walkTo( 158.819519, height, 295.229065) |
---|
| 211 | secondguard:walkTo( 158.941727, height, 307.225800) |
---|
| 212 | secondguard:walkTo( 159.095718, height, 322.344818) |
---|
| 213 | secondguard:walkTo( 159.248337, height, 332.535400) |
---|
| 214 | secondguard:walkTo( 159.600082, height, 343.361420) |
---|
| 215 | secondguard:walkTo( 160.006805, height, 355.880432) |
---|
| 216 | secondguard:walkTo( 161.582108, height, 441.998688) |
---|
| 217 | secondguard:walkTo( 161.650970, height, 447.407074) |
---|
| 218 | secondguard:walkTo( 161.755173, height, 455.592651) |
---|
| 219 | secondguard:walkTo( 162.311462, height, 471.569611) |
---|
| 220 | secondguard:walkTo( 164.966690, height, 482.971222) |
---|
| 221 | secondguard:walkTo( 168.578796, height, 492.256317) |
---|
| 222 | secondguard:walkTo( 204.727936, height, 507.833527) |
---|
| 223 | secondguard:walkTo( 212.031540, height, 508.235596) |
---|
| 224 | secondguard:walkTo( 226.355484, height, 509.024170) |
---|
| 225 | secondguard:walkTo( 441.672638, height, 512.266846) |
---|
| 226 | secondguard:walkTo( 509.640350, height, 512.965515) |
---|
| 227 | secondguard:walkTo( 576.208435, height, 512.614258) |
---|
| 228 | secondguard:walkTo( 638.251770, height, 512.247986) |
---|
| 229 | secondguard:walkTo( 667.897888, height, 512.072693) |
---|
| 230 | secondguard:walkTo( 683.874451, height, 511.978363) |
---|
| 231 | secondguard:walkTo( 693.377319, height, 511.922302) |
---|
| 232 | secondguard:walkTo( 700.632446, height, 511.837494) |
---|
| 233 | secondguard:walkTo( 703.564148, height, 511.713562) |
---|
| 234 | secondguard:walkTo( 710.958313, height, 510.896362) |
---|
| 235 | secondguard:walkTo( 724.824585, height, 502.160461) |
---|
| 236 | secondguard:walkTo( 728.256226, height, 497.817627) |
---|
| 237 | secondguard:walkTo( 734.361206, height, 484.795380) |
---|
| 238 | secondguard:walkTo( 737.112488, height, 478.616089) |
---|
| 239 | secondguard:walkTo( 740.696350, height, 470.796539) |
---|
| 240 | secondguard:walkTo( 743.915833, height, 462.804688) |
---|
| 241 | secondguard:walkTo( 750.241150, height, 438.829529) |
---|
| 242 | secondguard:walkTo( 751.186340, height, 432.598022) |
---|
| 243 | secondguard:walkTo( 751.977051, height, 427.385315) |
---|
| 244 | secondguard:walkTo( 756.962708, height, 379.979919) |
---|
| 245 | secondguard:walkTo( 759.845581, height, 337.377167) |
---|
| 246 | secondguard:walkTo( 762.304626, height, 288.355713) |
---|
| 247 | secondguard:walkTo( 764.125244, height, 248.893723) |
---|
| 248 | secondguard:walkTo( 766.738892, height, 164.214142) |
---|
| 249 | secondguard:walkTo( 767.405884, height, 116.896973) |
---|
| 250 | secondguard:walkTo( 767.289917, height, 68.270233) |
---|
| 251 | secondguard:walkTo( 767.680176, height, 31.480713) |
---|
| 252 | secondguard:walkTo( 767.315247, height, -46.728809) |
---|
| 253 | secondguard:walkTo( 767.634888, height, -85.314407) |
---|
| 254 | secondguard:walkTo( 767.905823, height, -112.270973) |
---|
| 255 | secondguard:walkTo( 767.716003, height, -134.956741) |
---|
| 256 | secondguard:walkTo( 765.699829, height, -159.042664) |
---|
| 257 | secondguard:walkTo( 762.026978, height, -178.211639) |
---|
| 258 | secondguard:walkTo( 751.512512, height, -219.904297) |
---|
| 259 | secondguard:walkTo( 735.898499, height, -277.525970) |
---|
| 260 | secondguard:walkTo( 722.206055, height, -329.591888) |
---|
| 261 | secondguard:walkTo( 709.354858, height, -383.514618) |
---|
| 262 | secondguard:walkTo( 697.115295, height, -434.870483) |
---|
| 263 | secondguard:walkTo( 685.142822, height, -485.212402) |
---|
| 264 | secondguard:walkTo( 681.659058, height, -532.429504) |
---|
| 265 | secondguard:walkTo( 679.999634, height, -581.595886) |
---|
| 266 | secondguard:walkTo( 678.678101, height, -632.772156) |
---|
| 267 | secondguard:walkTo( 678.162842, height, -682.753113) |
---|
| 268 | secondguard:walkTo( 678.398376, height, -731.779053) |
---|
| 269 | secondguard:walkTo( 679.124756, height, -782.160034) |
---|
| 270 | secondguard:walkTo( 680.050781, height, -831.132141) |
---|
| 271 | secondguard:walkTo( 678.395569, height, -877.242920) |
---|
| 272 | secondguard:walkTo( 676.737793, height, -919.301819) |
---|
| 273 | secondguard:walkTo( 676.191956, height, -962.443909) |
---|
| 274 | secondguard:walkTo( 676.493774, height, -994.707703) |
---|
| 275 | secondguard:walkTo( 677.446716, height, -1018.486389) |
---|
| 276 | secondguard:walkTo( 681.286865, height, -1042.623901) |
---|
| 277 | secondguard:walkTo( 685.302917, height, -1060.096436) |
---|
| 278 | secondguard:walkTo( 692.212036, height, -1083.229370) |
---|
| 279 | secondguard:walkTo( 698.947937, height, -1103.496826) |
---|
| 280 | secondguard:walkTo( 710.392944, height, -1137.932617) |
---|
| 281 | secondguard:walkTo( 719.685608, height, -1164.374634) |
---|
| 282 | secondguard:walkTo( 728.124512, height, -1186.812622) |
---|
| 283 | secondguard:walkTo( 746.270569, height, -1235.059082) |
---|
| 284 | secondguard:walkTo( 754.436340, height, -1259.201660) |
---|
| 285 | secondguard:walkTo( 760.588013, height, -1286.830933) |
---|
| 286 | secondguard:walkTo( 765.026733, height, -1329.641113) |
---|
| 287 | secondguard:walkTo( 765.849609, height, -1362.461670) |
---|
| 288 | secondguard:walkTo( 765.842346, height, -1398.791016) |
---|
| 289 | secondguard:walkTo( 765.749695, height, -1425.336304) |
---|
| 290 | secondguard:walkTo( 765.650024, height, -1454.007935) |
---|
[3954] | 291 | hangarProgrammed = true |
---|
| 292 | end |
---|
| 293 | |
---|
[3965] | 294 | guardX = secondguard:getAbsCoorX() |
---|
| 295 | guardY = secondguard:getAbsCoorY() |
---|
| 296 | guardZ = secondguard:getAbsCoorZ() |
---|
| 297 | |
---|
| 298 | if dist( guardX,guardY,guardZ, 2.861493, 29, -1705.131958) < 60 then |
---|
[3954] | 299 | return true |
---|
| 300 | end |
---|
| 301 | |
---|
[3945] | 302 | return false |
---|
[3954] | 303 | |
---|
[3945] | 304 | end |
---|
| 305 | |
---|
[3965] | 306 | time = 2 |
---|
[3945] | 307 | function tick(timestep) |
---|
[3946] | 308 | --io.write("Secondguard called \n") |
---|
| 309 | |
---|
| 310 | observePrisoner() |
---|
[3964] | 311 | observeGuard() |
---|
[4080] | 312 | observePlayer() |
---|
[3945] | 313 | |
---|
| 314 | if not allOk then |
---|
[3951] | 315 | cellReached = goToCell(timestep) |
---|
[3945] | 316 | end |
---|
| 317 | |
---|
[3965] | 318 | --do talking |
---|
| 319 | if cellReached then |
---|
| 320 | time = time - timestep |
---|
| 321 | end |
---|
| 322 | |
---|
| 323 | |
---|
| 324 | if time < 0 then |
---|
| 325 | |
---|
[3951] | 326 | if cellReached and not guidePositionReached then |
---|
[3945] | 327 | guidePositionReached = goToGuidePosition(timestep) |
---|
| 328 | end |
---|
| 329 | |
---|
[3964] | 330 | if guidePositionReached and not hangarReached then |
---|
[3945] | 331 | hangarReached = goToHangar(timestep) |
---|
| 332 | end |
---|
| 333 | |
---|
| 334 | if hangarReached then |
---|
| 335 | return true |
---|
| 336 | end |
---|
| 337 | |
---|
[3965] | 338 | |
---|
| 339 | end |
---|
| 340 | |
---|
| 341 | |
---|
[3945] | 342 | return false |
---|
| 343 | end |
---|