Guest User

OnTrailerAttached (c) by Kaliber

a guest
Jul 30th, 2015
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. /* SA-MP Include Trailer Callback
  2.  *
  3.  * (c) by Kaliber, 2015
  4.  *
  5.  */
  6. #if !defined _samp_included
  7.     #include <a_samp>
  8. #endif
  9. #if defined _samp_trailer
  10.     #endinput
  11. #endif
  12. #define _samp_trailer
  13. #if !defined MAX_TRAILER
  14.     #define MAX_TRAILER (50)
  15. #endif
  16. #define A:: a_S_
  17. /*
  18.     native CreateTrailer(modelid,Float:x,Float:y,Float:z,Float:a,color1,color2,respawn_delay);
  19. */
  20. static trailer[MAX_TRAILER];
  21.  
  22. stock CreateTrailer(modelid,Float:x,Float:y,Float:z,Float:a,color1,color2,respawn_delay)
  23. {
  24.     static idx;
  25.     if(idx == MAX_TRAILER) return 0;
  26.     trailer[idx++] = CreateVehicle(modelid,x,y,z,a,color1,color2,respawn_delay);
  27.     return trailer[idx-1];
  28. }
  29. #if defined FILTERSCRIPT
  30.     public OnFilterScriptInit()
  31.     {
  32.     SetTimer(!"@trailer",750,1);
  33.         #if defined a_S_OnFilterScriptInit
  34.         return A::OnFilterScriptInit();
  35.     #else
  36.         return 1;
  37.     #endif
  38.     }
  39.     #if defined a_S_OnFilterScriptInit
  40.     forward A::OnFilterScriptInit();
  41.     #endif
  42.     #if defined _ALS_OnFilterScriptInit
  43.     #undef OnFilterScriptInit
  44.     #else
  45.     #define _ALS_OnFilterScriptInit
  46.     #endif
  47.     #define OnFilterScriptInit a_S_OnFilterScriptInit
  48. #else
  49.     public OnGameModeInit()
  50.     {
  51.         SetTimer(!"@trailer",750,1);
  52.         #if defined a_S_OnGameModeInit
  53.         return A::OnGameModeInit();
  54.     #else
  55.         return 1;
  56.     #endif
  57.     }
  58.     #if defined a_S_OnGameModeInit
  59.     forward A::OnGameModeInit();
  60.     #endif
  61.     #if defined _ALS_OnGameModeInit
  62.     #undef OnGameModeInit
  63.     #else
  64.     #define _ALS_OnGameModeInit
  65.     #endif
  66.     #define OnGameModeInit a_S_OnGameModeInit
  67. #endif
  68. static @trailer();@trailer() {
  69.     static bool:attached[MAX_TRAILER char];
  70.     for(new i; i<MAX_TRAILER; i++)
  71.     {
  72.         if(!trailer[i]) continue;
  73.         if(IsTrailerAttachedToVehicle(trailer[i]) && !attached{i}) {
  74.         CallLocalFunction(!"OnTrailerAttached",!"i",trailer[i]);
  75.         attached{i}=true;
  76.     } else if(!IsTrailerAttachedToVehicle(trailer[i]) && attached{i}) {
  77.         CallLocalFunction(!"OnTrailerDetached",!"i",trailer[i]);
  78.         attached{i}=false;
  79.     }
  80.     }
  81.     return 1;
  82. }
  83. forward OnTrailerAttached(vehicleid);
  84. forward OnTrailerDetached(vehicleid);
  85. #undef A
Advertisement
Add Comment
Please, Sign In to add comment