SAMP Gitlab CI Test
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
2.5 KiB

  1. //
  2. // A test driver NPC with very basic AI
  3. // Kye 2009
  4. //
  5. #include <a_npc>
  6. new gStoppedForTraffic = 0;
  7. new gPlaybackActive = 0;
  8. public ScanTimer();
  9. #define AHEAD_OF_CAR_DISTANCE 11.0
  10. #define SCAN_RADIUS 11.0
  11. //------------------------------------------
  12. main(){}
  13. //------------------------------------------
  14. stock GetXYInfrontOfMe(Float:distance, &Float:x, &Float:y)
  15. {
  16. new Float:z, Float:angle;
  17. GetMyPos(x,y,z);
  18. GetMyFacingAngle(angle);
  19. x += (distance * floatsin(-angle, degrees));
  20. y += (distance * floatcos(-angle, degrees));
  21. }
  22. //------------------------------------------
  23. public OnNPCModeInit()
  24. {
  25. SetTimer("ScanTimer",200,1);
  26. }
  27. //------------------------------------------
  28. LookForAReasonToPause()
  29. {
  30. new Float:X,Float:Y,Float:Z;
  31. new x=0;
  32. GetMyPos(X,Y,Z);
  33. GetXYInfrontOfMe(AHEAD_OF_CAR_DISTANCE,X,Y);
  34. while(x!=MAX_PLAYERS) {
  35. if(IsPlayerConnected(x) && IsPlayerStreamedIn(x)) {
  36. if( GetPlayerState(x) == PLAYER_STATE_DRIVER ||
  37. GetPlayerState(x) == PLAYER_STATE_ONFOOT )
  38. {
  39. if(IsPlayerInRangeOfPoint(x,SCAN_RADIUS,X,Y,Z)) {
  40. return 1;
  41. }
  42. }
  43. }
  44. x++;
  45. }
  46. //new msg[256];
  47. //new Float:angle;
  48. //GetMyFacingAngle(angle);
  49. //format(msg,256,"My yaw/heading = %f",angle);
  50. //SendChat(msg);
  51. return 0;
  52. }
  53. //------------------------------------------
  54. public ScanTimer()
  55. {
  56. //new ticker = GetTickCount() - g_LastTick;
  57. //printf("npctest: timer (%d)ms", ticker);
  58. //g_LastTick = GetTickCount();
  59. new ReasonToPause = LookForAReasonToPause();
  60. if(ReasonToPause && !gStoppedForTraffic)
  61. {
  62. //SendChat("I'm pausing");
  63. PauseRecordingPlayback();
  64. gStoppedForTraffic = 1;
  65. }
  66. else if(!ReasonToPause && gStoppedForTraffic)
  67. {
  68. //SendChat("I'm resuming");
  69. ResumeRecordingPlayback();
  70. gStoppedForTraffic = 0;
  71. }
  72. }
  73. //------------------------------------------
  74. StartPlayback()
  75. {
  76. StartRecordingPlayback(PLAYER_RECORDING_TYPE_DRIVER,"taxi_test_1282");
  77. gStoppedForTraffic = 0;
  78. gPlaybackActive = 1;
  79. }
  80. //------------------------------------------
  81. public OnRecordingPlaybackEnd()
  82. {
  83. StartPlayback();
  84. }
  85. //------------------------------------------
  86. public OnNPCEnterVehicle(vehicleid, seatid)
  87. {
  88. StartPlayback();
  89. }
  90. //------------------------------------------
  91. public OnNPCExitVehicle()
  92. {
  93. StopRecordingPlayback();
  94. }
  95. //------------------------------------------