Advertisement
Guest User

xD

a guest
Sep 4th, 2010
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.15 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define Distance 50.0
  4.  
  5. new bool:IsAttached[MAX_VEHICLES] = false;
  6. new missile_object[MAX_VEHICLES];
  7. new Float:VehPos[MAX_VEHICLES][3];
  8. new Float:VehCameraPos[MAX_VEHICLES][3];
  9. new Float:VehVectorPos[MAX_VEHICLES][3];
  10. new Float:OffSet[MAX_VEHICLES][3];
  11.  
  12. const Float:Dist = Distance;
  13.  
  14. public OnFilterScriptInit()
  15. {
  16.     SetTimer("CheckPos",10,true);
  17.     return 1;
  18. }
  19.  
  20. forward AttachMissileToVehicle(vehicleid,Float:OffSetX,Float:OffSetY,Float:OffSetZ);
  21. public AttachMissileToVehicle(vehicleid,Float:OffSetX,Float:OffSetY,Float:OffSetZ)
  22. {
  23.     IsAttached[vehicleid] = true;
  24.     OffSet[vehicleid][0] = OffSetX;
  25.     OffSet[vehicleid][1] = OffSetY;
  26.     OffSet[vehicleid][2] = OffSetZ;
  27.     GetVehiclePos(vehicleid,VehPos[vehicleid][0],VehPos[vehicleid][1],VehPos[vehicleid][2]);
  28.     missile_object[vehicleid] = CreateObject(360,VehPos[vehicleid][0]+OffSetX,VehPos[vehicleid][1]+OffSetY,VehPos[vehicleid][2]+OffSetZ,0.0,0.0,0.0,400);
  29.     return 1;
  30. }
  31.  
  32. forward DeAttachMissileFromVehicle(vehicleid);
  33. public DeAttachMissileFromVehicle(vehicleid)
  34. {
  35.     IsAttached[vehicleid] = false;
  36.     DestroyObject(missile_object[vehicleid]);
  37.     return 1;
  38. }
  39.  
  40. stock GetVehicleDriver(vehicleid)
  41. {
  42.     for(new i=0; i<MAX_PLAYERS, IsPlayerConnected(i); i++)
  43.     {
  44.         if(GetPlayerVehicleID(i) == vehicleid && GetPlayerState(i) == PLAYER_STATE_DRIVER) return i;
  45.     }
  46.     return INVALID_PLAYER_ID;
  47. }
  48.  
  49. forward CheckPos();
  50. public CheckPos()
  51. {
  52.     for(new i = 0; i < MAX_VEHICLES; i++)
  53.     {
  54.         if(IsAttached[i] == true)
  55.         {
  56.             GetVehiclePos(i,VehPos[i][0],VehPos[i][1],VehPos[i][2]);
  57.             SetObjectPos(missile_object[i],VehPos[i][0]+OffSet[i][0],VehPos[i][1]+OffSet[i][1],VehPos[i][2]+OffSet[i][2]);
  58.             GetPlayerCameraPos(GetVehicleDriver(i),VehCameraPos[i][0],VehCameraPos[i][1],VehCameraPos[i][2]);
  59.             GetPlayerCameraFrontVector(GetVehicleDriver(i),VehVectorPos[i][0],VehVectorPos[i][1],VehVectorPos[i][2]);
  60.             SetObjectRot(missile_object[i],0.0,-asin(VehVectorPos[i][2]),90 - atan2(VehVectorPos[i][0],VehVectorPos[i][1]));
  61.         }
  62.     }
  63. }
  64.  
  65. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  66. {
  67.     if(newkeys & KEY_FIRE)
  68.     {
  69.         if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  70.         {
  71.             for(new i = 0; i < MAX_VEHICLES; i++)
  72.             {
  73.                 if(IsAttached[i] == true)
  74.                 {
  75.                     if(GetPlayerVehicleID(playerid) == i)
  76.                     {
  77.                         new i2 = GetPlayerVehicleID(playerid);
  78.                         CreateExplosion(VehCameraPos[i2][0]+(VehVectorPos[i2][0] * Dist),VehCameraPos[i2][1]+(VehVectorPos[i2][1] * Dist),VehCameraPos[i2][2]+(VehVectorPos[i2][2] * Dist),7,100);
  79.                     }
  80.                 }
  81.             }
  82.         }
  83.     }
  84.     return 1;
  85. }
  86.  
  87. public OnPlayerCommandText(playerid,cmdtext[])
  88. {
  89.     if(strcmp(cmdtext,"/attachmissile",true) == 0)
  90.     {
  91.         if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  92.         {
  93.             AttachMissileToVehicle(GetPlayerVehicleID(playerid),0,0,1.01);
  94.         }
  95.         else return SendClientMessage(playerid,0xFFFFFFFF,"ERROR: You are not driving any vehicle!");
  96.         return 1;
  97.     }
  98.     return 0;
  99. }
  100.  
  101. public OnFilterScriptExit()
  102. {
  103.     for(new i = 0; i < MAX_VEHICLES; i++)
  104.     {
  105.         if(IsAttached[i] == true)
  106.         {
  107.             DestroyObject(missile_object[i]);
  108.             IsAttached[i] = false;
  109.         }
  110.     }
  111.     return true;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement