Advertisement
Guest User

new

a guest
Nov 12th, 2021
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #include <a_samp>
  2. #include <math>
  3. #include <zcmd>
  4.  
  5. #if !defined IsValidVehicle
  6.     native IsValidVehicle(vehicleid);
  7. #endif
  8.  
  9. new
  10.     attach_trailer[MAX_VEHICLES] = 0,
  11.     attach_vehicle[MAX_VEHICLES] = 0,
  12.     attach_timer[MAX_VEHICLES] = 0
  13. ;
  14.  
  15. stock DFT30_TrailerAttach(vehicleid, trailerid)
  16. {
  17.     if(!IsValidVehicle(vehicleid) || GetVehicleModel(vehicleid) != 578) return 0;
  18.     if(!IsValidVehicle(trailerid) || GetVehicleModel(trailerid) == 578) return 0;
  19.     if(attach_trailer[vehicleid] || attach_vehicle[trailerid]) return 0;
  20.  
  21.     attach_trailer[vehicleid] = trailerid;
  22.     attach_vehicle[trailerid] = vehicleid;
  23.     attach_timer[vehicleid] = SetTimerEx("DFT30_UpdateTrailer", 15, true, "d", vehicleid);
  24.  
  25.     return 1;
  26. }
  27.  
  28. stock DFT30_DetachTrailer(vehicleid)
  29. {
  30.     if(!attach_timer[vehicleid]) return 0;
  31.     new trailerid = attach_trailer[vehicleid];
  32.     KillTimer(attach_timer[vehicleid]);
  33.     attach_trailer[vehicleid] = 0;
  34.     attach_vehicle[trailerid] = 0;
  35.     return 1;
  36. }
  37.  
  38. forward DFT30_UpdateTrailer(vehicleid);
  39. public DFT30_UpdateTrailer(vehicleid)
  40. {
  41.     new Float:x, Float:y, Float:z, Float:angle;
  42.     GetVehicleZAngle(vehicleid, angle);
  43.     GetVehiclePos(vehicleid, x, y, z);
  44.     GetXYFromAngle(x, y, angle, -1.8);
  45.    
  46.     new trailerid = attach_trailer[vehicleid];
  47.     SetVehiclePos(trailerid, x, y, (z + 1.2));
  48.  
  49.     GetVehicleZAngle(vehicleid, angle);
  50.     SetVehicleZAngle(trailerid, angle);
  51.     // Melhor usar (Get/Set)VehicleRot
  52.     // https://github.com/Leonardo541/matrix
  53.     return 1;
  54. }
  55.  
  56. CMD:guinchar(playerid, params[])
  57. {
  58.     new
  59.         vehicleid = GetPlayerVehicleID(playerid),
  60.         trailerid = strval(params)
  61.     ;
  62.  
  63.     if(!DFT30_TrailerAttach(vehicleid, trailerid))
  64.     {
  65.         new Float:x, Float:y, Float:z, Float:rot;
  66.         GetVehiclePos(vehicleid, x, y, z);
  67.         GetVehicleZAngle(vehicleid, rot);
  68.         GetXYFromAngle(x, y, rot, 10.0);
  69.  
  70.         DFT30_DetachTrailer(vehicleid);
  71.         SetVehicleZAngle(vehicleid, rot);
  72.         SetVehiclePos(vehicleid, x, y, z);
  73.     }
  74.     return 1;
  75. }
  76.  
  77. main() { print("SA-MP ANDROID 2021"); }
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement