Guest User

Untitled

a guest
Jun 23rd, 2012
2,780
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. This include prevents the bug where if you press G to enter a vehicle as a passenger and after 3 seconds entry isn't achieved you are teleported inside.
  3. This is abusable as a player may start to enter an enemy player's vehicle, the enemy may drive off leaving the passenger still running after the car but
  4. he will be teleported inside.
  5. */
  6.  
  7. #include <YSI\y_hooks>
  8.  
  9. #define MAX_VEHICLE_MOVE_RADIUS 2.0 // The distance a vehicle can move by for passengers to warp inside
  10.  
  11. enum E_GBUG
  12. {
  13.     Float:gbug_playerpos[3],
  14.     Float:gbug_vehpos[3],
  15.     gbug_playerenteringveh,
  16.     gbug_pentervtick
  17.    
  18. }
  19. new gBugPlayerData[MAX_PLAYERS][E_GBUG];
  20.  
  21. Hook:gbug_OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  22. {
  23.     if(!ispassenger || gBugPlayerData[playerid][gbug_playerenteringveh] != 0) return 1;
  24.     gBugPlayerData[playerid][gbug_pentervtick] = GetTickCount();
  25.     GetPlayerPos(playerid, gBugPlayerData[playerid][gbug_playerpos][0], gBugPlayerData[playerid][gbug_playerpos][1], gBugPlayerData[playerid][gbug_playerpos][2]);
  26.     GetVehiclePos(vehicleid, gBugPlayerData[playerid][gbug_vehpos][0], gBugPlayerData[playerid][gbug_vehpos][1], gBugPlayerData[playerid][gbug_vehpos][2]);
  27.     gBugPlayerData[playerid][gbug_playerenteringveh] = 1;
  28.     //SendClientMessage(playerid, -1, "Starting to enter vehicle..");
  29.     return 1;
  30. }
  31.  
  32. Hook:gbug_OnPlayerStateChange(playerid, newstate, oldstate)
  33. {
  34.     if(newstate == 3) // Entered vehicle
  35.     {
  36.         if((gBugPlayerData[playerid][gbug_playerenteringveh] == 1 || gBugPlayerData[playerid][gbug_playerenteringveh] == 2) && GetVehicleDistanceFromPoint(GetPlayerVehicleID(playerid), gBugPlayerData[playerid][gbug_vehpos][0], gBugPlayerData[playerid][gbug_vehpos][1], gBugPlayerData[playerid][gbug_vehpos][2]) > MAX_VEHICLE_MOVE_RADIUS)
  37.         {
  38.             SetPlayerPos(playerid, gBugPlayerData[playerid][gbug_playerpos][0], gBugPlayerData[playerid][gbug_playerpos][1], gBugPlayerData[playerid][gbug_playerpos][2]);
  39.             gBugPlayerData[playerid][gbug_playerenteringveh] = 0;
  40.             //SendClientMessage(playerid, -1, "Entry denied");
  41.             GameTextForPlayer(playerid, "~R~entry denied", 3000, 3);
  42.         }
  43.         else
  44.         {
  45.             gBugPlayerData[playerid][gbug_playerenteringveh] = 0;
  46.             //SendClientMessage(playerid, -1, "Entry accepted");
  47.         }
  48.     }
  49.     return 1;
  50. }
  51.  
  52. stock gbug_PutPlayerInVehicle(playerid, vehicleid, seatid)
  53. {
  54.     gBugPlayerData[playerid][gbug_playerenteringveh] = 0;
  55.     PutPlayerInVehicle(playerid, vehicleid, seatid);
  56.     return 1;
  57. }
  58.  
  59. #if defined _ALS_PutPlayerInVehicle
  60.     #undef PutPlayerInVehicle
  61. #else
  62.     #define _ALS_PutPlayerInVehicle
  63. #endif
  64. #define PutPlayerInVehicle  gbug_PutPlayerInVehicle
  65.  
  66. Hook:gbug_OnPlayerUpdate(playerid)
  67. {
  68.     if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_ENTER_VEHICLE && gBugPlayerData[playerid][gbug_playerenteringveh] == 0) // OnPlayerEnterVehicle wasn't called, tsk tsk tsk
  69.     {
  70.         gBugPlayerData[playerid][gbug_pentervtick] = GetTickCount();
  71.         GetPlayerPos(playerid, gBugPlayerData[playerid][gbug_playerpos][0], gBugPlayerData[playerid][gbug_playerpos][1], gBugPlayerData[playerid][gbug_playerpos][2]);
  72.         gBugPlayerData[playerid][gbug_playerenteringveh] = 1;
  73.         //SendClientMessage(playerid, -1, "Starting to enter vehicle..");
  74.         return 1;
  75.     }
  76.  
  77.     if(gBugPlayerData[playerid][gbug_playerenteringveh] == 0) return 1; // Not handling
  78.    
  79.     if(GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_ENTER_VEHICLE && gBugPlayerData[playerid][gbug_playerenteringveh] != 3 && GetTickCount()-gBugPlayerData[playerid][gbug_pentervtick] > 321)
  80.     {
  81.         {
  82.             gBugPlayerData[playerid][gbug_playerenteringveh] = 0;
  83.             //SendClientMessage(playerid, -1, "Cancelled entry while running to door: special action");
  84.         }
  85.         return 1;
  86.     }
  87.  
  88.     new Float:x, Float:y, Float:z;
  89.     GetPlayerVelocity(playerid, x, y, z);
  90.  
  91.     if(gBugPlayerData[playerid][gbug_playerenteringveh] == 3 && GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_ENTER_VEHICLE)
  92.     {
  93.         gBugPlayerData[playerid][gbug_playerenteringveh] = 0;
  94.         //SendClientMessage(playerid, -1, "Cancelled entry while stepping in (special action)");
  95.         return 1;
  96.     }
  97.    
  98.     if(x == 0 && y == 0 && z == 0) // Standing still, did they get in?
  99.     {
  100.         if(gBugPlayerData[playerid][gbug_playerenteringveh] != 3)
  101.         {
  102.             if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_ENTER_VEHICLE && GetTickCount()-gBugPlayerData[playerid][gbug_pentervtick] > 321)
  103.             {
  104.                 if(gBugPlayerData[playerid][gbug_playerenteringveh] == 2) // Stepping in
  105.                 {
  106.                     gBugPlayerData[playerid][gbug_playerenteringveh] = 3;
  107.                     //SendClientMessage(playerid, -1, "Stepping in");
  108.                 }
  109.                 else
  110.                 {
  111.                     gBugPlayerData[playerid][gbug_playerenteringveh] = 2; // Stepping in?
  112.                     //SendClientMessage(playerid, -1, "Stepping in?");
  113.                     gBugPlayerData[playerid][gbug_pentervtick] = GetTickCount();
  114.                 }
  115.             }
  116.             else if(GetTickCount()-gBugPlayerData[playerid][gbug_pentervtick] > 321) // Cancelled entry
  117.             {
  118.                 gBugPlayerData[playerid][gbug_playerenteringveh] = 0;
  119.                 //SendClientMessage(playerid, -1, "Cancelled entry while running to door (special action)");
  120.             }
  121.         }
  122.     }
  123.     return 1;
  124. }
RAW Paste Data