kerts93

busX1.pwn

Jul 9th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.60 KB | None | 0 0
  1. #include <a_npc>
  2.  
  3. new gStoppedForTraffic = 0;
  4. new gPlaybackActive = 0;
  5.  
  6. new Suund = 0;
  7.  
  8. public ScanTimer();
  9.  
  10. #define AHEAD_OF_CAR_DISTANCE    11.0
  11. #define SCAN_RADIUS              3.0
  12.  
  13. //------------------------------------------
  14.  
  15. main(){}
  16.  
  17. //------------------------------------------
  18.  
  19. stock GetXYInfrontOfMe(Float:distance, &Float:x, &Float:y)
  20. {
  21.     new Float:z, Float:angle;
  22.     GetMyPos(x,y,z);
  23.     GetMyFacingAngle(angle);
  24.     x += (distance * floatsin(-angle, degrees));
  25.     y += (distance * floatcos(-angle, degrees));
  26. }
  27.  
  28. //------------------------------------------
  29.  
  30. public OnNPCModeInit()
  31. {
  32.     SetTimer("ScanTimer",200,1);
  33. }
  34.  
  35. //------------------------------------------
  36.  
  37. LookForAReasonToPause()
  38. {
  39.     new Float:X,Float:Y,Float:Z;
  40.     new x=0;
  41.    
  42.     GetMyPos(X,Y,Z);
  43.     GetXYInfrontOfMe(AHEAD_OF_CAR_DISTANCE,X,Y);
  44.    
  45.     while(x!=MAX_PLAYERS) {
  46.         if(IsPlayerConnected(x) && IsPlayerStreamedIn(x)) {
  47.             if( GetPlayerState(x) == PLAYER_STATE_DRIVER ||
  48.                 GetPlayerState(x) == PLAYER_STATE_ONFOOT )
  49.             {
  50.                 if(IsPlayerInRangeOfPoint(x,SCAN_RADIUS,X,Y,Z)) {
  51.                     return 1;
  52.                 }
  53.             }
  54.         }
  55.         x++;
  56.     }
  57.    
  58.     //new msg[256];
  59.     //new Float:angle;
  60.     //GetMyFacingAngle(angle);
  61.     //format(msg,256,"My yaw/heading = %f",angle);
  62.     //SendChat(msg);
  63.    
  64.     return 0;
  65. }
  66.  
  67.  
  68. //------------------------------------------
  69.  
  70. public ScanTimer()
  71. {
  72.     //new ticker = GetTickCount() - g_LastTick;
  73.     //printf("npctest: timer (%d)ms", ticker);
  74.     //g_LastTick = GetTickCount();
  75.    
  76.     new ReasonToPause = LookForAReasonToPause();
  77.    
  78.     if(ReasonToPause && !gStoppedForTraffic)
  79.     {
  80.         //SendChat("I'm pausing");
  81.         PauseRecordingPlayback();
  82.         gStoppedForTraffic = 1;
  83.     }
  84.     else if(!ReasonToPause && gStoppedForTraffic)
  85.     {
  86.         //SendChat("I'm resuming");
  87.         ResumeRecordingPlayback();
  88.         gStoppedForTraffic = 0;
  89.     }
  90. }
  91.  
  92.  
  93. //------------------------------------------
  94.  
  95. StartPlayback()
  96. {
  97.     if (Suund == 0){
  98.         StartRecordingPlayback(PLAYER_RECORDING_TYPE_DRIVER,"busX1toHabra");
  99.     } else if (Suund == 1) {
  100.         StartRecordingPlayback(PLAYER_RECORDING_TYPE_DRIVER,"busX1toSanta");
  101.     }
  102.     gStoppedForTraffic = 0;
  103.     gPlaybackActive = 1;
  104. }
  105.    
  106. //------------------------------------------
  107.  
  108. public OnRecordingPlaybackEnd()
  109. {
  110.     if (Suund == 0){
  111.         Suund = 1;
  112.     } else if (Suund == 1){
  113.         Suund = 0;
  114.     }
  115.     StartPlayback();
  116. }
  117.  
  118. //------------------------------------------
  119.  
  120. public OnNPCEnterVehicle(vehicleid, seatid)
  121. {
  122.     StartPlayback();
  123. }
  124.  
  125. //------------------------------------------
  126.  
  127. public OnNPCExitVehicle()
  128. {
  129.     StopRecordingPlayback();
  130. }
  131.  
  132. //------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment