-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbotcode
More file actions
2734 lines (2297 loc) · 73.7 KB
/
botcode
File metadata and controls
2734 lines (2297 loc) · 73.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//-----------------------------Hole Mod--------------------------------//
//About:---------------------------------------------------------------//
//Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis aliquam//
//eros doesn't this look fancy molestie neque consecetur. In ultricies //
//magna ac ipsum tristique elementum. Charlie Sheen Suspendisse Winning//
//ultricies elementum ligula, vel viverra enim semper eu. //
//---------------------------------------------------------------------//
//
//By:------------------------------------------------------------------//
//--Rodrigo------------------------------------------------------------//
//----"I always wanted to have a weird group of text-------------------//
//----like this prefixing code."---------------------------------------//
//----------"So fancy..."----------------------------------------------//
//---------------------------------------------------------------------//
//
//Bot Hole Mod Goals
//------------------
//Self-Contained
//Easy plugin support?
//Simple efficient ai
//Avoiding confclits if possible
//
//Was supposed to be a general clear movement command, but usually I needed to cancel only certain things //Should rework this
function AIPlayer::hClearMovement(%obj)
{
// %obj.mountImage(hJumpImage,2);
// %obj.mountImage(hCrouchImage,3);
%obj.clearMoveY();
%obj.clearMoveX();
%obj.setImageTrigger(0,0);
%obj.setImageTrigger(1,0);
%obj.hResetMoveTriggers();
%obj.setMoveObject("");
%obj.clearAim();
%obj.maxYawSpeed = 10;
%obj.maxPitchSpeed = 10;
%obj.hResetHeadTurn();
}
// clear the movement from triggers, jump/jet/crouch
function AIPlayer::hResetMoveTriggers( %obj )
{
%obj.setJumping(0);
%obj.setCrouching(0);
// confusing, but hasJetted is called when doing long jets
if( !%obj.hHasJetted )
%obj.setJetting(0);
%obj.setMoveSpeed( %obj.hMaxMoveSpeed );
// if( %obj.getDataBlock().canJet )
// %obj.hStopJetting();
}
function AIPlayer::hSetMoveY( %obj, %val )
{
%val = %val*%obj.hMaxMoveSpeed;
%obj.setMoveY( %val );
}
function AIPlayer::hSetMoveX( %obj, %val )
{
%val = %val*%obj.hMaxMoveSpeed;
if( %obj.isJetting() )
return;
%obj.setMoveX( %val );
}
function AIPlayer::hJump( %obj, %time )
{
if( %obj.hLastSpawnTime+200 > getSimTime() )
return;
if( !strlen( %time ) )
%time = 1000;
%obj.setJumping(1);
%obj.scheduleNoQuota(%time,setJumping,0);
}
function AIPlayer::hCrouch( %obj, %time )
{
if( %obj.isJetting() )
return;
if( !strlen( %time ) )
%time = 1000;
%obj.setCrouching(1);
%obj.scheduleNoQuota(%time,setCrouching,0);
}
function AIPlayer::hLongJet( %obj )
{
%obj.hHasJetted = 1;
%obj.setMoveSpeed( 0.2 );
%obj.hJump( 100 );
%obj.setJetting( 1 );
%obj.clearMoveX();
}
function AIPlayer::hJet( %obj, %time, %slow )
{
cancel( %obj.hJetSchedule );
if( %slow )
%obj.setMoveSpeed( 0.2 );
if( !strlen( %time ) )
%time = 1000;
%obj.setMoveSpeed(0.2);
%obj.setJetting(1);
%obj.hJetSchedule = %obj.scheduleNoQuota( %time, setJetting, 0 );
%obj.scheduleNoQuota( %time, setMoveSpeed, %obj.hMaxMoveSpeed );
}
// checks if we're falling too fast and jets if so
function AIPlayer::hIsFalling( %obj )
{
%zVel = getWord( %obj.getVelocity(), 2 );
if( %zVel <= -4 )
return true;
else
return false;
}
// called whenever we stop jetting
function AIPlayer::hJetCheck( %obj, %override )
{
%jet = %obj.getDataBlock().canJet;
if( !%jet )
return;
if( !%obj.hIsFalling() && !%override )
{
%obj.setJetting( 0 );
return;
}
%obj.hHasJetted = 0;
// %obj.setJetting(1);
// %obj.setMoveSpeed(0.3);
// %tickRate = %obj.getDataBlock().hTickRate;
// if(!%tickRate)
// %tickRate = 3000;
%tickrate = %obj.hGetTickRate();
// if( %override )
// %tickSub = 100;
%obj.clearMoveX();
if( %override )
%obj.hJet( %tickRate-1000 );
else
%obj.hJet( %tickRate-500 );
}
function AIPlayer::hStopJetting( %obj )
{
// stop the jet
%obj.setJetting(0);
// after a second do hJetCheck, which checks if we're falling to our death
%obj.scheduleNoQuota( 1000, hJetCheck );
}
// randomly activate one of the triggers
function AIPlayer::hRandomMoveTrigger( %obj )
{
%jet = %obj.getDataBlock().canJet;
if( %jet )
%ran = getRandom( 0, 2 );
else
%ran = getRandom( 0, 1 );
if( %ran == 0 )
%obj.setCrouching(1);
else if( %ran == 1 )
%obj.setJumping(1);
else
%obj.setJetting(1);
}
function hGetAnglesFromVector( %vec )
{
%yawAng = mAtan( getWord(%vec,0), getWord(%vec,1) );
if( %yawAng < 0.0 )
{
%yawAng += $pi*2;
}
return %yawAng;
}
function AIPlayer::hResetHeadTurn( %obj )
{
%obj.setHeadAngleSpeed( 0.5 );
%obj.setHeadAngle( 0 );
%obj.hHeadTurn = 0;
}
function AIPlayer::hRandomHeadTurn( %obj )
{
// 3.14159
%rand = getRandom( 0, 3141 );
%rand = %rand/1000;
if( getRandom( 0, 1 ) )
%rand = -%rand;
%speed = hGetRandomFloat( 02, 10 );
%obj.setHeadAngleSpeed( %speed );
%obj.setHeadAngle( %rand );
%obj.hHeadTurn = 1;
}
//Follow player command, can be called in and out of the hole loop
function AIPlayer::hFollowPlayer( %obj, %targ, %inHoleLoop, %skipAlert )
{
//If the target doesn't exist or we're dead stop
if(!isObject(%targ) || %obj.getstate() $= "Dead" )
return;
%objPos = %obj.getPosition();
%targPos = %targ.getPosition();
%targDist = vectorDist( %objPos, %targPos );
%mount = %obj.getObjectMount();
if( %mount )
%driver = %mount.getControllingObject();//%mount.getMountNodeObject( 0 );
else
%driver = 0;
if(!%obj.hShootTimes)
%obj.hShootTimes = %obj.getDataBlock().hShootTimes;
if(!%obj.hTickRate)
%tickRate = %obj.getDataBlock().hTickRate;
else
%tickRate = %obj.hTickRate;
%obj.playthread(3,root);
cancel(%obj.hSched);
%obj.hSched = 0;
%obj.setMoveObject(%targ);
// %obj.setMoveY(1);
%obj.setMoveSlowdown( %obj.hMoveSlowdown );
%obj.clearAim();
// %obj.mountImage(hJumpImage,2);
// %obj.mountImage(hCrouchImage,3);
%obj.setImageTrigger(0,0);
%obj.hResetMoveTriggers();
%obj.maxYawSpeed = 10;
%obj.maxPitchSpeed = 10;
%obj.hFollowing.BotAttacker = %obj;
%scale = getWord(%obj.getScale(),0);
// if(%obj.getDataBlock().hCustomFollow)
%obj.getDataBlock().onBotFollow(%obj,%targ);
//Remember who we're following
%obj.hFollowing = %targ;
//If we don't have a gun, and we can't melee PANIC
%obj.hIsRunning = 0;
if( ( !%obj.getMountedImage(0) || %obj.getMountedImage(0).nonLethal ) && !%obj.hMelee)
{
%obj.setMoveObject(0);
%obj.clearMoveY();
%obj.clearAim();
%obj.hIsRunning = 1;
%obj.hRunAwayFromPlayer( %targ );
if( !getRandom( 0, 3 ) )
%obj.hSpazzClick( 0, 1 );
}
//Good for when you have the bots really far away and you don't want them jumping like retards
if( %obj.hSpazJump && %targDist <= 100*%scale )//vectorDist(%obj.getPosition(),%targ.getPosition()) <= 100*%scale)
{
%objZ = getword(%obj.getPosition(),2);
%targZ = getword(%targ.getPosition(),2);
if(%objz+3 < %targZ )//|| getrandom(0,2) == 0)
{
%obj.setJumping(1);
}
}
//Play the Alarm Emote only when first finding a target
if( %obj.hState !$= "Following" && %obj.hEmote && !%skipAlert && getSimTime() > %obj.hLastSpawnTime+3000)
{
%obj.emote(alarmProjectile);
}
//Tell the other bots you've been shot
if(%obj.hAlertOtherBots && !%skipAlert)
{
%obj.hAlertTeammates( %targ );
}
%obj.hState = "Following";
//Should I randomly strafe? Distance check is needed to avoid them circling corpses
//if(%obj.hStrafe && %targDist > 6 * %scale && getRandom(1,2) == 1)//vectorDist(%obj.getPosition(),%targ.getPosition()) > 6*%scale)
//{
// %obj.hSetMoveX(getrandom(-1,1));
//}
//If there's no maxShootRange set, set the default one. Whenever a player gives a bot to a weapon it should work.
if(!%obj.hMaxShootRange)
%obj.hMaxShootRange = 42;
// set the engage distance to hMaxShootRange, if we have a melee weapon set it to melee distance
%obj.setEngageDistance( brickToMetric( %obj.hMaxShootRange )*%scale );
if( %obj.getMountedImage(0).melee || %obj.getMountedImage(0).TypeOfWeapon $= "Melee" )
%obj.setEngageDistance( ( 10 + getRandom(-2,2 ) )*%scale );
//Giant shooting chunk, if we have weapon, can shoot etc
if(!%obj.hIsRunning && %obj.hShoot && isObject(%obj.getMountedImage(0)) && brickToMetric( %obj.hMaxShootRange )*%scale >= %targDist && hLOSCheck(%obj,%targ,1))//vectorDist(%obj.getPosition(),%targ.getPosition())
{
cancel(%obj.hShotSched);
%obj.hShotSched = 0;
//Again if these values don't exist, create them
if(!%obj.hShootTimes)
%obj.hShootTimes = 4;
if(!%tickRate)
%tickRate = 3000;
//if trying to shoot too many times within tick fix it
if(%tickRate/%obj.hShootTimes < 275)
{
%obj.hShootTimes = mFloatLength(%tickRate/275,0);
}
%imageName = %obj.getMountedImage(0).getName();
//Special case for spear
if( %obj.getMountedImage(0).isChargeWeapon || %imageName $= "spearImage" || %imageName $= "hTurretImage")
{
%obj.hShootTimes = 1;
}
//Shoot the set amount of times within the tick
%nIterate = %tickRate/%obj.hshootTimes;
for(%a = 0; %a < %obj.hshootTimes; %a++)
{
%obj.hShotSched = %obj.scheduleNoQuota( %a*%nIterate, hShootPrediction, %targ, %tickRate, %obj.hShootTimes );
}
//Avoid close range fights if you don't have melee
if(%obj.hAvoidCloseRange)
{
//convert to brick units
%range = brickToMetric( %obj.hTooCloseRange )*%scale;
//Make the bot backpedal if he's too close and the weapon he's using isn't melee based.
if( %targDist <= %range && !%obj.getMountedImage(0).Melee)//vectordist(%obj.getPosition(),%targ.getPosition())
{
// %obj.setMoveY(-0.5);
%obj.setMoveY( -%obj.hMaxMoveSpeed/2 );
}
//even if it's melee, still don't want to be point blank most of the time
if(%obj.getMountedImage(0).melee)
{
%range = 2;
if( %targDist <= %range)// vectordist(%obj.getPosition(),%targ.getPosition())
{
%obj.setMoveY(-0.2);
}
}
}
}
// if(%obj.hAvoidObstacles)
// {
%obj.hAvoidObstacle();
// }
//Record the player's last position, most likely not needed but it sometimes might make it function better
%obj.hLastPosition = %obj.getPosition();
//Record if we saw the player this tick
%obj.hSawPlayerLastTick = hLOSCheck(%obj,%targ,1);
//Check if we're in or out of the hole loop, if out that means we have to restart the schedule
if(!%inHoleLoop)
{
%obj.inHoleLoop = 0;
%tickrate = %obj.getDatablock().hTickRate;
if(!%tickrate)
{
%tickrate = 3000;
}
%obj.hSched = %obj.scheduleNoQuota(%tickrate*1.75,hLoop);
}
//Swimming checks, uses empty images, not sure if this is the best way to do this
if(%obj.getWaterCoverage())
{
%objZ = getWord(%obj.getPosition(),2);
%targZ = getWord(%targ.getPosition(),2);
if(%objZ < %targZ && %targZ-%objZ >= 2)
{
%obj.setJumping(1);
%obj.setCrouching(0);
}
else if(%objZ-%targZ >= 2)
{
%obj.setJumping(0);
%obj.setCrouching(1);
}
}
// jet check, this is going to be bad most likely
if( %obj.getDataBlock().canJet )
{
%objZ = getWord(%obj.getPosition(),2);
%targZ = getWord(%targ.getPosition(),2);
if( %targZ > %objZ+5 || %obj.hIsFalling() )//getWord( %obj.getVelocity(), 2 ) < 2 )
{
// %obj.setJetting(1);
%obj.hJump();
// %obj.hJetCheck(1);
%obj.hHasJetted = 1;
%obj.setJetting(1);
%obj.setMoveSpeed( 0.2 );
%obj.clearMoveX();
}
else if( %obj.hHasJetted )
%obj.hJetCheck(1);
else
%obj.hHasJetted = 0;
// else
// %obj.hJetCheck();
// %obj.hStopJetting();
// %obj.setJetting(0);
}
if( %mount )
{
if( %driver != %obj && %targDist < brickToMetric( 32 ) || %targ.getObjectMount() == %mount )// !%driver || checkHoleBotTeams( %obj, %driver ) )
%obj.dismount();
}
// if we're in a vehicle randomly "break" when close to target
if( %mount && !getRandom( 0, 1 ) && %targDist < 32 && !( %mount.getType() & $TypeMasks::PlayerObjectType ) )
%obj.hJump( 150+getRandom(0,150) );
}
//Main bot loop, called every tick, tick is usually every 3 seconds, every bot uses this function in some way.
function AIPlayer::hLoop(%obj)
{
//if we somehow got here and you or your spawnbrick doesn't exist anymore, then poof
if( !isObject(%obj.spawnBrick) ) // isObject(%obj) &&
{
%obj.delete();
return;
}
//Check if we exist, our spawnbrick exists, we're currently active and not dead, we need to exist
if( !isObject(%obj.spawnbrick) || %obj.isDisabled() || !%obj.hLoopActive ) // !isObject(%obj) || .getState() $= "Dead"
return;
%scale = getWord(%obj.getScale(),0);
%mount = %obj.getObjectMount();
// if we're in water set our move tolerance to be a bit higher
if( %mount && !( %mount.getType() & $TypeMasks::PlayerObjectType ) )
%obj.setMoveTolerance( 12 * %scale );
else if( %obj.getWaterCoverage() != 0 || %mount )
%obj.setMoveTolerance( 3 * %scale );
else
%obj.setMoveTolerance( 2 * %scale );
//Lay out all the options we have so we can alter them as the function progresses
%obj.inHoleLoop = 1;
%wander = %obj.hWander;
%gridWander = %obj.hGridWander;
%search = %obj.hSearch;
%strafe = %obj.hStrafe;
if(!%obj.hTickRate){
%tickrate = %obj.getDatablock().hTickRate;
}
else
%tickrate = %obj.hTickRate;
%spastic = %obj.hSpasticLook;
%idleAnim = %obj.hIdleAnimation;
%AFKScale = %obj.hAFKOmeter;
%idle = %obj.hIdle;
if(!%AFKScale)
%AFKScale = 1;
%data = %obj.getDatablock();
%canJet = %data.canJet;
%spawnBrick = %obj.spawnBrick;
%minigame = getMiniGameFromObject( %obj );// %obj.spawnBrick.getGroup().client.minigame;
%minigameHost = %minigame.owner;// %obj.spawnBrick.getGroup().client.minigame.owner;
%isHost = %obj.spawnBrick.getGroup().client == %minigameHost;
%isIncluded = %minigame.useAllPlayersBricks;
%respawnTime = %miniGame.botRespawnTime;
%brickGroup = %obj.spawnBrick.getGroup();
// let's figure out when to get out of the vehicle
if( %mount )
{
// %driver = %mount.getMountNodeObject( 0 );
%driver = %mount.getControllingObject();
if( !%driver && !getRandom( 0, 2 ) )
%mount.mountObject( %obj, 0 );
else if( !%driver || checkHoleBotTeams( %obj, %driver ) )
%obj.dismount();
else if( %idle && %driver != %obj && !getRandom( 0, 4 ) )
{
if( getRandom( 0, 1 ) )
serverCmdNextSeat( %obj );
else
serverCmdPrevSeat( %obj );
}
}
%obj.playThread(3,root);
if(%obj.getDataBlock().getName() $= "CannonTurret" || %obj.getDataBlock().getName() $= "TankTurretPlayer" || %obj.getDataBlock().isTurret)
{
%isTurret = 1;
%obj.hShoot = 1;
%obj.mountImage(hTurretImage,0);
}
else
%isTurret = 0;
//If we have certain idle actions activate this function gives you back your weapon/fixes your hands
if(%obj.hIsSpazzing)
{
if( isObject(%obj.hLastWeapon) )
{
%obj.setWeapon( %obj.hLastWeapon );
fixArmReady(%obj);
// %obj.mountImage(%obj.hLastWeapon,0);
// if( isObject(%obj.hLastWeaponL) )
// {
// %obj.mountImage(%obj.hLastWeaponL,1);
// }
}
else
{
%obj.unMountImage(0);
fixArmReady(%obj);
}
%obj.hIsSpazzing = 0;
// fixArmReady(%obj);
if( strlen( %obj.hDefaultThread ) )
%obj.playThread(1,%obj.hDefaultThread);
}
else if( isObject( %obj.getMountedImage(0) ) )
{
%obj.hLastWeapon = %obj.getMountedImage(0);
// if( isObject(%obj.getMountedImage(1)) )
// {
// %obj.hLastWeaponL = %obj.getMountedImage(1);
// }
}
//If no tickrate create one, useful for when bots are changed into other datablocks ie horse
if(!%tickrate)
{
%tickrate = 3000;
}
// %customLoop = %obj.getDatablock().hCustomLoop;
//If spawnClose is set, check if we've seen a player, if we don't see one for 3 ticks then poof ourselves
if(%obj.getDatablock().hSpawnClose)
{
%sCheck = doHoleSpawnDetect(%obj);
if(!%sCheck)
%obj.hCSpawnD++;
else
%obj.hCSpawnD = 0;
if(%obj.hCSpawnD >= 1) //egh: changing this to 1 so they unspawn faster
{
%spawnBrick = %obj.spawnBrick;
%spawnBrick.unSpawnHoleBot();
cancel(%spawnBrick.hSpawnDetectSchedule);
%spawnBrick.hSpawnDetectSchedule = %spawnBrick.scheduleNoQuota( 5000, spawnHoleBot );
return;
}
}
//Again clear movement and reattach jump/crouch images, there is probably a better way to do this
// %obj.mountImage(hJumpImage,2);
// %obj.mountImage(hCrouchImage,3);
%obj.clearMoveY();
%obj.clearMoveX();
//%obj.clearAim();
%obj.hResetMoveTriggers();
%obj.maxYawSpeed = 10;
%obj.maxPitchSpeed = 10;
// check if we're a jet datablock and we're falling to our death
%obj.hJetCheck();
if(%search)
{
//Radius Check
if(isObject(%minigame) && %obj.hSearchFOV != 1)
{
if(%isHost || %isIncluded)
{
%target = %obj.hFindClosestPlayer();
if( isObject( %target ) && hLOSCheck( %obj, %target ) )// && vectorDist(%target.getPosition(),%obj.getPosition()) <= %obj.hFinalRadius && hLOSCheck(%obj,%target))
{
//if we've found someone set wander to 0 so we don't do any idle actions or wander around
%wander = 0;
%idle = 0;
%obj.hFollowPlayer( %target, 1 );
}
else if( %obj.hIgnore != %obj.hFollowing && %obj.hSawPlayerLastTick && isObject(%obj.hFollowing) && !%obj.hFollowing.isDisabled() && checkHoleBotTeams(%obj,%obj.hFollowing, 1))
{
if(%obj.hIsRunning)
%chaseDist = 64;
else
%chaseDist = 128;
if(vectorDist(%obj.getPosition(),%obj.hFollowing.getPosition()) <= %chaseDist*%scale)
{
//We saw someone last tick so we should go to where we last saw him/towards him. Might redo the way this works
%wander = 0;
%idle = 0;
%obj.hFollowPlayer( %obj.hFollowing, 1 );
}
}
}
}
//Fov Check
if(isObject(%minigame) && %obj.hSearchFOV)
{
if(%isHost || %isIncluded)
{
if( %obj.hIgnore != %obj.hFollowing && %obj.hSawPlayerLastTick && isObject(%obj.hFollowing) && !%obj.hFollowing.isDisabled() && checkHoleBotTeams(%obj,%obj.hFollowing, 1))
{
if(%obj.hIsRunning)
%chaseDist = 64;
else
%chaseDist = 128;
if(vectorDist(%obj.getPosition(),%obj.hFollowing.getPosition()) <= %chaseDist*%scale)
{
//We saw someone last tick so we should go to where we last saw him/towards him. Might redo the way this works
%wander = 0;
%idle = 0;
%obj.hFollowPlayer( %obj.hFollowing, 1 );
}
}
if(%obj.hDoHoleFOVCheck(%obj.hFOVRadius,1,1))
{
%wander = 0;
%idle = 0;
}
else
{
cancel(%obj.hFOVSchedule);
%obj.hFOVSchedule = %obj.scheduleNoQuota(%tickRate/2,hDoHoleFOVCheck,%obj.hFOVRadius,0,1);
}
}
}
}
//If there's a custom script tag on the datablock, then call the function
// if(%customLoop)
%obj.getDataBlock().onBotLoop(%obj);
//If we have a brick target that takes precedence over wandering
if(isObject(%obj.hPathBrick) && %obj.hState !$= "Following")
{
//Again ghetto clear movement things
%obj.setMoveObject("");
%obj.clearMoveY();
%obj.clearMoveX();
%obj.clearAim();
%obj.hResetHeadTurn();
// %obj.hResetMoveTriggers();
%obj.hState = "Pathing";
%tPos = getWords(%obj.hPathBrick.getPosition(),0,1) SPC 0;
%pos = getWords(%obj.getPosition(),0,1) SPC 0;
//Ok we've landed at the brick, er.. well close enough
// if(vectorDist(%pos,%tPos) <= 3*%scale)
// {
// %lastBrick = %obj.hPathBrick;
// %obj.hPathBrick = 0;
// %lastBrick.onBotReachBrick(%obj);
// %obj.lastBrickReachTime = getSimTime()+500;//No idea why this is here, I must of had something planned for it
// //%obj.hSched = %obj.scheduleNoQuota(%tickrate/2+getrandom(0,750),hLoop);
// %obj.scheduleNoQuota(100,hLoop);
// return;
// }
if( %canJet )
{
%brickZ = %obj.hPathBrick.hGetPosZ();
%objZ = %obj.hGetPosZ();
// echo( %brickZ SPC %objZ+3 );
if( %brickZ > %objZ+18 )
%obj.hLongJet();
else if( %obj.hHasJetted || %brickZ > %objZ+2 )
%obj.hJetCheck(1);
%obj.maxYawSpeed = 20;
// else if( !getRandom( 0, 2 ) && !%obj.hIsFalling() )
// {
// %obj.hJump( 100 );
// %obj.hJet( 500+getRandom(0,300) );
// }
if( %obj.isJetting() && vectorDist(%pos,%tPos) <= 6*%scale)
{
// echo( "close" );
%obj.setMoveSpeed( 0.1 );
}
}
// setMoveSlowdown should govern this as well
%obj.setMoveDestination( getwords(%obj.hPathBrick.getPosition(),0,1) SPC getword(%obj.getPosition(),2) );
// %obj.setAimLocation( %obj.hPathBrick.getPosition() );
//If people disable %wander then we assume they don't want the bot to be doing much, so don't avoid obstacles
if(%obj.hAvoidObstacles && %wander)
{
%obj.hAvoidObstacle();
}
%obj.hSched = %obj.scheduleNoQuota(%tickrate+getrandom(0,750),hLoop);
return;
}
if(%wander)
{
%obj.hIsRunning = 0;
//Er again, but still...
%obj.setMoveObject("");
%obj.clearMoveY();
%obj.clearMoveX();
//%obj.clearAim();
%obj.setImageTrigger(0,0);
%obj.hResetHeadTurn();
// %obj.hResetMoveTriggers();
//%obj.stopThread(1);
%pos = %obj.getPosition();
//Again converting to brick units, easier for players
%returnDist = brickToMetric( %obj.hSpawnDist );//2-0.25;
%avoid = 0;
//if 0 we assume they want to always return to brick
// if returnDistance is zero then our bot will always try to get back to spawn since the distance between bot and spawn is never truly zero
if(%returnDist <= 0)
%returnDist = 1.6;//1.6;
%returnDist = %returnDist*%scale;
if( %returnDist < 1 )
%returnDist = 1;
// perhaps we should make this trigger onReachBrick when we get back?
//We're too far let's go back.. it's safe there
if( %obj.hReturnToSpawn && vectordist( %pos, %obj.spawnBrick.getPosition() ) > %returnDist )
{
// if %obj.hSpawnDist is zero that means we will never random wander, so let's set a flag that will reset our rotation to our spawnbrick when we arrive
if( %obj.hSpawnDist == 0 )
%obj.hIsGuard = 1;
%brickPos = %obj.spawnBrick.getPosition();
%brickZ = hGetZ( %brickPos );
%objZ = %obj.hGetPosZ();
if( vectorDist(%pos,%brickPos) <= 6*%scale )
%obj.setMoveSpeed( 0.2 );
if( %canJet )
{
if( %brickZ > %objZ+18 )
%obj.hLongJet();
else if( %obj.hHasJetted || %brickZ > %objZ+2 )
%obj.hJetCheck(1);
if( %obj.isJetting() && vectorDist(%pos,%brickPos) <= 6*%scale )
%obj.setMoveSpeed( 0.1 );
}
// else if( !getRandom( 0, 2 ) && !%obj.hIsFalling() )
// {
// %obj.hJump( 100 );
// %obj.hJet( 500+getRandom(0,300) );
// }
%obj.clearAim();
%obj.hFollowing.BotAttacker = 0;
%obj.hFollowing = "";
%obj.setMoveDestination( %brickPos );
%obj.hState = "Returning";
%obj.hAvoidObstacle();
%obj.hSched = %obj.scheduleNoQuota(%tickrate+getrandom(0,1000),hLoop);
return;
}
else if( %obj.hReturnToSpawn && %obj.hIsGuard )
{
%posSpawn = %spawnBrick.getPosition();
// check that we've fully returned to spawn
if( vectordist( %pos, %posSpawn ) <= %returnDist )
{
// ok we've returned so let's look forward and turn off hIsGuard
%obj.maxYawSpeed = getRandom( 5, 10 );
%obj.maxPitchSpeed = getRandom( 5, 10 );
// %obj.setAimLocation( %loc );
%obj.setAimVector( %spawnBrick.getForwardVector() );
%obj.hIsGuard = 0;
// call onBotReachBrick event
%spawnBrick.onBotReachBrick(%obj);
}
}
// randomly jet
if( %obj.hSpawnDist != 0 && !getRandom( 0, 4 ) && !%obj.hIsFalling() )
{
%obj.hJump( 100 );
// randomly do a long safe jump, or a short jump
if( !getRandom( 0, 2 ) )
%obj.hJet( %tickrate-500 );
else
%obj.hJet( 1000+getRandom(0,500) );
}
//If we just saw a target, better act fast and irrational
if(%obj.hState $= "Following" && %obj.hSpawnDist != 0)
{
if(isObject(%obj.hFollowing) && %obj.hFollowing.getState() $= "Dead")
{
%obj.hFollowing.BotAttacker = 0;
%obj.hFollowing = 0;
}
else
{
%obj.clearAim();
%xRand = getrandom(-15,15);
%yRand = getrandom(-15,15);
%obj.setMoveDestination(vectoradd(%pos,%xRand SPC %yRand SPC 0));
%obj.hAvoidObstacle();
%obj.hState = "Wandering";
if(%obj.hEmote)
{
%obj.emote(wtfImage);
}
//echo("From going to wander from following");
%obj.hFollowing.BotAttacker = 0;
%obj.hFollowing = "";
%obj.hSched = %obj.scheduleNoQuota(%tickrate/2,hLoop);
return;
}
}
//Already did return check and lost target check, set to wander
%obj.hState = "Wandering";
//If spawn distance is set to 0 we don't randomly wander. We assume the user wants them to act as guard bots
//Grid walking
if(%obj.hGridWander && getRandom(-1,mFloatLength(1*%AFKScale,0)) <= 0 && %obj.hSpawnDist != 0)
{
%avoid = 1;
%noStrafe = 1;
%onlyJump = 1;
%idle = 0;
%obj.clearAim();
%obj.hFollowing.BotAttacker = 0;
%obj.hFollowing = "";
//%sPos = %obj.getPosition();
//%sPos = %obj.hGridPosition;
%sPos = lockToGrid(%obj, %obj.getPosition());
if(getRandom(0,1))
{
%rand = getRandom(-4,4)*2*%scale;
%tPos = vectorAdd(%sPos, %rand SPC "0 0");
}
else
{
%rand = getRandom(-4,4)*2*%scale;
%tPos = vectorAdd(%sPos, "0" SPC %rand SPC "0");
}
%pos = %tPos;
//%pos = lockToGrid(%obj, %tPos);
%obj.setMoveDestination(%pos);
//%obj.hGridPosition = %pos;
if(getRandom(0,4) > 0)
%obj.scheduleNoQuota( %tickrate/2, hDetectWall );
}
//Smooth wandering
else if(%obj.hSmoothWander && !%obj.hGridWander && !getRandom(0,mFloatLength(2*%AFKScale,0)) && %obj.hSpawnDist != 0)
{
%avoid = 1;
%idle = 0;
// randomly crouch
if( !getRandom(0,3) )
%obj.setCrouching(1);
else if( !getRandom(0,1) )
%obj.setCrouching(0);
%obj.smoothWander();
// randomly go up or down in water
if(%obj.getWaterCoverage())
{
if(getRandom(1,4) == 1)
{
%obj.hRandomMoveTrigger();
}
}
//3/4 chance that the bot will face away from a wall
if( getRandom(0,3) > 0 )
%obj.scheduleNoQuota( %tickrate/2, hDetectWall );
}
//More conventional bot movement, mixing between the two creates a good variety of movement
else if(!%obj.hGridWander && !getrandom(0,mFloatLength(2*%AFKScale,0)) && %obj.hSpawnDist != 0)
{
%idle = 0;
%avoid = 1;
//Strafing is disbaled from the avoidance function to prevent the bot from walking around a point
%noStrafe = 1;
//Random crouching, works surprisingly well
if(!getRandom(0,3))
%obj.setCrouching(1);
else if(!getRandom(0,1))
%obj.setCrouching(0);
%obj.maxYawSpeed = getRandom(3,10);
%obj.maxPitchSpeed = getRandom(3,10);
%obj.clearAim();
%xRand = getrandom(-7,7);
%yRand = getrandom(-7,7);
%obj.hFollowing.BotAttacker = 0;
%obj.hFollowing = "";
%rFinal = vectorAdd(%pos,%xRand SPC %yRand SPC 0);